<activity
android:name="MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="{your mime}.com"
android:scheme="http" >
</data>
</intent-filter>
</activity>
<!--
android:scheme="http" will make android "think" thats this is a link
-->
现在注册自定义MIME类型,当你接收短信与文本"http://{your mime}.com"
或点击该文本链接,您的活动(MainActivity)将运行。
您还可以添加参数:
text = "http://{your mime}.com/?number=111";
然后在的onCreate()或的onResume()方法,将添加:
Intent intentURI = getIntent();
Uri uri = null;
String receivedNum = "";
Log.d("TAG", "intent= "+intentURI);
if (Intent.ACTION_VIEW.equals(intentURI.getAction())) {
if (intentURI!=null){
uri = intentURI.getData();
Log.d("TAG", "uri= "+uri);
}
if (uri!=null)
receivedNum = uri.getQueryParameter("number");
}
意图过滤器应该足够好。 看看http://stackoverflow.com/questions/1733195/android-intent-filter-for-a-particular-file-extension – pinxue 2011-12-20 08:22:13
你不需要创建自己的mimeType。您可以使用一些文件扩展名。看看这个答案https://stackoverflow.com/a/2062112/1298357。这非常有帮助! – 2012-03-29 18:10:52