当前位置: 首页>>代码示例>>Java>>正文


Java UriPermission类代码示例

本文整理汇总了Java中android.content.UriPermission的典型用法代码示例。如果您正苦于以下问题:Java UriPermission类的具体用法?Java UriPermission怎么用?Java UriPermission使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


UriPermission类属于android.content包,在下文中一共展示了UriPermission类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRootUri

import android.content.UriPermission; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.KITKAT)
private Uri getRootUri(String docId){
    Uri treeUri;
    final int splitIndex = docId.indexOf(':', 1);
    final String tag = docId.substring(0, splitIndex);

    //check in cache
    treeUri = secondaryRoots.get(tag);
    if(null != treeUri){
        return treeUri;
    }

    //get root dynamically
    List<UriPermission> permissions = mContext.getContentResolver().getPersistedUriPermissions();
    for (UriPermission permission :
            permissions) {
        String treeRootId = getRootUri(permission.getUri());
        if(docId.startsWith(treeRootId)){
            treeUri = permission.getUri();
            secondaryRoots.put(tag, treeUri);
            return treeUri;
        }
    }
    return treeUri;
}
 
开发者ID:kranthi0987,项目名称:easyfilemanager,代码行数:26,代码来源:SAFManager.java

示例2: checkPersistUriPermissionsAndUpdate

import android.content.UriPermission; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static boolean checkPersistUriPermissionsAndUpdate(Context context, DocumentFolder documentFolder)
{
    Uri uri = documentFolder.getFolder().getUri();
    List<UriPermission> permissions = context.getContentResolver().getPersistedUriPermissions();
    for (UriPermission permission : permissions)
    {
        String permissionTreeId = DocumentsContract.getTreeDocumentId(permission.getUri());
        String uriTreeId = DocumentsContract.getTreeDocumentId(uri);
        if (uriTreeId.startsWith(permissionTreeId))
        {
            // update permissions - after a restart this is necessary...
            updatePersistUriPermissions(context, uri);
            documentFolder.updateDocument(DocumentFile.fromTreeUri(context, permission.getUri()));
            return true;
        }
    }
    return false;
}
 
开发者ID:MFlisar,项目名称:StorageManager,代码行数:20,代码来源:StoragePermissionManager.java

示例3: hasStorageAccess

