如何在Android中修复null Uri data = intent.getData()

时间:2016-10-13 19:01:50

标签: android android-intent deep-linking

我想在我的应用程序中打开此链接,而不是在浏览器中打开。对于这项工作,我想使用 DeepLink
但是在启动应用程序时,请为URI显示null。。

我的链接: Link

我在manifest中编写了这段代码:

<activity
    android:name=".Activities.PostShow_page"
    android:screenOrientation="portrait"
    android:theme="@style/AppThemeWithStatus">

    <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="www.kolony.ir"
            android:scheme="http" />

        <data
            android:host="kolony.ir"
            android:scheme="http" />

    </intent-filter>

</activity>

活动代码:

// Deep Linking
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
Log.e("Deep", "Link : " + data);

但在运行应用程序时,在 LogCat 中显示:Link : null

如何修复此URI的 null 并在uri中显示logCat

3 个答案:

答案 0 :(得分:0)

试试这个:

Intent intent = getIntent();
Uri data = (Uri) intent.getExtras().get(Intent.ACTION_VIEW);

答案 1 :(得分:0)

尝试一下

intent.getStringExtra(Intent.EXTRA_TEXT)

您将获得确切的位置。它可以帮助我希望,也可以帮助您。

答案 2 :(得分:-1)

  String action = intent.getAction();
    String data = intent.getDataString();
    if (Intent.ACTION_VIEW.equals(action) && data != null) {
        String recipeId = data.substring(data.lastIndexOf("/") + 1);
    }