-3

I want to show a notification or dialog (when app opens) if the current installed app is not the Updated Version (available in play store).

How can i do that?

akkk
  • 1,457
  • 4
  • 23
  • 41

2 Answers2

0

You can use Firebase notifications as described here. You can choose your segment (e.g. app version) as described here.

HormCodes
  • 89
  • 6
  • I think your question is duplicate. I wrote an answer for a question that is really similar. Could you please check it out and see if we figure it out? http://stackoverflow.com/a/40029702/3732187 – Vansuita Jr. Oct 13 '16 at 19:55
0

add this dependency to your gradle file..

com.github.rampo.updatechecker:library:2.1.8

And try this code in your Activity..

public static String NEW_VERSION = "1.1.0";
public void checkForAppUpdate () {
        try {
            if (!((Activity) context).isFinishing()) {
                    UpdateChecker.setNotice(Notice.NOTIFICATION);
                    UpdateChecker.setNoticeIcon(R.drawable.your_notification_logo);
                    String s = "Hello User, New version of this application is now available on play store.";
                    if (Comparator.isVersionDownloadableNewer((Activity) context, NEW_VERSION)){

                        SharedPreferences pref = context.getSharedPreferences(UpdateChecker.PREFS_FILENAME, 0);
                        boolean b = pref.getBoolean(UpdateChecker.DONT_SHOW_AGAIN_PREF_KEY + NEW_VERSION, false);
                        if (!b) {
                            displayAlertDialogforPlayStore(context, "Update Available", s);
                        }
                    }
}
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

And Function displayAlertDialogforPlayStore() is...

public void displayAlertDialogforPlayStore(final Context context, String title,
                                               String message) {
        try {
            final AlertDialog.Builder alert = new AlertDialog.Builder(context);

            alert.setIcon(R.drawable.your_notification_logo);
            if (title != null) {
                alert.setTitle(title);
            }
            alert.setMessage(message);

            alert.setPositiveButton("Update Now", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {



                    final String appPackageName = context.getPackageName();
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse("market://details?id=" + appPackageName));
                    context.startActivity(intent);
                }
            });

            alert.setNegativeButton("Later", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            });

            alert.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

This code display both notification and alertDailog for update.

Jitesh Prajapati
  • 2,533
  • 4
  • 29
  • 51