Java tutorial
//package com.java2s; import java.util.List; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; import android.widget.Toast; public class Main { private static final String REVIEW_DONE = "com.adroitstudio.apkextractor.MKRUtils.ReviewDone"; /** * Method to open app * * @param context */ public static void openApp(Context context, String appPackage) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackage)); if (isConnectionAvailable(context) && isIntentAvailable(context, intent)) { // SET THAT REVIEW IS DONE SharedPreferences sharedPreferences = context.getSharedPreferences(REVIEW_DONE, Context.MODE_PRIVATE); Editor edit = sharedPreferences.edit(); edit.putBoolean(REVIEW_DONE, true); edit.commit(); // START REVIEW ACTIVITY context.startActivity(intent); } else { Toast.makeText(context, "Network Error", Toast.LENGTH_LONG).show(); } } /** * Method to check weather the network is available in the device * * @param context * @return */ private static boolean isConnectionAvailable(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnectedOrConnecting()) { return true; } return false; } /** * Method to get weather the intent is available in system to perform * specified operation * * @param ctx * @param in * @return */ private static boolean isIntentAvailable(Context ctx, Intent in) { PackageManager packageManager = ctx.getPackageManager(); List<ResolveInfo> activities = packageManager.queryIntentActivities(in, 0); return (activities == null) ? false : (activities.size() > 0); } }