【问题标题】:How to open my application when app link is clicked?单击应用程序链接时如何打开我的应用程序?
【发布时间】:2016-02-15 19:57:08
【问题描述】:

我想要的是分享我的应用程序特定页面的链接。假设我在我的应用程序中某个用户的个人资料页面中,我想将该用户分享给我的一些朋友,因此我想通过 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"));

在我的清单中,我声明了这样的活动

<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 或任何其他方式共享的链接时,我仍然无法看到我的应用程序。

请帮帮我

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

【问题讨论】:

标签: android android-intent intentfilter


【解决方案1】:

在项目的 AndroidManifest 中将以下意图过滤器添加到您的活动声明中:

    <intent-filter>

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

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

    </intent-filter>

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

【讨论】:

  • 为了传递数据,假设用户 ID 我将额外的内容放入共享意图中??
  • 是的,您可以将任何类型的数据传递给您的意图。你可以看看这个以获取更多信息。developer.android.com/guide/components/intents-filters.html
  • 你能看到我更新的问题并告诉我我做错了什么
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-16
  • 1970-01-01
  • 2014-12-09
  • 2017-04-29
  • 1970-01-01
  • 2012-10-22
相关资源
最近更新 更多