How to get android:installLocation value of a specified app? - android

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/

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!

Integrating Air Watch Android Studio

I am very much new to AirWatch Concept but had gone thoroughly about AirWatch. I have gone through the following links,
http://developer.air-watch.com/android/application-configuration-with-the-android-sdk/
http://developer.air-watch.com/android/android-sdk-setup/
but in vain.
Could anyone please help me regarding the integration of Air Watch in Android ?
Things i have done so far,
I have created app in the https://apidev.awmdm.com, and i have added assignemnts. The question here is, How can i get the assignment details in my android application that were added in the Air Watch Console.
Help is really appreciated.
Update:
I am able to create and push the application from AIR WATCH CONSOLE to my Device. Now, the issue i am facing is, If i am adding some application configuration in the AIR WATCH CONSOLE, i am not able to get those details in my application.
I have gone through the below Url for the above scenario,
https://appconfig.org/android/ which is very much similar to https://appconfig.org/ios/
I have implemented those things that were mentioned in the above url but still then i am not able to get those details.Please let me know if i am wrong anywhere.
I got to know that the key value pairs that were being passed in Air watch console will be coming into com.apple.configuration.managed key in iOS. Does any one have an idea that how these key value pairs will come. As far as i know, they will be handled via Restriction Manager. But no idea/clue how to handle in Android.
Updated:
xml/app_restrictions.xml:
<?xml version="1.0" encoding="utf-8"?>
<restrictions xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<restriction
android:key="ManagedServer"
android:restrictionType="string"
android:title="Managed Server"
tools:ignore="ValidRestrictions" />
<restriction
android:key="#string/mdm_key_managed_server_name"
android:restrictionType="string"
android:title="#string/mdm_key_managed_server_url"
tools:ignore="ValidRestrictions" />
<restriction
android:key="#string/mdm_key_managed_server_url"
android:restrictionType="string"
android:title="#string/mdm_key_managed_server_url"
tools:ignore="ValidRestrictions" />
</restrictions>
oncreate Method :
IntentFilter restrictionsFilter =
new IntentFilter(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED);
BroadcastReceiver restrictionsReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
// Get the current configuration bundle
Bundle appRestrictions = myRestrictionsMgr.getApplicationRestrictions();
// Check current configuration settings, change your app's UI and
// functionality as necessary.
Toast.makeText(LoginActivity.this, "Reciever Called", Toast.LENGTH_LONG).show();
RestrictionsManager myRestrictionsMgr =
(RestrictionsManager)
getSystemService(Context.RESTRICTIONS_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
if (myRestrictionsMgr != null) {
Bundle appRestrictions = myRestrictionsMgr.getApplicationRestrictions();
if (appRestrictions != null) {
if (appRestrictions.containsKey("ManagedServer")) {
String mConfigDetails = appRestrictions.getString("Managed Server");
Toast.makeText(LoginActivity.this, "" + mConfigDetails, Toast.LENGTH_LONG).show();
}
}
}
}
}
};
registerReceiver(restrictionsReceiver, restrictionsFilter);
List of Users:
When i am actually trying the other command:
Update:
Created a sample app and published to Play Store. App link as follows,
https://play.google.com/store/apps/details?id=com.manu.samplemdm
Now, its a play store app. When I am sending Application Configuration but unable to receive it in the Application. Its giving me still empty bundle from the application.
Help would be really appreciated.
Help is really appreciated
Beside AirWatch Resources, which tells you how you can create an app and set the app configurations,key-value pairs, to push to your devices, You need to check out Android Restriction Manager API. Follow the steps described in the link.
How the whole process works is, AirWatch controls AndroidForWork environment after you set your MDM as AirWatch. And then, AirWatch manages the device from AirWatch console and it pushes the App Configuration to AndroidForWork in your device. You need to implement Android Restriction Manager to access to these data passed you by your MDM. It goes same for all of the MDMs in the Market.
Update:
In order to install your app into Work Container in the development phase, you can use adb to copy it from Personal Container to Work Container.
First, list all of the active users in the device:
./adb shell pm list users
And later, find the Work User's ID from the List of Users and set it in the command below along with your app's package name and App's Main Activity.
./adb shell am start —user 13 -n “your.apps.package.name/your.main.activity.package.name”
13 up there in the command is the Work User's ID. In my case, it's 13.
For more information about ./adb commands in Managed Profiles, see this link and check the most bottom of the page.
There are a couple of different approaches to integrating with AirWatch. It depends on the technology set you're trying to use. I think these are the 2 that are most relevant to you based on what I see in your post:
AirWatch SDK
AppConfig Standard
Both these approaches can accomplish similar functionality but each have different deployment requirements. It sounds like you have gone with the second approach which is using the AppConfig standard and the native APIs provided by Google to have an app read configuration values delivered through AirWatch.
One important thing to note is the AppConfig standard approach on Android requires the device to support "Android for Work" enrollment which is a relatively newer management protocol released by Google. It's worth noting that AirWatch does support Android for Work enrollment so it may just be a matter of getting your AirWatch test instance configured for "Android for Work enrollment" instead of the traditional older Android enrollment protocol. More information about Android for Work can be found here:
https://enterprise.google.com/android/solutions/personal/
If you're already a customer of AirWatch, it may be helpful to create an account here on their resource portal if you haven't done so already to get access to documentation about how you can setup Android for Work within AirWatch. https://resources.air-watch.com
I hope this helps.

how to determine an application version from own application

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

How can we know whether an application installed in the android device reads contacts of our mobile?

I have one small problem i.e whenever we install an application in our android mobile we need to find whether that application reads our contacts or not. If that application reads contacts then we have to raise one alert box with red mark and with some information. So thats why i am creating one application to find, the newly installed application reads our contacts or not.
Pls help me.
Thanks and regards.
Possible duplicate...
Answer is here: Java: Need some way to shorten this code
PackageManager p = context.getPackageManager();
final List<PackageInfo> appinstall =
p.getInstalledPackages(PackageManager.GET_PERMISSIONS |
PackageManager.GET_PROVIDERS)
If an application can read contacts it requires android.permission.READ_CONTACTS permission. If you want to specify some particular contacts that should raise an alert then you cannot do this on an application level. You need to get down to the Android Framework level and build your own version of Android.

Android - check for presence of another app

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

Categories

Resources