打开Android应用,其中包含指向Google Play商店的链接

时间:2015-07-29 13:48:08

标签: android google-play

我想用链接打开我的应用。我想要使​​用的链接是指向Google Play商店的链接。我尝试过,但我的应用程序没有启动。 有可能这样做吗?

在我的清单中,我执行以下操作:

<activity android:name="myApp">
<intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </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:scheme="http" android:host="play.google.com" 
            android:path="/store/apps/details?id=myApp" />
        <data android:scheme="https" android:host="play.google.com" 
            android:path="/store/apps/details?id=myApp" />
    </intent-filter>
</activity>

我也尝试过使用pathPrefix。

最好的问候

3 个答案:

答案 0 :(得分:1)

打开应用程序到Google Play的链接的最佳方法。

String appPackageName = getPackageName();
            try {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
            } catch (android.content.ActivityNotFoundException anfe) {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
            }

如果您使用的是Fragment,则可以获取packageName:

String appPackageName = getActivity().getPackageName();

在Adapter中,您可以这样:

String appPackageName = context.getPackageName();

答案 1 :(得分:0)

不知道是否迟到,但这个可能适合你

<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="http" android:host="some.host.com" android:pathPrefix="/store/apps/details" />
</intent-filter>

答案 2 :(得分:-1)

使用意向:

String url = "https://play.google.com/store/apps/details?id=org.example.omri.saharplus";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);

并在MANIFEST中

<uses-permission android:name="android.permission.INTERNET" />
相关问题