start Review in Market - Android App

Android examples for App:App Market

Description

start Review in Market

Demo Code


//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.Uri;
import android.widget.Toast;

public class Main {
    private static final String REVIEW_PREFS = "Review_pref_data";
    private static final String KEY_REVIEW_DONE = "ReviewDone";

    public static void startReview(Context context) {

        Intent intent = new Intent(Intent.ACTION_VIEW,
                getReviewUri(context));/*from   w ww . j  a  v a 2s  . co  m*/
        if (isIntentAvailable(context, intent)) {
            context.startActivity(intent);
            setReviewDone(context, true);
        } else {
            setReviewDone(context, false);
            Toast.makeText(context, "Network Error", Toast.LENGTH_LONG)
                    .show();
        }

    }

    private static Uri getReviewUri(Context context) {
        return Uri.parse("market://details?id=" + context.getPackageName());
    }

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

    public static void setReviewDone(Context context, boolean isDone) {

        SharedPreferences sharedPreferences = context.getSharedPreferences(
                REVIEW_PREFS, Context.MODE_PRIVATE);
        Editor edit = sharedPreferences.edit();
        edit.putBoolean(KEY_REVIEW_DONE, isDone);
        edit.commit();

    }
}

Related Tutorials