i think you are getting this error because the signature is not the same between store version (signed by your release key) and the studio-run version which is signed by the debug key (exist in android data folder)
so this is regarding the error, you have to build the APK as if you will upload it to the store, and sign it with your release keystore... then install it on the device (using adb install
or adb push then install from mobile, or copy apk to mobile memory then install from mobile ... etc) maybe?
now regarding the second part, detect 1st run of app/ detect 1st run after app update, you can use SharedPreferences
as advised by that answer. but this will not be sufficient, as it will not be linked/effected by app version, and thats what you need to detect 1st run after upgrade.
what you need to do is to get app version-code (which is integer) that you specify on manifest file android:versionCode
, and you have to increase it every time you upload a version to the PlayStore.
this code will do what you need (you can use it in the activity/fragment that you wish to show the dialog on)
//this code gets current version-code (after upgrade it will show new versionCode)
PackageManager manager = this.getPackageManager();
PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
int versionCode = info.versionCode;
SharedPreferences prefs = this.getSharedPreferences("yourAppName", Context.MODE_PRIVATE);
if(prefs.getInt("last_version_code", -1) > 0){
if(prefs.getInt("last_version_code", -1) != versionCode){
//save current versionCode: 1st-run after upgrade
prefs.edit().putInt("last_version_code", versionCode).commit();
//put show the dialog code here...
} //no need for else, because app version did not change...
}else{
//save current versionCode for 1st-run ever
prefs.edit().putInt("last_version_code", versionCode).commit();
}
prefs.getInt("last_version_code", -1)
this will get last saved value in the preferences for key last_version_code
and in case no value (1st run ever) it will return -1
as default.
the if
checks the value returned from preferences > 0 (not first run)
and it does NOT equal the one in manifest. that will mean (UPGRADED)
in case of ==-1
you just write the versionCode so next time you try to get that value it will return a number (last version code saved)
if you want to use it as a method (may be called in multiple places)
create a method to return true/false if app was updated
public static boolean appWasUpdated(Context context){
//this code gets current version-code (after upgrade it will show new versionCode)
PackageManager manager = context.getPackageManager();
PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
int versionCode = info.versionCode;
SharedPreferences prefs = context.getSharedPreferences("yourAppName", Context.MODE_PRIVATE);
if(prefs.getInt("last_version_code", -1) > 0){
if(prefs.getInt("last_version_code", -1) != versionCode){
//save current versionCode: 1st-run after upgrade
prefs.edit().putInt("last_version_code", versionCode).commit();
return true;
} //no need for else, because app version did not change...
}else{
//save current versionCode for 1st-run ever
prefs.edit().putInt("last_version_code", versionCode).commit();
}
return false;
}
and just call this method from activity/fragment
if(appWasUpdated(this)){
showMyDialog();
}