Reputation: 1051
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
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
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
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