import android.content.UriPermission; //导入依赖的package包/类
/**
 * request_codeに対応するUriへアクセス可能かどうか
 * @param context
 * @param request_code
 * @return
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
public static boolean hasStorageAccess(@NonNull final Context context,
	final int request_code) {

	boolean found = false;
	if (BuildCheck.isLollipop()) {
		final Uri uri = loadUri(context, getKey(request_code));
		if (uri != null) {
			// 恒常的に保持しているUriパーミッションの一覧を取得する
			final List<UriPermission> list
				= context.getContentResolver().getPersistedUriPermissions();
			for (final UriPermission item: list) {
				if (item.getUri().equals(uri)) {
					// request_codeに対応するUriへのパーミッションを恒常的に保持していた時
					found = true;
					break;
				}
			}
		}
	}
	return found;
}
 
开发者ID:saki4510t,项目名称:libcommon,代码行数:29,代码来源:SDUtils.java

示例4: revokePermission

import android.content.UriPermission; //导入依赖的package包/类
protected void revokePermission()
{
	// TODO: This does not stop writing once permission was granted...needs more testing might be an android bug
	for (UriPermission p : getContentResolver().getPersistedUriPermissions())
	{
		getContentResolver().releasePersistableUriPermission(p.getUri(),
				Intent.FLAG_GRANT_READ_URI_PERMISSION |
				Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
	}
	if (getContentResolver().getPersistedUriPermissions().size() == 0)
	{
		Snackbar.make(findViewById(android.R.id.content), R.string.revokeSuccess, Snackbar.LENGTH_SHORT).show();
	}
	else
	{
		Snackbar.make(findViewById(android.R.id.content), R.string.revokeFail, Snackbar.LENGTH_SHORT).show();
	}
}
 
开发者ID:rcketscientist,项目名称:DocumentActivity,代码行数:19,代码来源:BaseActivity.java

示例5: getDocumentTree

import android.content.UriPermission; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static String getDocumentTree() {
    String treeUri = PreferenceUtil.getInstance(RetroApplication.getInstance()).getDocumentTreeUri();
    List<UriPermission> perms = RetroApplication.getInstance().getContentResolver().getPersistedUriPermissions();
    for (UriPermission perm : perms) {
        if (perm.getUri().toString().equals(treeUri) && perm.isWritePermission())
            return treeUri;
    }
    return null;
}
 
开发者ID:h4h13,项目名称:RetroMusicPlayer,代码行数:11,代码来源:TaggerUtils.java

示例6: isSDCardAccessGranted

import android.content.UriPermission; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static boolean isSDCardAccessGranted(Context context) {
    if (!isTreeUriSaved(context)) return false;

    String sdcardUri = PreferenceUtil.getInstance(context).getSAFSDCardUri();

    List<UriPermission> perms = context.getContentResolver().getPersistedUriPermissions();
    for (UriPermission perm : perms) {
        if (perm.getUri().toString().equals(sdcardUri) && perm.isWritePermission()) return true;
    }

    return false;
}
 
开发者ID:h4h13,项目名称:RetroMusicPlayer,代码行数:14,代码来源:SAFUtil.java

示例7: getStorageUri

import android.content.UriPermission; //导入依赖的package包/类
/**
 * request_codeに対応するUriが存在していて恒常的パーミッションがあればそれを返す, なければnullを返す
 * @param context
 * @param request_code
 * @return
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Nullable
public static Uri getStorageUri(@NonNull final Context context,
	final int request_code) {

	if (BuildCheck.isLollipop()) {
		final Uri uri = loadUri(context, getKey(request_code));
		if (uri != null) {
			boolean found = false;
			// 恒常的に保持しているUriパーミッションの一覧を取得する
			final List<UriPermission> list
				= context.getContentResolver().getPersistedUriPermissions();
			for (final UriPermission item: list) {
				if (item.getUri().equals(uri)) {
					// request_codeに対応するUriへのパーミッションを恒常的に保持していた時
					found = true;
					break;
				}
			}
			if (found) {
				return uri;
			}
		}
	}
	return null;
}
 
开发者ID:saki4510t,项目名称:libcommon,代码行数:33,代码来源:SDUtils.java

示例8: releaseGarbagePermissions

import android.content.UriPermission; //导入依赖的package包/类
/**
 * Releases all persisted URI permissions that are no longer referenced
 */
void releaseGarbagePermissions() {
    ContentResolver contentResolver = context.getContentResolver();
    for (UriPermission permission : contentResolver.getPersistedUriPermissions()) {
        if (isGarbage(permission.getUri())) {
            Log.i(TAG, "releaseGarbagePermissions: Releasing permission for " + permission.getUri());
            contentResolver.releasePersistableUriPermission(permission.getUri(), Intent.FLAG_GRANT_READ_URI_PERMISSION);
        } else {
            Log.v(TAG, "releaseGarbagePermissions: Keeping permission for " + permission.getUri());
        }
    }
}
 
开发者ID:julian-klode,项目名称:dns66,代码行数:15,代码来源:RuleDatabaseUpdateTask.java

示例9: getPermissibleRoot

import android.content.UriPermission; //导入依赖的package包/类
/**
 * Returns the permissible root uri if one exists, null if not.
 *
 * @return The tree URI.
 */
public Uri getPermissibleRoot(Uri uri)
{
	if (uri == null)
		return null;

	// Files can't be correlated to UriPermissions so rely on canWrite?
	if (FileUtil.isFileScheme(uri))
	{
		File f = new File(uri.getPath());

		while (f != null && !f.canWrite())
		{
			if (f.canWrite())
				return Uri.fromFile(f);
			f = f.getParentFile();
		}
		return null;
	}
	else
	{
		for (UriPermission permission : mRootPermissions)
		{
			String permissionTreeId = DocumentsContract.getTreeDocumentId(permission.getUri());
			String uriTreeId = DocumentsContract.getTreeDocumentId(uri);

			if (uriTreeId.startsWith(permissionTreeId))
			{
				return permission.getUri();
			}
		}
	}

	return null;
}
 
开发者ID:rcketscientist,项目名称:DocumentActivity,代码行数:40,代码来源:DocumentActivity.java

示例10: findGrantedUri

import android.content.UriPermission; //导入依赖的package包/类
private Uri findGrantedUri(final String mountPoint) {
    final List<UriPermission> list = mContext.getContentResolver().getPersistedUriPermissions();
    final Iterator<UriPermission> iterator = list.iterator();
    while (iterator.hasNext()) {
        final Uri uri = checkPermission(iterator.next(), mountPoint);
        if (uri == null) {
            continue;
        }
        return uri;
    }
    return null;
}
 
