【发布时间】: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