PackageManager.getInstalledApplications(0); in Android 7.0 - android

My problem is that I use package manager to list all the installed applications
final PackageManager pm = parentActivity.getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(0);
With this code I can list successfully all the applications in other versions of android except in Android 7.0 (which only list the app that I'm using), can anyone knows why this is happening and how to solve it?

Try the below code. It is working fine for me:
final PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(0);
for (ApplicationInfo applicationInfo : packages) {
Log.d("APP_INFO", "App: " + applicationInfo.name + " Package: " + applicationInfo.packageName);
}
Tested on Android 6, 7 and 8
Hope this will help!

Related

Block installed app in android like applock app

I have to block installed application when the application is launched like applock android application.
I got list of installed application.I don't know how to block those applications.
final PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm
.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
Log.d("Package", "Installed package :" + packageInfo.packageName);
Log.d("Launch",
"Launch Activity :"
+ pm.getLaunchIntentForPackage(packageInfo.packageName));
}
I tried to kill app by using process id.It does n't work
android.os.Process.killProcess(10096);

Obtaining Build Target in android development

I want to obtain build target in run time and show it on the app. As I know build target is shown when you right click properties and select the android tab. But how can I get it in the code and show in run time on the activity?
Thanx.
You can read out your own ApplicationInfo:
PackageManager pm = context.getPackageManager();
ApplicationInfo info = pm.getApplicationInfo(
context.getPackageName(), PackageManager.GET_META_DATA );
Log.i( "Info", "Target SDK is: " + info.targetSdkVersion );
use Build.VERSION.SDK_INT, it returns a version that app was built on

Android - how to get installed package in JNI C code

I have a requirement to implement an equivalent of following java code in JNI C on android:
PackageManager pm = context.getPackageManager();
List<PackageInfo> packages = pm.getInstalledPackages(0);
for(PackageInfo packageInfo : packages) {
...
}
My question is how to get installed packages in JNI C. Is it even possible?
Thanks
Your best bet is to call PacakgeManager via JNI. There is no "C interface", you have to go through the system service. Installing a package does quite a few things, so just copying the APK to the right place is not enough.

How to Identify the package name for specified application(.apk) in android

My application contains some list of *.apk files.
I know only the application(example.apk) name.
How to identify this application(example.apk) package name through programmatically.
Is it possible.
Thanks in advance.
This will loop through installed applications and get package name and path to apk.
Assuming you have the ApplicationInfo for your apk, you can do the same approach as here (without loop).
PackageManager pm = getPackageManager();
for(ApplicationInfo app : pm.getInstalledApplications(0)) {
Log.d("PackageList", "package: " + app.packageName + ", sourceDir: " + app.sourceDir);
}

How to get the file *.apk location in Android device

Need some help by retrieving *.apk file name from Android device programmaticaly ? Could any body provide some Android methods doing that or even shell commands run under Android to get the file location , if I know just a part from file name ?
Also if there is a way how to find out where the *.apk file went after downloading from Market or outside Market ?
Thank you in advance.
List<ApplicationInfo> PackageManager.getInstalledApplications() will give you a list of the installed applications, and ApplicationInfo.sourceDir is the path to the .apk file.
PackageManager pm = getPackageManager();
for (ApplicationInfo app : pm.getInstalledApplications(0)) {
Log.d("PackageList", "package: " + app.packageName + ", sourceDir: " + app.sourceDir);
}
Outputs something like this:
package: com.tmobile.themechooser, sourceDir: /system/app/ThemeChooser.apk
package: com.tmobile.thememanager, sourceDir: /system/app/ThemeManager.apk
package: com.touchtype.swiftkey, sourceDir: /data/app/com.touchtype.swiftkey-1.apk
package: com.twitter.android, sourceDir: /data/app/com.twitter.android-2.apk
package: fm.last.android, sourceDir: /data/app/fm.last.android-1.apk
$ adb shell pm list packages -f
This gave me path in form /data/app/xxx.apk:
https://developer.android.com/reference/android/content/Context.html#getPackageResourcePath%28%29
You can also do adb bugreport and look at the output. You'll want to look for <package name="com.app.package" codePath="path/to/the/app.apk"...
The apps that you download go to /data/app so using ls you can get a list of the downloaded apks.

Categories

Resources