Context checkCallingOrSelfPermission - top ranked examples from Open Source projects

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

This code example shows how to use the following methods:checkCallingOrSelfPermission, getCacheDir
		File appCacheDir = null;
		if (MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) && hasExternalStoragePermission(context)) {
			appCacheDir = getExternalCacheDir(context);
		} 
		if (appCacheDir == null) {
			appCacheDir = context.getCacheDir();
		} 
		if (appCacheDir == null) {
			L.w("Can't define system cache directory! The app should be re-installed."); 
		} 
		return appCacheDir;
	} 
 
	/** 
	 * Returns individual application cache directory (for only image caching from ImageLoader). Cache directory will be 
	 * created on SD card <i>("/Android/data/[app_package_name]/cache/uil-images")</i> if card is mounted and app has 
	 * appropriate permission. Else - Android defines cache directory on device's file system. 
	 * 
	 * @param context Application context 
	 * @return Cache {@link File directory} 

7
CodeRank
This code example shows how to use the following methods:checkCallingOrSelfPermission
            return null; 
        } 
    } 
 
    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
                != PackageManager.PERMISSION_GRANTED) {
            pw.println("Permission Denial: can't dump PhoneSubInfo from from pid="
                    + Binder.getCallingPid()
                    + ", uid=" + Binder.getCallingUid());
            return; 
        } 
 
        pw.println("Phone Subscriber Info:");
        pw.println("  Phone Type = " + mPhone.getPhoneName());
        pw.println("  Device ID = " + mPhone.getDeviceId());
    } 
 
} 
7
CodeRank
This code example shows how to use the following methods:checkCallingOrSelfPermission, getCacheDir
		File appCacheDir = null;
		if (MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) && hasExternalStoragePermission(context)) {
			appCacheDir = getExternalCacheDir(context);
		} 
		if (appCacheDir == null) {
			appCacheDir = context.getCacheDir();
		} 
		if (appCacheDir == null) {
			L.w("Can't define system cache directory! The app should be re-installed."); 
		} 
		return appCacheDir;
	} 
 
	/** 
	 * Returns individual application cache directory (for only image caching 
	 * from ImageLoader). Cache directory will be created on SD card 
	 * <i>("/Android/data/[app_package_name]/cache/uil-images")</i> if card is 
	 * mounted and app has appropriate permission. Else - Android defines cache 
	 * directory on device's file system. 
	 *  

7
CodeRank
This code example shows how to use the following methods:checkCallingOrSelfPermission
                + " pid=" + Binder.getCallingPid() + '}';
    } 
 
    @Override 
    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
                != PackageManager.PERMISSION_GRANTED) {
            pw.println("Permission Denial: can't dump update lock service from from pid="
                    + Binder.getCallingPid()
                    + ", uid=" + Binder.getCallingUid());
            return; 
        } 
 
        mLocks.dump(pw);
    } 
} 
7
CodeRank
This code example shows how to use the following methods:checkCallingOrSelfPermission, getSharedPreferences
 
        if (width != mWidth || height != mHeight) {
            mWidth = width;
            mHeight = height;
 
            SharedPreferences preferences = mContext.getSharedPreferences(PREFERENCES,
                    Context.MODE_PRIVATE);
 
            final SharedPreferences.Editor editor = preferences.edit();
            editor.putInt(HINT_WIDTH, width);
            editor.putInt(HINT_HEIGHT, height);
            editor.commit();
        } 
    } 
 
    public int getWidthHint() throws RemoteException { 
        return mWidth;
    } 
 
    public int getHeightHint() throws RemoteException { 

6
CodeRank
This code example shows how to use the following methods:checkCallingOrSelfPermission
    public boolean getFlashlightEnabled() { 
        return Hardware.getFlashlightEnabled(); 
    } 
     
    public void setFlashlightEnabled(boolean on) {
        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.FLASHLIGHT) 
                != PackageManager.PERMISSION_GRANTED &&
                mContext.checkCallingOrSelfPermission(android.Manifest.permission.HARDWARE_TEST) 
                != PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException("Requires FLASHLIGHT or HARDWARE_TEST permission");
        } 
        Hardware.setFlashlightEnabled(on);
    } 
 
    public void enableCameraFlash(int milliseconds) {
        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.CAMERA) 
                != PackageManager.PERMISSION_GRANTED &&
                mContext.checkCallingOrSelfPermission(android.Manifest.permission.HARDWARE_TEST) 
                != PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException("Requires CAMERA or HARDWARE_TEST permission");
6
CodeRank
This code example shows how to use the following methods:checkCallingOrSelfPermission
                + " pid=" + Binder.getCallingPid() + '}';
    } 
 
    @Override 
    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
                != PackageManager.PERMISSION_GRANTED) {
            pw.println("Permission Denial: can't dump update lock service from from pid="
                    + Binder.getCallingPid()
                    + ", uid=" + Binder.getCallingUid());
            return; 
        } 
 
        mLocks.dump(pw);
    } 
} 
6
CodeRank
This code example shows how to use the following methods:checkCallingOrSelfPermission
        } 
    } 
 
    @Override 
    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
                != PackageManager.PERMISSION_GRANTED) {
            pw.println("Permission Denial: can't dump UsbManager from from pid="
                    + Binder.getCallingPid()
                    + ", uid=" + Binder.getCallingUid());
            return; 
        } 
 
        pw.println("USB Manager State:");
 
        if (mDeviceManager != null) {
            mDeviceManager.dump(fd, pw);
        } 
        if (mHostManager != null) {
            mHostManager.dump(fd, pw);
6
CodeRank
This code example shows how to use the following methods:checkCallingOrSelfPermission
            return null; 
        } 
    } 
 
    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
                != PackageManager.PERMISSION_GRANTED) {
            pw.println("Permission Denial: can't dump PhoneSubInfo from from pid="
                    + Binder.getCallingPid()
                    + ", uid=" + Binder.getCallingUid());
            return; 
        } 
 
        pw.println("Phone Subscriber Info:");
        pw.println("  Phone Type = " + mPhone.getPhoneName());
        pw.println("  Device ID = " + mPhone.getDeviceId());
    } 
 
} 
6
CodeRank
This code example shows how to use the following methods:checkCallingOrSelfPermission
        intent.putExtra(Phone.DATA_APN_TYPE_KEY, apnType);
        mContext.sendStickyBroadcast(intent);
    } 
 
    private boolean checkNotifyPermission(String method) {
        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
                == PackageManager.PERMISSION_GRANTED) {
            return true; 
        } 
        String msg = "Modify Phone State Permission Denial: " + method + " from pid="
                + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
        if (DBG) Slog.w(TAG, msg);
        return false; 
    } 
 
    private void checkListenerPermission(int events) {
        if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
            mContext.enforceCallingOrSelfPermission(
                    android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
 
5
CodeRank

Related Context checkCallingOrSelfPermission Questions & Answers:

checkCallingOrSelfPermission Method Overview
Determine whether the calling process of an IPC or you have been granted a particular permission.
See Code Examples for other Android Context Methods: