實現功能:
短信內容中含有url(例如,
http://youngo.com/app/
),點擊後打開apk
遺留問題:
點擊url後,會出現選擇框,讓用戶選擇是用瀏覽器打開仍是用該apk打開————沒有找到方法如何不出現該選擇框??
參考:
一、應用中AndroidManifest.xml配置——主要
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.msgintenapptest" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" /> <uses-permission android:name="android.permission.SEND_SMS"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <data android:scheme="http" android:host="youngo.com" android:pathPrefix="/app/"> </data> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.BROWSABLE"/> </intent-filter> </activity> </application></manifest>
二、測試發送短信
private Button.OnClickListener button_clickListener = new Button.OnClickListener(){ @Override public void onClick(View v) { try { URL url = new URL("http://youngo.com/app/"); intentToSms("18511111111",url.toString()); } catch (MalformedURLException e) { e.printStackTrace(); } } }; private void intentToSms(String tel, String msg){ Uri uri = Uri.parse("smsto:"+tel); Intent intent = new Intent(Intent.ACTION_SENDTO,uri); intent.putExtra("sms_body", msg); startActivity(intent); }
附件列表