learner
learner

Reputation: 1051

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"));
        }
    }
}

Upvotes: 4

Views: 4296

Answers (3)

A. Senna
A. Senna

Reputation: 131

If you are in the MainActivity, you can use:

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:

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">

Upvotes: 0

Egor
Egor

Reputation: 40193

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.

Upvotes: 10

ilango j
ilango j

Reputation: 6037

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

Upvotes: 5

Related Questions