PackageManager checkPermission - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for PackageManager checkPermission method.

This code example shows how to use the following methods:checkPermission
        if (pm == null) {
            return false; 
        } 
 
        try { 
            return pm.checkPermission(permission, context.getPackageName()) == PackageManager.PERMISSION_GRANTED;
        } catch (RuntimeException e) {
            // To catch RuntimeException("Package manager has died") that can occur on some version of Android, 
            // when the remote PackageManager is unavailable. I suspect this sometimes occurs when the App is being reinstalled. 
            return false; 
        } 
    } 
 
    /** 
     * @return PackageInfo for the current application or null if the PackageManager could not be contacted. 
     */ 
    public PackageInfo getPackageInfo() {
        final PackageManager pm = context.getPackageManager();
        if (pm == null) {
            return null; 
7
CodeRank
This code example shows how to use the following methods:checkPermission
        return hasUploadingPermission() && mUrl != null && !IS_INHIBITING_AUTO_UPLOAD;
    } 
 
    private boolean hasUploadingPermission() { 
        final PackageManager packageManager = mContext.getPackageManager();
        return packageManager.checkPermission(Manifest.permission.INTERNET,
                mContext.getPackageName()) == PackageManager.PERMISSION_GRANTED;
    } 
 
    public boolean isConvenientToUpload() { 
        return isExternallyPowered() && hasWifiConnection(); 
    } 
 
    private boolean isExternallyPowered() { 
        final Intent intent = mContext.registerReceiver(null, new IntentFilter(
                Intent.ACTION_BATTERY_CHANGED));
        final int pluggedState = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
        return pluggedState == BatteryManager.BATTERY_PLUGGED_AC
                || pluggedState == BatteryManager.BATTERY_PLUGGED_USB;
    } 
5
CodeRank
This code example shows how to use the following methods:checkPermission
	} 
	 
	public static boolean checkPermission(Context context, String paramString)
	{ 
		PackageManager localPackageManager = context.getPackageManager();
		return localPackageManager.checkPermission(paramString, context.getPackageName()) == 0;
	} 
 
	public static String getImsi(Context context)
	{ 
		TelephonyManager tm = (TelephonyManager)context.getSystemService("phone");
		StringBuffer ImsiStr = new StringBuffer();
		try 
		{ 
			if (checkPermission(context, "android.permission.READ_PHONE_STATE")) {
				ImsiStr.append(tm.getSubscriberId() == null ? "" : tm.getSubscriberId());
			} 
			while (ImsiStr.length() < 15)
				ImsiStr.append("0");
		} 
5
CodeRank
This code example shows how to use the following methods:checkPermission
    public AndroidHardwareInfo(Context context) {
        m_telMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        // check if we can access the phone state 
        final String pkgName = context.getPackageName();
        final PackageManager pm = context.getPackageManager();
        m_allowToReadPhoneState = pm.checkPermission(Manifest.permission.READ_PHONE_STATE, pkgName) == PackageManager.PERMISSION_GRANTED;
    } 
     
     
    public String getIMEI() {
        if(m_allowToReadPhoneState &&
            (m_telMgr.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM)) {
             
            return checkValidString(m_telMgr.getDeviceId());
        } 
        return null; 
    } 
     
     
    public String getIMSI() {
3
CodeRank
This code example shows how to use the following methods:checkPermission
		mContext = context;
 
		PackageManager pm = mContext.getPackageManager();
		String packageName = mContext.getPackageName();
 
		if (pm.checkPermission(PERMISSION, packageName) == GRANTED) {
			mEnabled = true;
		} else { 
			Log.w(packageName + "/PlayerHater",
					"You need to request wake lock permission to enable wake locking during playback."); 
			mEnabled = false;
		} 
	} 
 
	@Override 
	public MediaPlayer swapPlayer(MediaPlayer mediaPlayer, int state) {
		MediaPlayer mp = super.swapPlayer(mediaPlayer, state);
		if (mEnabled) {
			mediaPlayer.setWakeMode(mContext, WAKE_LOCK);
		} 
5
CodeRank
This code example shows how to use the following methods:checkPermission
                Context.TELEPHONY_SERVICE);
         
        String pkgName = m_context.getPackageName();
        PackageManager pm = m_context.getPackageManager();
         
        if (pm.checkPermission(
                Manifest.permission.ACCESS_COARSE_LOCATION, pkgName) == PackageManager.PERMISSION_GRANTED) {
            m_cellIdAllowed = true;
        } 
    } 
 
 
 
    /* (non-Javadoc) 
     * @see com.wayfinder.pal.network.info.TGPPInfo#getCurrentMCC() 
     */ 
    public String getCurrentMCC() throws NetworkException {
        // first 3 is MCC 
    	String net = m_telMgr.getNetworkOperator();
    	if (net.length() > 4) {
5
CodeRank
This code example shows how to use the following methods:checkPermission
This code example shows how to use the following methods:checkPermission
This code example shows how to use the following methods:checkPermission
        return wrapped.getInstalledPackages(flags);
    } 
 
    @Override 
    public int checkPermission(String permName, String pkgName) {
        return wrapped.checkPermission(permName, pkgName);
    } 
 
    @Override 
    public boolean addPermission(PermissionInfo info) {
        return wrapped.addPermission(info);
    } 
 
    @Override 
    public boolean addPermissionAsync(PermissionInfo info) {
        return wrapped.addPermissionAsync(info);
    } 
 
    @Override 
    public void removePermission(String name) {
4
CodeRank

Related PackageManager checkPermission Questions & Answers:

checkPermission Method Overview
Check whether a particular package has been granted a particular permission.
See Code Examples for other Android PackageManager Methods: