This question already has answers here:
"Rate This App"-link in Google Play store app on the phone
(21 answers)
Closed 2 years ago.
I am currently developing an application in Android Where I want to give some functionality to user to rate the current application.
Their will be a button on it's click it will ask ask whether user want to rate the application or not? If yes will will go to market application on device to rate application
(Market should show this application.) or it will open browser which will load market & showing this application.
Any one used this kind of functionality before. Please provide some help.
Thank You.
I always use a method like this one:
private void launchMarket() {
Uri uri = Uri.parse("market://details?id=" + getPackageName());
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
try {
startActivity(goToMarket);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, R.string.couldnt_launch_market, Toast.LENGTH_LONG).show();
}
}
public class AppRater {
private final static String APP_TITLE = "App Name";// App Name
private final static String APP_PNAME = "com.example.name";// Package Name
private final static int DAYS_UNTIL_PROMPT = 3;//Min number of days
private final static int LAUNCHES_UNTIL_PROMPT = 3;//Min number of launches
public static void app_launched(Context mContext) {
SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0);
if (prefs.getBoolean("dontshowagain", false)) { return ; }
SharedPreferences.Editor editor = prefs.edit();
// Increment launch counter
long launch_count = prefs.getLong("launch_count", 0) + 1;
editor.putLong("launch_count", launch_count);
// Get date of first launch
Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0);
if (date_firstLaunch == 0) {
date_firstLaunch = System.currentTimeMillis();
editor.putLong("date_firstlaunch", date_firstLaunch);
}
// Wait at least n days before opening
if (launch_count >= LAUNCHES_UNTIL_PROMPT) {
if (System.currentTimeMillis() >= date_firstLaunch +
(DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) {
showRateDialog(mContext, editor);
}
}
editor.commit();
}
public static void showRateDialog(final Context mContext, final SharedPreferences.Editor editor) {
final Dialog dialog = new Dialog(mContext);
dialog.setTitle("Rate " + APP_TITLE);
LinearLayout ll = new LinearLayout(mContext);
ll.setOrientation(LinearLayout.VERTICAL);
TextView tv = new TextView(mContext);
tv.setText("If you enjoy using " + APP_TITLE + ", please take a moment to rate it. Thanks for your support!");
tv.setWidth(240);
tv.setPadding(4, 0, 4, 10);
ll.addView(tv);
Button b1 = new Button(mContext);
b1.setText("Rate " + APP_TITLE);
b1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME)));
dialog.dismiss();
}
});
ll.addView(b1);
Button b2 = new Button(mContext);
b2.setText("Remind me later");
b2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
ll.addView(b2);
Button b3 = new Button(mContext);
b3.setText("No, thanks");
b3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (editor != null) {
editor.putBoolean("dontshowagain", true);
editor.commit();
}
dialog.dismiss();
}
});
ll.addView(b3);
dialog.setContentView(ll);
dialog.show();
}}
Now Integrate class to your activity like this ->
AppRater.app_launched(this);
Here is simple solution for :
final String appPackageName = "com.name.app";
private void launchMyMarket() {
Uri uri = Uri.parse("market://details?id=" + getPackageName());
Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri);
try {
startActivity(myAppLinkToMarket);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, " unable to find source market app! try again", Toast.LENGTH_LONG).show();
}
}
The answers here won't take you directly to playstore if you have multiple market apps on your phone. Instead it will show a picker dialog.
To open playstore directly, use this:
private fun rateUs() {
val uri = Uri.parse("https://play.google.com/store/apps/details?id=" + activity?.packageName.toString() + "")
val intent = Intent(Intent.ACTION_VIEW, uri)
startActivity(intent)
}
Related
I create a mini game . The User need to answer my question in 2 seconds, if user answer true , the score will increase 1 , and if user answer wrong - Game over and the score become to 0.
I want to use SharedRefences so that I can save the score when the user play again . But it's not working .
My CountDownTimer:
public void start_game() {
flag = false;
btnTrue.setClickable(true);
btnWrong.setClickable(true);
a = (int) (Math.random() * 6);
b = (int) (Math.random() * 6);
sum = (int) (Math.random() * 11);
tvDetails.setText(a + " + " + b + " = " + sum);
proTime.setSecondaryProgress(0);
timer = new CountDownTimer(3000, 10) {
#Override
public void onFinish() {
// TODO Auto-generated method stub
btnTrue.setClickable(false);
btnWrong.setClickable(false);
if (flag) {
tmp++;
tvScore.setText("" + tmp);
start_game();
} else {
ShowDialogs();
tmp = 0;
tvScore.setText("" + tmp);
}
}
#Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
proTime.setSecondaryProgress(proTime.getSecondaryProgress() + 10);
}
};
timer.start();
}
public void ShowDialogs() {
final Dialog dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.custom_dialog);
dialog.setCanceledOnTouchOutside(true);
dialog.setCancelable(false);
tvNowScore = (TextView) dialog.findViewById(R.id.NowScore);
tvHighScore = (TextView) dialog.findViewById(R.id.HighScore);
ImageView btnRep = (ImageView) dialog.findViewById(R.id.Rep);
ImageView btnExit = (ImageView) dialog.findViewById(R.id.Exit);
ResPreferences();
int HighScore = Integer.parseInt(tvHighScore.getText().toString());
int Score = Integer.parseInt(tvScore.getText().toString());
if (Score > HighScore) {
HighScore = Score;
SavingPreferences();
}
tvNowScore.setText("" + Score);
tvHighScore.setText("" + HighScore);
btnExit.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
System.exit(0);
}
});
btnRep.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
dialog.cancel();
if (timer != null) {
timer.cancel();
timer = null;
}
start_game();
}
});
dialog.show();
}
I can't save a score when the game finish.
This is my Save Preferences
public void SavingPreferences() {
SharedPreferences pre = getSharedPreferences(PrefName, MODE_PRIVATE);
SharedPreferences.Editor editor = pre.edit();
String HighScore = tvHighScore.getText().toString();
editor.putString("HighScore", HighScore);
editor.commit();
}
This is Restrore Pre:
public void ResPreferences() {
SharedPreferences pre = getSharedPreferences(PrefName, MODE_PRIVATE);
String score = pre.getString("HighScore", "0");
tvHighScore.setText(score);
}
Try this :
public void SavingPreferences() {
SharedPreferences pre = getSharedPreferences(PrefName, MODE_PRIVATE);
String score = null;
if(pre.contains("HighScore")){
score = pre.getString("HighScore", "0");
}
SharedPreferences.Editor editor = pre.edit();
String HighScore = tvHighScore.getText().toString();
if(score != null && Integer.parseInt(score) > Integer.parseInt(HighScore )){
editor.putString("HighScore", score);
} else {
editor.putString("HighScore", HighScore);
}
editor.commit();
}
i am trying the code to show users to rate my app
however once the user has rated the app it should not show again
how can that be done
moreover can we track if users have rated our app, is there any google api for this feature , can analytics be helpfull for tracking ratings of an app
public class AppRater {
private final static String APP_TITLE = "App Name";// App Name
private final static String APP_PNAME = "com.example.name";// Package Name
private final static int DAYS_UNTIL_PROMPT = 3;//Min number of days
private final static int LAUNCHES_UNTIL_PROMPT = 3;//Min number of launches
public static void app_launched(Context mContext) {
SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0);
if (prefs.getBoolean("dontshowagain", false)) { return ; }
SharedPreferences.Editor editor = prefs.edit();
// Increment launch counter
long launch_count = prefs.getLong("launch_count", 0) + 1;
editor.putLong("launch_count", launch_count);
// Get date of first launch
Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0);
if (date_firstLaunch == 0) {
date_firstLaunch = System.currentTimeMillis();
editor.putLong("date_firstlaunch", date_firstLaunch);
}
// Wait at least n days before opening
if (launch_count >= LAUNCHES_UNTIL_PROMPT) {
if (System.currentTimeMillis() >= date_firstLaunch +
(DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) {
showRateDialog(mContext, editor);
}
}
editor.commit();
}
public static void showRateDialog(final Context mContext, final SharedPreferences.Editor editor) {
final Dialog dialog = new Dialog(mContext);
dialog.setTitle("Rate " + APP_TITLE);
LinearLayout ll = new LinearLayout(mContext);
ll.setOrientation(LinearLayout.VERTICAL);
TextView tv = new TextView(mContext);
tv.setText("If you enjoy using " + APP_TITLE + ", please take a moment to rate it. Thanks for your support!");
tv.setWidth(240);
tv.setPadding(4, 0, 4, 10);
ll.addView(tv);
Button b1 = new Button(mContext);
b1.setText("Rate " + APP_TITLE);
b1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME)));
dialog.dismiss();
}
});
ll.addView(b1);
Button b2 = new Button(mContext);
b2.setText("Remind me later");
b2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
ll.addView(b2);
Button b3 = new Button(mContext);
b3.setText("No, thanks");
b3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (editor != null) {
editor.putBoolean("dontshowagain", true);
editor.commit();
}
dialog.dismiss();
}
});
ll.addView(b3);
dialog.setContentView(ll);
dialog.show();
}
}
You need to use Shared Preferences Shared Preferences
whenever user rate your app you set the boolean variable to true and makes the check before showing the rate app dialog if the user has already rated it or not if your boolean variable is false you can ask the user to rate the app, otherwise user has already rated your app,Shared Preferences are app level variables that stores the data even you close the app they only get destroyed when you remove the app from your device or clear the data under the Applications in Android.
moreover can we track if users have rated our app, is there any google
api for this feature , can analytics be helpfull for tracking ratings
of an app
=> There isn't such official API available yet!
And SharedPreference is not gonna be helpful as there isn't any such API available, using which you would be able to track whether user has rated already!
When I added a button it should take me to skype application to a user (name_here) .. if Skype didn't exist on my mobile, it goes to https://play.google.com/store/apps/details?id=com.skype.raider
The code is
raskypelink.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
if (uri.contains("https://www.skype.com/" )) {
String name_here = "name_here";
String uri1 = "skype://Page/" + name_here;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri1));
startActivity(intent);
} else {
String skype = "skype";
String uri1 = "https://play.google.com/store/apps/details?id=com.skype.raider" + skype;
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri1));
startActivity(i);
}
}
});
Please help!
For IF
Android Docs - http://developer.skype.com/skype-uris/skype-uri-tutorial-android
For ELSE
Change from
String uri1 = "https://play.google.com/store/apps/details?id=com.skype.raider" + skype;
to
Remove + skype
String uri1 = "https://play.google.com/store/apps/details?id=com.skype.raider";
I am using the below class to rate my app. But the every time I do this, it says "Requested item not found". but the link < play.google.com/store/apps/details?id=com.xxx.xxx > works perfectly in the browser. Why is it not working here?
One more thing I noticed that if I change the package name to the same of some other app, it works. Is there any chance that something might have been missed while uploading the previous version?
public class apprater {
private final static String APP_TITLE = "abcd";
private final static String APP_PNAME = "com.xxx.xxx";
private final static int DAYS_UNTIL_PROMPT = 3;
private final static int LAUNCHES_UNTIL_PROMPT = 7;
public static void app_launched(Context mContext) {
SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0);
if (prefs.getBoolean("dontshowagain", false)) { return ; }
SharedPreferences.Editor editor = prefs.edit();
// Increment launch counter
long launch_count = prefs.getLong("launch_count", 0) + 1;
editor.putLong("launch_count", launch_count);
// Get date of first launch
Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0);
if (date_firstLaunch == 0) {
date_firstLaunch = System.currentTimeMillis();
editor.putLong("date_firstlaunch", date_firstLaunch);
}
// Wait at least n days before opening
if (launch_count >= LAUNCHES_UNTIL_PROMPT) {
if (System.currentTimeMillis() >= date_firstLaunch +
(DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) {
showRateDialog(mContext, editor);
}
}
editor.commit();
}
public static void showRateDialog(final Context mContext, final SharedPreferences.Editor editor) {
final Dialog dialog = new Dialog(mContext);
dialog.setTitle("Rate " + APP_TITLE);
LinearLayout ll = new LinearLayout(mContext);
ll.setOrientation(LinearLayout.VERTICAL);
TextView tv = new TextView(mContext);
tv.setText("If you enjoy using " + APP_TITLE + ", please take a moment to rate it. Thanks for your support!");
tv.setWidth(240);
tv.setPadding(4, 0, 4, 10);
ll.addView(tv);
Button b1 = new Button(mContext);
b1.setText("Rate " + APP_TITLE);
b1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME)));
System.out.println("eeeeeeeeeeeee: "+APP_PNAME);
dialog.dismiss();
}
});
ll.addView(b1);
Button b2 = new Button(mContext);
b2.setText("Remind me later");
b2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
ll.addView(b2);
Button b3 = new Button(mContext);
b3.setText("No, thanks");
b3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (editor != null) {
editor.putBoolean("dontshowagain", true);
editor.commit();
}
dialog.dismiss();
}
});
ll.addView(b3);
dialog.setContentView(ll);
dialog.show();
}
}
This what I am using now:
public void onClick(View v) {
final String appName = APP_PNAME;
try
{
mContext.startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=com.xxx.xxx")));
}
catch (android.content.ActivityNotFoundException anfe)
{
mContext.startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://play.google.com/store/apps/details?id=com.xxx.xxx")));
}
// mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME)));
dialog.dismiss();
}
Try this one
final String appName = getPackageName();
try
{
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id="+ appName)));
}
catch (android.content.ActivityNotFoundException anfe)
{
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://play.google.com/store/apps/details?id="+ appName)));
}
I've a mapview that displays an itemized overlay, and each onTap event shows a dialog with information about travel agency and three buttons, one of them is supposed to open the agency web site in the browser, but when i click the button i got : no activity found to handle Intent.
here's my code :
protected boolean onTap(int i){
float[] results = new float[1];
Location.distanceBetween(decdegrees(appState.getMyLocation().getLatitudeE6()), decdegrees(appState.getMyLocation().getLongitudeE6()), decdegrees(points.get(i).getPoint().getLatitudeE6()), decdegrees(points.get(i).getPoint().getLongitudeE6()), results);
float distance = results[0]/1000;
DecimalFormat maxDigitsFormatter = new DecimalFormat("#.#");
String infos=points.get(i).getSnippet() + "#" + String.valueOf(maxDigitsFormatter.format(distance));
final String [] AInfos = infos.split("#");
final Dialog ADialog = new Dialog(c);
ADialog.setContentView(R.layout.travelagency);
TextView txtAgence = (TextView)ADialog.findViewById(R.id.txtAgence);
TextView txtAddress = (TextView)ADialog.findViewById(R.id.txtAddress);
TextView txtDistance = (TextView)ADialog.findViewById(R.id.txtDistance);
TextView txtFax = (TextView)ADialog.findViewById(R.id.txtFax);
Button btnCall = (Button)ADialog.findViewById(R.id.btnCall);
Button btnWebSite = (Button)ADialog.findViewById(R.id.btnWebSite);
Button btnCancel = (Button)ADialog.findViewById(R.id.btnCancel);
ADialog.setTitle(AInfos[0]);
btnCall.setText("Appeler : " + AInfos[2]);
txtAgence.setText(AInfos[1]);
txtDistance.setText("Approximativement à : " +AInfos[6] + " Km");
txtAddress.setText("Adresse : " + AInfos[3]);
txtFax.setText("Fax : " + AInfos[4]);
ADialog.show();
btnCancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
ADialog.dismiss();
}
});
btnWebSite.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(Intent.ACTION_VIEW,Uri.parse(AInfos[5]));
v.getContext().startActivity(myIntent);
}
});
return (true);
}
I found examples here and here but suddently not work for me..
thanks
This will create the proper intent to open a web page in the default browser:
Uri url = Uri.parse("http://www.someUrl.com");
Intent intent = new Intent(Intent.ACTION_VIEW, url);
startActivity(intent);
Most probably your AInfos[5] is not a proper url. Hard-code a url like http://www.google.com and see if it works first. Also print what AInfos[5] contains.