Java tutorial
//package com.java2s; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.text.TextUtils; public class Main { private static Context mContext = null; public static void hasPermission() { if (mContext == null) throw new NullPointerException("you must initialize in appliction to use: CCCoreUtil.init"); PackageManager pm = mContext.getPackageManager(); PackageInfo pInfo = null; try { pInfo = pm.getPackageInfo(mContext.getPackageName(), PackageManager.GET_PERMISSIONS); String[] permissions = pInfo.requestedPermissions; for (String permission : permissions) { if (TextUtils.equals(mContext.getPackageName() + ".permission." + "WANG_CC_CONG", permission)) return; } } catch (Exception e) { // TODO: handle exception System.out.print("Authentication failed, you must register WANG_CC_CONG permission like:" + " <uses-permission android:name=\"PACKNAME.permission.WANG_CC_CONG\" />"); throw new RuntimeException("you must register WANG_CC_CONG permission like:" + " <uses-permission android:name=\"PACKNAME.permission.WANG_CC_CONG\" />"); } System.out.print("Authentication failed, you must register WANG_CC_CONG permission like:" + " <uses-permission android:name=\"PACKAGENAME.permission.WANG_CC_CONG\" />"); throw new RuntimeException("you must register WANG_CC_CONG permission like:" + " <uses-permission android:name=\"PACKNAME.permission.WANG_CC_CONG\" />"); } }