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);
Related
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!
Is it possible to get package name of the installing application before app installed. i.e., While showing installer activity itself can we find?
Thanks.
We can get package name of application from .apk file using its filepath.
PackageInfo packageInfo = getPackageManager().getPackageArchiveInfo(filepath,PackageManager.GET_ACTIVITIES);
if(packageInfo != null) {
ApplicationInfo appInfo = packageInfo.applicationInfo;
String package_name= appInfo.packageName;
}
where filepath is a String containing filepath of the apk e.g. "/sdcard/xyz.apk".
Make sure you add READ_EXTERNAL_STORAGE uses permission in AndroidManifest.xml
I hope this helps.
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
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.
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);
}