简体   繁体   English

如何使用Google Play商店链接到Android应用

[英]How to link to android app with Google Play Store

I have a free version of app and i want to link the app store on click of the buy button on the app. 我有一个免费版本的应用程序,我想点击应用程序上的购买按钮链接应用程序商店。 How to i do this, i have completely no idea and please help me with some code. 我怎么做,我完全不知道,请帮我一些代码。
Thanks in advance 提前致谢

What I did was 我做的是

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    buyButton = (Button)findViewById(R.id.buybutton);

    buyButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("market://details?id=app name"));
        }
    }
}

Use this code to redirect user to the market: 使用此代码将用户重定向到市场:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=your.game.package.name"));
startActivity(intent);

Hope this helps. 希望这可以帮助。

use below code 使用下面的代码

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=your_package_name"));
startActivity(intent);

refer this link 请参阅此链接

http://developer.android.com/guide/publishing/publishing.html http://developer.android.com/guide/publishing/publishing.html

If you are in the MainActivity, you can use: 如果您在MainActivity中,则可以使用:

MainActivity.this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=YourPackageName")));               

But if you are a Fragment, is important add Flag "FLAG_ACTIVITY_NEW_TASK" in your intent, like this code: 但是如果你是一个片段,重要的是在你的意图中添加Flag“FLAG_ACTIVITY_NEW_TASK”,就像这段代码一样:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("market://details?id=YourPackageName"));
startActivity(intent);

if you need to know your package name, you can verify it in your manifests file 如果您需要知道您的包名称,可以在清单文件中进行验证

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="Here"
android:versionCode="40"
android:versionName="6.7">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM