如何处理这个字符串,打开我的应用程序 [英] how do i handle this string to open my app
问题描述
我得到这个字符串,在浏览器重定向
i get this string in a browser redirect
原意://查看ID = 123#意图;包= com.myapp;计划=的myapp; launchFlags = 268435456;结束;
intent://view?id=123#Intent;package=com.myapp;scheme=myapp;launchFlags=268435456;end;
我如何使用它?
在发现:的http:// fokkezb.nl/2013/09/20/url-schemes-for-ios-and-android-2/
推荐答案
您已经在同一篇文章的第1部分答案:
You have your answer in the part 1 of the same article :
http://fokkezb.nl / 2013/8月26日/ URL-计划换IOS和 - 机器人-1 /
您的活动必须有一个意图过滤器匹配给定的意图 在这里,您有:
Your activity must have an intent filter matching the given intent Here you have :
package=com.myapp;scheme=myapp
您的应用程序包必须的 com.myapp </ em>的和URL方案的的myapp:// 的 所以,你必须声明你的活动这样的:
Your app package must be com.myapp and the url scheme is myapp:// So you must declare your activity like that :
<activity android:name=".MyActivity" >
<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:scheme="myapp" />
</intent-filter>
</activity>
那么你的活动将被自动机器人打开。
Then your activity will be automatically opened by android.
Optionnaly可以一起工作的URI从code接收到的,例如在onResume方法(为什么onResume - >,因为它总是叫onNewIntent后?):
Optionnaly you can work with the uri received from your code, for example in the onResume method (why onResume ? -> because it is always called after onNewIntent) :
@Override
protected void onResume() {
super.onResume();
Intent intent = getIntent();
if (intent != null && intent.getData() != null) {
Uri uri = intent.getData();
// do whatever you want with the uri given
}
}
如果您的活动采用onNewIntent,我推荐使用setIntent使得code以上,就总是执行去年的意图:
If your activity uses onNewIntent, i recommend to use setIntent so that code above is always executed on last intent :
@Override
protected void onNewIntent(Intent intent) {
setIntent(intent);
}
这是否回答你的问题?
Does this answers your question ?
这篇关于如何处理这个字符串,打开我的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!