How to prompt a message is app already exist in Android - android

I want to display an alert message on installing a non-market App. For example, If I have an App "ABC" installed in my phone and I want to install its latest version, So on installing, I want to prompt a message "ABC App of is already installed, Do you want to install its latest version ?". If user clicks on yes button, latest App should start installing else installation is terminated.
How do I achieve this?

In your app, use this
PackageInfo pkg = getPackageManager().getPackageInfo(getPackageName(), 0);
String version = pkg.versionName;
int Vcode = pkg.versionCode;
You get the version code of app. Now use a if condition to compare your app version with old version and set alert dialog. Else no alert dialog.

Actually, Now, on android phones if latest version of an application is about to install, android itself prompt a dialog box. on that a list of new permissions needed and an ok also a cancel button . So, you dont have to do it by yourself. :)

Related

Defining custom uses_feature in android app

I know we can define a custom permission in one app and other app can ask for this permission using uses_permission tag.
My problem is, I have 2 apps and one app is dependent on other to work as expected. As both the apps will be updated from play store over time, their versions has to be in sync so that they can interact and work without any issues.
User should be able to install/update app B to version 2 only if they have already installed/updated version 2 of app A.
My idea is, if this can be handled by defining something (uses_feature where we can define version also, just like glesVersion) in manifest file itself, then user will not see update available of app B, if they have not updated app A already.
I hope I have explained my problem clearly. Please suggest some solution.
While opening your launcher activity all you ought to do is check
the version of that package you have installed and then show them the
update.
You need to figure out what is the right package name of your installed application on your device.
Getting Package Info:
PackageInfo pinfo = null;
pinfo = getPackageManager().getPackageInfo("com.yourapplication.android", 0);
//getVersionCode is Deprecated, instead use getLongVersionCode().
long verCode = pinfo.getLongVersionCode();
//getVersionName is Deprecated, instead use versionName
String verName = pinfo.versionName;
Then you can check in here like,
if(verName.contentEquals("your new version") {
// do something such as update
}
else {
// function normally
}
Hope it helps!

Keep an internal app updated

I'm going to develop an android app for a museum, which will handle a tablet with the app installed on it to the visitors.
The app will be on foreground full time and visitor will only be able to use this app.
Since there will be many tablets, and they are all under our control, I would like a way to update all the tablets remotly with the last version of the app.
Is there a way to achive this?
Is there a way to achive this?
Answer is : Yes but with one exception lets have a look.
Step 1 : Create a local server for your museum. I guess it is already in the museum.
Step 2 : Now In your android application whenever you start your app check that whether new version of APK is available. For checking APK new version you can use this code.
PackageInfo packageInfo = getPackageManager().getPackageInfo(context.getPackageName(), 0);
int apkVersion = packageInfo.versionCode;
You should set your APK name like "yourAppname_version" so whenever you upload the new app to your local server just change the name so you can easily identify that new version of APK is available or not.
Step 3 : If new version is available then start downloading APK from the local server and save it to your storage directory.
Step 4 : When downloading completed you can call this set of code to install the new APK.
Intent intentApkInstall = new Intent(Intent.ACTION_VIEW);
intentApkInstall.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory()+"/"+"yourAppname_version.apk")), "application/vnd.android.package-archive");
intentApkInstall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentApkInstall);
Now the Exception part is here the above code will prompt user to install APK. So in this case you have to install it manually.

Force update for the latest version of android app

I am trying to figure out how to forcefully update the latest version from play store.
As the older version of my android app is already in play store where i haven't implement the check to get the current version of the app and compare with the play store app version like specified in the link update android app forcefully
I want that when I upload my new version on play store then user should not be able to use the app till he update the new version.
Could you please help me out.
I have to do the same thing but what i did i gonna share you i hope this will help you.
1> I get the previous code version of my application and store it the string.xml. like my live app version code is 1. And my new app version code is 1.1.
This code is tell us our app version code.
PackageInfo pinfo = getPackageManager().getPackageInfo(getPackageName(), 0);
int versionNumber = pinfo.versionCode;
String versionName = pinfo.versionName;
2> Than check
if (newcodeversion > previouscodeversion) {
// open any activity or pop up
}
3> And in the new activity place Text view with text "you have update version" and a button.And on the click of that button navigate to google play store.
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("Your application URL"));
startActivity(i);
It is not possible if the logic of comparing the versionCode and blocking the user isn't already placed inside the current app on PlayStore.
This is not difficult to do. Simply bar the user from having the core functionality of what ever your app is responsible for.
Example, if it is a calling app, do a version check, and if the user has not updated as yet, restrict the use of call making entirely.
According to #pieter-b, taken from Forcing Updates:
For this to work, some kind of logic the app uses needs to be under your control. And then without that part of logic the app won't work
and you can show a message: "your app is out of date, please download
the new version to continue use."
Consider a messenger app where traffic goes through your servers. Just
refuse to deliver messages of clients using an outdated version.
Also refer to Force update android app when new version available.

How to check some dependency before installation of an application in Android

I make two android application first one is installer app that download and install my application.
Now i just want to make second application that would not be install from outside installer, means before installing second application it will check that first app is installed or not, if first application is not install it will recommend that it is necessary to install first application before second application.
Please give me suggestion i am new on android
Thanks
You can do this with package name using PackageManager.
try{
ApplicationInfo appInfo = getPackageManager()
.getApplicationInfo("com.abc.firstApp", 0 );
// application exists
} catch(NameNotFoundException nnfe ){
// application doesn't exist
}
replace com.abc.firstApp with your first app's package name.
You can't do this during install process. You have to check this from your second app. after finish installation of second app.

Is it possible to programmatically uninstall a package in Android

Can a package uninstall itself? Can a package uninstall another package if they share the same userId and signature?
Uri packageURI = Uri.parse("package:"+"your.packagename.here");
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
startActivity(uninstallIntent);
A 3rd party app cannot install or uninstall any other packages programmatically, that would be a security risk for Android. However a 3rd party app can ask the Android OS to install or uninstall a package using intents, this question should provide more complete information:
install / uninstall APKs programmatically (PackageManager vs Intents)
In Kotlin, using API 14+, you can just call the following:
startActivity(Intent(Intent.ACTION_UNINSTALL_PACKAGE).apply {
data = Uri.parse("package:$packageName")
})
Or with Android KTX:
startActivity(Intent(Intent.ACTION_UNINSTALL_PACKAGE).apply {
data = "package:$packageName".toUri()
})
It will show the uninstall prompt for your app. You can change packageName to any package name of another app if needed.
Third Party app cannot Uninstall App Silently!
Either you need to become System App to get DELETE_PACKAGES Permission else you need to show Uninstall Popup (User Confirmation)
Alternatively, you can take Accessibility permission and then by showing an Accessibility Overlay you can tell your service to click on Uninstall button! But that will be privacy violation.

Categories

Resources