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!
Related
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.
It's possible to get if an app is currently installed on the sd-card or not, by using the next code, using the ApplicationInfo flags :
final boolean isInstalledOnExternalStorage=(applicationInfo.flags&ApplicationInfo.FLAG_EXTERNAL_STORAGE)!=0;
However, what I'd like to know is how to get the requested installation location as specified by the manifest (described here) of an installed app.
Sadly, as much as I've read here and on the documentation, I can't find out where this attribute's values can be fetched, unless maybe I'd need to parse the APK file myself...
So, how do I achieve it? Is it even possible using the normal Android framework?
Look at this code, it works in my app:
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(mPackageName, 0);
if (packageInfo.installLocation != PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY) {
.....
}
http://developer.android.com/reference/android/content/pm/PackageInfo.html#installLocation
was introduced in API 21
But this field exists even in Android 2.3
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.3_r1/android/content/pm/PackageInfo.java/
IThe scenario is that my application search all installed application in order to determine versions of those applications. Then store name of the application with its versions on the same file. If new version of the application is available, then give notification to the user. The question is "how can I learn the version of the other application from my application ?"
Thanks for all your help
Something like this should work to get the current version:
List<PackageInfo> packages = getPackageManager().getInstalledPackages();
for(int i=0;i<packages.size();i++)
{
int version = packages.get(i).versionCode;
// do whatever with it here
}
Getting the most recent version in the Play Store doesn't really work, though. Like A--C said, you could check versionName instead, and just notify as updated if the two aren't exactly the same(don't worry about higher/lower, just inequality).
You can do following (inside of Activity or any other Context)
getPackageManager().getPackageInfo(getPackageName(), 0).versionName
getPackageManager().getPackageInfo(getPackageName(), 0).versionCode
Is there anyway to notify the users (inside of my application) if newer versions is published? perhaps through Dialog?
Usually in web client android application we make a request to the server for getting the current version.
Use
String versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0 ).versionName;
And compare and notify the user with a dialog.
Santosh's solution just allow you to access to the "android:versionName" attribute in your manifest.
look at Android Market Application Updates.
It could help you
I'm working on an app that extends the functionality of another, existing app. I want to know what the easiest way is to determine, through code, whether the first app is installed, preferably by referencing it by com.whoever.whatever but almost any criteria would be helpful.
android.content.pm.PackageManager mPm = getPackageManager(); // 1
PackageInfo info = mPm.getPackageInfo(pName, 0); // 2,3
Boolean installed = info != null;
Used in an activity, you need a context to get the PackageManager
Throws PackageManager.NameNotFoundException, I guess. check!
pName is something like 'com.yourcompany.appname', the same as the value of 'package' in the manifest of the app
The recommended way is to check whether the other application publishes an Intent. Most Intent are not owned by a particular app, so, say, if you're looking for a program that publishes "sending mail" intent, the program that gets opened may be Gmail application or Yahoo Mail application, depending on the user's choice and what was installed in the system.
You may want to look at this: http://developer.android.com/guide/topics/intents/intents-filters.html
Starting Android 12, this requires android.permission.QUERY_ALL_PACKAGES permission, which Google Play may or may not allow you to have
See more details https://developer.android.com/training/package-visibility