android - 我如何处理这个字符串来打开我的应用程序

标签 android redirect android-intent

我在浏览器重定向中得到这个字符串

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/

相关文章:

android - 在android中开发unicode应用程序

安卓和slf4j : "java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory"

android - 向 Realm 添加新字段后如何设置默认值?

android - 创建布局图像

android - 如何使用 onChildClickListener 在 expandablelistview 中提取 child 的值(value)?

facebook - 创建排除 facebook 的 301 重定向

redirect - 在youtube的视频中提供外部链接

PHP header 重定向在表单提交时不起作用

php - 我如何将我的 Android 设备(不是模拟器)连接到 wamp 服务器?

android - 如何取消从 startActivityForResult 调用的 Intent