11

How to get App's Permission Detail for each app? how to do it programmatically?

I want to display "App's Permission Detail for each app" on TextView. But I try it but Not Ok??

Hello.java

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.content.Intent;
import android.content.Context;
import android.content.pm.*;
import android.widget.TextView;
import java.util.*;

public class HelloSakez extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final ListView lw = (ListView) findViewById(R.id.listView1);
final List<ResolveInfo> pkglist = lw.getContext().getPackageManager().queryIntentActivities(mainIntent, 0);
final TextView tw = (TextView) findViewById(R.id.textView1);
Iterator it = pkglist.iterator();
while(it.hasNext()){
ResolveInfo rf = (ResolveInfo)it.next();
tw.append(rf.toString());
}
}
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<ListView android:id="@+id/listView1" android:layout_height="wrap_content" android:layout_width="fill_parent"></ListView>
<TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>
Cody Gray
  • 222,280
  • 47
  • 466
  • 543
zhocker
  • 153
  • 1
  • 2
  • 11
  • please, give us more information. It is very difficult to understand what is your problem. Do you want to write an application which shows a list of applications with their permissions and ability to uninstall? – Vladimir Ivanov Mar 21 '11 at 08:03
  • Exactly, what do you want to know, how to get permissions, show permissions, or uninstall applications..? – Mudassir Mar 21 '11 at 08:05
  • @Vladimir Ivanov Yes!! I want example code for android. – zhocker Mar 21 '11 at 08:51
  • @Mudassir what do you want to know, how to get permissions, show permissions, or uninstall applications..? – I want to example code for each question. Because I am trying to find out 3 days ago. >///< I decided to ask questions. Sorry for I ask not good. Thank you for interesting my question. :) – zhocker Mar 21 '11 at 08:58
  • This question is a bit vague. Consider to ask one question to a specific problem, not three big questions inside one post. – Wroclai Mar 21 '11 at 09:17

4 Answers4

17

Use the following code in your activity:

I created StringBuffer appNameAndPermissions = new StringBuffer(); to append all the apps and permisssions info.

It's working fine. I tested it already. If you have any issues, please let me know.

StringBuffer appNameAndPermissions = new StringBuffer();
PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

for (ApplicationInfo applicationInfo : packages) {
    Log.d("test", "App: " + applicationInfo.name + " Package: " + applicationInfo.packageName);
try {
    PackageInfo packageInfo = pm.getPackageInfo(applicationInfo.packageName, PackageManager.GET_PERMISSIONS);
    appNameAndPermissions.append(packageInfo.packageName+"*******:\n");

    //Get Permissions
    String[] requestedPermissions = packageInfo.requestedPermissions;
    if(requestedPermissions != null) {
        for (int i = 0; i < requestedPermissions.length; i++) {
            Log.d("test", requestedPermissions[i]);
            appNameAndPermissions.append(requestedPermissions[i]+"\n");
        }
    appNameAndPermissions.append("\n");
} catch (NameNotFoundException e) {
    e.printStackTrace();
}

Use the following permission in your AndroidManifest.xml file:

<uses-permission android:name="android.permission.GET_TASKS"/>

techfly
  • 1,545
  • 3
  • 23
  • 26
Shaahul
  • 508
  • 4
  • 11
  • 2
    why do you need this persmission? you don't use it here. Also, you don't need to use StringBuffer, as you don't have multiple threads running... About the permissions, I think you can use "loadLabel" so that they will have the same name as shown to the user. – android developer Sep 06 '14 at 23:25
  • For some reason, when using the call to "getInstalledApplications" that you had, I get null for applicationInfo.name – android developer Nov 01 '15 at 14:43
5

You need to use PackageManager's GET_PERMISSIONS flag.

Check this question.

Community
  • 1
  • 1
Macarse
  • 87,001
  • 42
  • 169
  • 229
0

Zhocker

To uninstall any app use below code

Intent i = new Intent(Intent.ACTION_DELETE);
i.setData(Uri.parse("package:com.package name"));
startActivity(i); 

And to get permissions use getInstalledPackages(int) with the flag GET_PERMISSIONS

Bill the Lizard
  • 369,957
  • 201
  • 546
  • 842
100rabh
  • 6,028
  • 5
  • 24
  • 40
-3
  1. For App's permission go to Manifest file ans see.

2.for uninstall the app follow the below points:-

a. go to setting b. then Open Application c. then open Manage Application d. then choose the app which you want to Uninstall e. then click on Uninstall and Uninstall the app.

AndroidDanger
  • 1,019
  • 1
  • 9
  • 17
  • Oh >///< How I get "App's Permission" and show "App's Permission" List and uninstall for each application on Android. Sorry I ask not good. How to use code for get "App's Permission" and show "App's Permission" List and uninstall for each application on Android. Example Code for me. please. I want to ask that. Thank you for answer me. AndroidDanger Do you know answer for new question?? answer me. please – zhocker Mar 21 '11 at 08:38
  • 3
    Buddy, not downvoted but he is asking about how to do it programmatically? – Mudassir Mar 21 '11 at 09:14
  • @Mudassir I want that you say. I am trying to find answer for my question. 3 day ago. Haha I find link that is [link](http://stackoverflow.com/questions/2695746/how-to-get-a-list-of-installed-android-applications-and-pick-one-to-run) But I am newbie for android programming. I studied it about a week. I have a problem, so this point could not be developed. Now!! I am trying to find answer for my question. :) – zhocker Mar 21 '11 at 09:23
  • @Zhocker: The link you mentioned is about getting the list of installed apps while you are asking about permissions. I don't clearly understand what do you want? – Mudassir Mar 21 '11 at 09:27
  • @ Mudassir I want to example code to show list of installed apps. Why I are asking about permissions"? Answer : I want to show list of installed apps that show detail about permissions for each apps. I want example code about that. You understand me? :) – zhocker Mar 21 '11 at 09:28