현재 설치된 앱이 업데이트 된 버전 (Play 스토어에서 사용 가능)이 아닌 경우 알림 또는 대화 상자를 표시하려고합니다.새 버전의 Android 앱을 사용자에게 알립니다.
어떻게 할 수 있습니까?
현재 설치된 앱이 업데이트 된 버전 (Play 스토어에서 사용 가능)이 아닌 경우 알림 또는 대화 상자를 표시하려고합니다.새 버전의 Android 앱을 사용자에게 알립니다.
어떻게 할 수 있습니까?
...
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();
}
}
그리고 기능 displayAlertDialogforPlayStore는()입니다 .. .. 당신의 Gradle을 파일에
com.github.rampo.updatechecker:library:2.1.8
을이 종속성을 추가하고 활동이 코드를 시도
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();
}
}
이 코드는 알림 및 업데이트 용 alertDailog를 모두 표시합니다.
귀하의 질문은 중복 된 것 같습니다. 나는 정말로 비슷한 질문에 대한 답을 썼다. 그것을 확인해보고 우리가 알아 내면 안될까요? http://stackoverflow.com/a/40029702/3732187 –