我在浏览器重定向中得到这个字符串
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 部分中有答案:
http://fokkezb.nl/2013/08/26/url-schemes-for-ios-and-android-1/
您的 Activity 必须具有与给定 Intent 相匹配的 Intent 过滤器 给你:
package=com.myapp;scheme=myapp
您的应用程序包必须是 com.myapp 并且 url scheme 是 myapp:// 所以你必须这样声明你的 Activity :
<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>
然后你的activity会被android自动打开。
您可以选择使用从您的代码接收到的 uri,例如在 onResume 方法中(为什么使用 onResume? -> 因为它总是在 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
}
}
如果您的 Activity 使用 onNewIntent,我建议使用 setIntent,这样上面的代码总是在最后一个 Intent 上执行:
@Override
protected void onNewIntent(Intent intent) {
setIntent(intent);
}
这是否回答了您的问题?
关于android - 我如何处理这个字符串来打开我的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20545373/