android - 单击应用程序链接时如何打开我的应用程序?

标签 android android-intent intentfilter

我想要的是共享我的应用程序特定页面的链接。假设我在我的应用程序中某个用户的个人资料页面中,我想将该用户分享给我的一些 friend ,所以我想通过 WhatsApp 和其他应用程序分享它。

所以基本上我想分享一个指向我的应用程序的链接。

这就是我现在正在做的事情

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=" + activity.getPackageName());
    activity.startActivity(Intent.createChooser(shareIntent, "Share"));

我知道这不是我真正想要的,但它已经部分完成了。 如果用户尚未安装我的应用程序,则此代码会将他重定向到 Google Play 商店页面以下载此应用程序。

主要问题是当用户已经拥有此应用程序时,此链接只会打开该应用程序。我想在用户点击链接时将他重定向到该特定页面。

我该怎么做?

我听说过一些有关 intent-filter 的信息,但不确定如何使用它们。

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/pdf" />

已更新

现在我正尝试像这样分享我的应用程序链接

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra("PostID", postID);
    shareIntent.putExtra("UserID", userID);
    shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=" + activity.getPackageName());
    activity.startActivity(Intent.createChooser(shareIntent, "Share"));

在我的 list 中,我声明了这样的 Activity

<activity
        android:name=".activities.ShareActivity"
        android:screenOrientation="sensorPortrait"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">

        <intent-filter>
            <action android:name="android.intent.action.SEND" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="details"
                android:scheme="market" />
            <data
                android:host="play.google.com"
                android:pathPattern="/store/apps/details?id=my_package_name"
                android:scheme="http" />
            <data
                android:host="play.google.com"
                android:pathPattern="/store/apps/details?id=my_package_name"
                android:scheme="https" />
        </intent-filter>
    </activity>

但当我点击我使用 WhatsApp 或任何其他方式分享的链接时,我仍然无法看到我的应用程序。

请帮帮我

任何帮助将不胜感激。 提前致谢。

最佳答案

在项目的 AndroidManifest 中将以下 intent-filters 添加到 Activity 声明中:

    <intent-filter>

        <action android:name="android.intent.action.SEND"/>
        <category android:name="android.intent.category.DEFAULT"/>

        <data android:mimeType="text/plain"/>

    </intent-filter>

现在,在 Activity 生命周期的 onCreate()onResume()onNewIntent() 方法中,您可以使用 <触发您的 Activity 的 intent 的 strong>getData()。

关于android - 单击应用程序链接时如何打开我的应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35417950/

相关文章:

android - 在 Django 中处理 JSON 的最佳和简单方法

android - myActivity 扩展 GridView 实现 OnClickListener

android - BroadcastReceiver ClassNotFound 异常

android - Url Scheme Intent 不适用于获取参数

Android Intent-Filter 自定义文件类型

android - "android.intent.category.DEFAULT"的目的是什么?

Android onResume() 在 onPause() 之前调用?

android - 尝试使用 Intent 启动新的 Activity

java - 如何在 Android Studio 上传输多个 Activity 的数据?

android - 应用程序强制关闭时未执行广播接收器