Is it possible to get the manifest permissions of any installed Android application?
Thanks for the hint,got it running with:
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0);
for (Object obj : pkgAppsList) {
ResolveInfo resolveInfo = (ResolveInfo) obj;
PackageInfo packageInfo = null;
try {
packageInfo = getPackageManager().getPackageInfo(resolveInfo.activityInfo.packageName, PackageManager.GET_PERMISSIONS);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] requestedPermissions = packageInfo.requestedPermissions;
}
Get installed packages using this.
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0);
And use the package name to get the info.
http://developer.android.com/reference/android/content/pm/PackageInfo.html
If you have apk file it is very simple just open cmd from start menu and write this command line:
aapt d permissions D:\dina\app-debug.apk
take care for the path you write then you can get list from all permissions in this application and package name also like this:
package: com.example.dinasaif.facebookintegration
uses-permission: android.permission.INTERNET
Related
I have a listview which show the all installed apps including some system apps but does not show gallery, contact, messages apps. Please tell me how can I get all these system apps. Here is my code
public static List getInstalledApplication(Context c)
{
// return c.getPackageManager().getInstalledApplications(PackageManager.GET_META_DATA);
List<ApplicationInfo> installedApps = new ArrayList<ApplicationInfo>();
PackageManager pm = c.getPackageManager();
List<ApplicationInfo> apps = pm.getInstalledApplications(0);
for(ApplicationInfo app : apps) {
//checks for flags; if flagged, check if updated system app
if((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1) {
installedApps.add(app);
//it's a system app, not interested
} else if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
//Discard this one
//in this case, it should be a user-installed app
// installedApps.add(app);
} else {
installedApps.add(app);
}
}
return installedApps;
}
Tell me where I make mistake. Help me with some code.
The apps that you want to list (Gallery, Message, etc) are written in system partition and hence, (app.flags & ApplicationInfo.FLAG_SYSTEM) == 1) will be true.
FLAG_SYSTEM
if set, this application is installed in the device's system image.
Thats why the apps that you want to also list are getting skipped.
If you want to get apps which are listed in your launcher i.e apps with category <Launcher> get the list using following code
final PackageManager packageManager = getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> resInfos = packageManager.queryIntentActivities(intent, 0);
// using hashset so that there will be no duplicate packages,
// if no duplicate packages then there will be no duplicate apps
HashSet<ApplicationInfo> installedApps = new HashSet<ApplicationInfo>(0);
// getting package names and adding them to the hashset
for (ResolveInfo resolveInfo : resInfos) {
installedApps.add(resolveInfo.activityInfo.applicationInfo);
}
Since you want to show all the installed apps. You could get rid of the if-else block in your code and simply add all the apps and display them.
or make these change in you code
1) Fetch all the apps by this code.
List<ApplicationInfo> apps = getPackageManager().getInstalledPackages(0);
2) And separate system apps from user installed with the following code:
List<ApplicationInfo> apps = getPackageManager().getInstalledApplications(0);
for(ApplicationInfo app : apps) {
if((app.flags & (ApplicationInfo.FLAG_UPDATED_SYSTEM_APP | ApplicationInfo.FLAG_SYSTEM)) > 0) {
// It is a system app
} else {
// It is installed by the user
}
}
Try this different ways.
//First
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List pkgAppsList = context.getPackageManager().queryIntentActivities(mainIntent, 0);
// Second
PackageManager pm = getPackageManager();
List packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages)
{
Log.d(TAG, "Installed package :" + packageInfo.packageName);
Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName));
}
// Third
private List getInstalledComponentList()
throws NameNotFoundException {
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List ril = getPackageManager().queryIntentActivities(mainIntent, 0);
List componentList = new ArrayList();
String name = null;
for (ResolveInfo ri : ril) {
if (ri.activityInfo != null) {
Resources res = getPackageManager().getResourcesForApplication(ri.activityInfo.applicationInfo);
if (ri.activityInfo.labelRes != 0) {
name = res.getString(ri.activityInfo.labelRes);
} else {
name = ri.activityInfo.applicationInfo.loadLabel(
getPackageManager()).toString();
}
componentList.add(name);
}
}
return componentList;
}
Good day!
Are there some tools in Android SDK, that i can use to remove application from activity. In particular, i need activity method, that removes other application with the same app-name, but other package.
If you mean with "same name app" to app with same label that define in XML menifest as the label of your app, this snippest should work:
private void deleteAppByActivityName(#NonNull String myAppLabel,#NonNull Context context){
try {
PackageManager pm = context.getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> dataInDevice = pm.queryIntentActivities(mainIntent, 0);
for (ResolveInfo resolveInfo : dataInDevice){
String label = resolveInfo.loadLabel(pm).toString();
if (label.equals(myAppLabel)) { //we find app with same name as ours
Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:" + resolveInfo.activityInfo.packageName));
context.startActivity(intent);
break;
}
}
}catch (ActivityNotFoundException e){
e.printStackTrace();
}
}
I try to remove application from another application in android but When I run below code I got a this error "The application was not found in the list of installed applications" how can I solve this problem furthermore try to remove application has a many package which can I use?
Uri packageURI = Uri.parse("package:com.example.anke");
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
startActivity(uninstallIntent);
try below code and see your application's package name in your device and use this package name which you want to remove application.
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getApplicationContext().getPackageManager().queryIntentActivities( mainIntent, 0);
You can check for whether particular application is installed or not like below
private boolean isApplicationInstalled(String packagename, Context context) {
PackageManager packageManager = context.getPackageManager();
try {
packageManager.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
return true;
} catch (NameNotFoundException e) {
return false;
}
}
If you get true go for uninstall, if false then application is not installed.
I want to open Android Wear Start Screen (the one with red G icon and text 'Speak Now') from my app. Is this possible?
thanks.
w
It's not possible to launch this exact screen (no API for that).
However you can easily recreate a similar screen yourself.
This code lists the activities available in the launcher:
final PackageManager packageManager = getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> resInfos = packageManager.queryIntentActivities(intent, 0);
//using hashset so that there will be no duplicate packages,
//if no duplicate packages then there will be no duplicate apps
HashSet<String> packageNames = new HashSet<String>(0);
List<ApplicationInfo> appInfos = new ArrayList<ApplicationInfo>(0);
//getting package names and adding them to the hashset
for(ResolveInfo resolveInfo : resInfos) {
packageNames.add(resolveInfo.activityInfo.packageName);
}
//now we have unique packages in the hashset, so get their application infos
//and add them to the arraylist
for(String packageName : packageNames) {
try {
appInfos.add(packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA));
} catch (NameNotFoundException e) {
//Do Nothing
}
}
//to sort the list of apps by their names
Collections.sort(appInfos, new ApplicationInfo.DisplayNameComparator(packageManager));
Then show the elements in appInfos into a WearableListView.
Source:
https://stackoverflow.com/a/24351610/540990
I'm looking for the best way to check if application is launchable.
There is my code :
PackageManager packageManager = context.getPackageManager();
List<PackageInfo> packs = packageManager.getInstalledPackages(0);
for (int i = 0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
if (packageManager.getLaunchIntentForPackage(p.applicationInfo.packageName) != null) {
// Get application info
}
}
This works, but when i do app profiling i noticed that packageManager.getLaunchIntentForPackage() method consumes a lot of execution time, so i'm looking for an alternative way to check if each application is launchable without getting the launch intent.
Any idea ?
Thank you !
I found solution for my own problem, i hope it will help someone :
PackageManager packageManager = context.getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List<ResolveInfo> apps = packageManager.queryIntentActivities(
mainIntent, 0);
Collections.sort(apps, new ResolveInfo.DisplayNameComparator(
packageManager));
for (ResolveInfo resolveInfo : apps) {
// Get application data here
}