Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

import android.util.Log;

public class Main {
    /**
     * get all <uses-permission> tags included under <manifest>
     * 
     * @param context
     */
    public static void getAllAppPermissions(Context context) {
        PackageManager pm = context.getPackageManager();
        PackageInfo packageInfo;
        try {
            // Array of all <uses-permission> tags included under <manifest>, or
            // null if there were none.
            packageInfo = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);
            String permissions[] = packageInfo.requestedPermissions;

            if (permissions != null) { // to list permission
                for (String permission : permissions) {
                    Log.i("4A", "permission:" + permission);
                }
            }

        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
    }
}