import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.StringRes;
import android.widget.Toast;
public class PlayStoreLink {
public void checkForUpdate(Context context, int applicationId)
{
try {
context.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(context.getString(R.string.url_market_details)
+ applicationId)));
} catch (android.content.ActivityNotFoundException anfe) {
try {
context.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(context.getString(R.string.url_playstore_app)
+ applicationId)));
} catch (Exception e) {
Toast.makeText(context,
R.string.install_google_play_store,
Toast.LENGTH_SHORT).show();
}
}
}
public void moreApps(Context context, @StringRes int devName) {
try {
context.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(context.getString(R.string.url_market_search_app)
+ context.getString(devName))));
} catch (android.content.ActivityNotFoundException anfe) {
try {
context.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(context.getString(R.string.url_playstore_search_app)
+ context.getString(devName))));
} catch (Exception e) {
Toast.makeText(context,
R.string.install_google_play_store,
Toast.LENGTH_SHORT).show();
}
}
}
public void rateApp(Context context, int applicationId) {
try {
Uri uri = Uri.parse(context.getString(R.string.url_market_details)
+ applicationId);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH)
flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
else
flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
intent.addFlags(flags);
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
checkForUpdate(context, applicationId);
}
}
}
<string name="install_google_play_store" translatable="false">Please install google play store and then try again.</string>
<string name="url_market_details" translatable="false">market://details?id=</string>
<string name="url_playstore_app" translatable="false">https://play.google.com/store/apps/details?id=</string>
<string name="url_market_search_app" translatable="false">market://search?q=pub:</string>
<string name="url_playstore_search_app" translatable="false">http://play.google.com/store/search?q=pub:</string>
<string name="app_link" translatable="false">https://play.google.com/store/apps/details?id=</string>
devName은 Play 스토어의 개발자 계정 이름입니다.