Code example for Context

Methods: enforceCallingOrSelfPermission

0
        } 
        return false; 
    } 
 
    public void setSyncAutomatically(Account account, String providerName, boolean sync) {
        mContext.enforceCallingOrSelfPermission(Manifest.permission.WRITE_SYNC_SETTINGS,
                "no permission to write the sync settings"); 
        int userId = UserHandle.getCallingUserId();
 
        long identityToken = clearCallingIdentity();
        try { 
            SyncManager syncManager = getSyncManager();
            if (syncManager != null) {
                syncManager.getSyncStorageEngine().setSyncAutomatically(
                        account, userId, providerName, sync);
            } 
        } finally { 
            restoreCallingIdentity(identityToken);
        } 
    }