开发者ID:DeFuture,项目名称:AmazeFileManager-master,代码行数:13,代码来源:ExternalStoragePermissionGrant.java

示例11: revokePermission

import android.content.UriPermission; //导入依赖的package包/类
@RequiresApi(api = KITKAT)
private void revokePermission() {
    for (UriPermission p : getContentResolver().getPersistedUriPermissions()) {
        getContentResolver().releasePersistableUriPermission(p.getUri(),
                Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    }
    if (getContentResolver().getPersistedUriPermissions().size() == 0) {
        LogHelper.d(TAG, "Permissions revoked successfully.");
    } else {
        LogHelper.d(TAG, "Permissions failed to be revoked.");
    }
}
 
开发者ID:avluis,项目名称:Hentoid,代码行数:13,代码来源:ImportActivity.java

示例12: deleteBackingPhotos

import android.content.UriPermission; //导入依赖的package包/类
/**
 * We can't just simply delete the rows as that won't free up the space occupied by the
 * chosen image files for each row being deleted. Instead we have to query
 * and manually delete each chosen image file
 */
private void deleteBackingPhotos(Context context, List<ChosenPhoto> chosenPhotos) {
    for (ChosenPhoto chosenPhoto : chosenPhotos) {
        File file = GalleryProvider.getCacheFileForUri(context, chosenPhoto.uri);
        if (file != null && file.exists()) {
            if (!file.delete()) {
                Log.w(TAG, "Unable to delete " + file);
            }
        } else {
            Uri uriToRelease = chosenPhoto.uri;
            ContentResolver contentResolver = context.getContentResolver();
            boolean haveUriPermission = context.checkUriPermission(uriToRelease,
                    Binder.getCallingPid(), Binder.getCallingUid(),
                    Intent.FLAG_GRANT_READ_URI_PERMISSION) == PackageManager.PERMISSION_GRANTED;
            if (haveUriPermission) {
                // Try to release any persisted URI permission for the imageUri
                List<UriPermission> persistedUriPermissions = contentResolver.getPersistedUriPermissions();
                for (UriPermission persistedUriPermission : persistedUriPermissions) {
                    if (persistedUriPermission.getUri().equals(uriToRelease)) {
                        contentResolver.releasePersistableUriPermission(
                                uriToRelease, Intent.FLAG_GRANT_READ_URI_PERMISSION);
                        break;
                    }
                }
            } else {
                // On API 25 and lower, we don't get URI permissions to URIs
                // from our own package so we manage those URI permissions manually
                try {
                    contentResolver.call(uriToRelease, "releasePersistableUriPermission",
                            uriToRelease.toString(), null);
                } catch (Exception e) {
                    Log.w(TAG, "Unable to manually release uri permissions to " + chosenPhoto.uri, e);
                }
            }
        }
    }
}
 
开发者ID:romannurik,项目名称:muzei,代码行数:42,代码来源:ChosenPhotoDao.java

示例13: getPersistedUriPermissions

import android.content.UriPermission; //导入依赖的package包/类
@Override @RequiresApi(KITKAT) @NonNull public List<UriPermission> getPersistedUriPermissions() {
	return mBase.getPersistedUriPermissions();
}
 
开发者ID:Trumeet,项目名称:MiPushFramework,代码行数:4,代码来源:ContentResolverWrapper.java

示例14: getOutgoingPersistedUriPermissions

import android.content.UriPermission; //导入依赖的package包/类
@Override @RequiresApi(KITKAT) @NonNull public List<UriPermission> getOutgoingPersistedUriPermissions() {
	return mBase.getOutgoingPersistedUriPermissions();
}
 
开发者ID:Trumeet,项目名称:MiPushFramework,代码行数:4,代码来源:ContentResolverWrapper.java

示例15: hasPermission

import android.content.UriPermission; //导入依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public static boolean hasPermission() {
    List<UriPermission> uriPermission = Common.getInstance().getContentResolver().getPersistedUriPermissions();
    return uriPermission != null && uriPermission.size() > 0;
}
 
开发者ID:reyanshmishra,项目名称:Rey-MusicPlayer,代码行数:6,代码来源:MusicUtils.java


注:本文中的android.content.UriPermission类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。