本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
}
}
示例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;
}
示例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;
}
示例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.");
}
}
示例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);
}
}
}
}
}
示例13: getPersistedUriPermissions
import android.content.UriPermission; //导入依赖的package包/类
@Override @RequiresApi(KITKAT) @NonNull public List<UriPermission> getPersistedUriPermissions() {
return mBase.getPersistedUriPermissions();
}
示例14: getOutgoingPersistedUriPermissions
import android.content.UriPermission; //导入依赖的package包/类
@Override @RequiresApi(KITKAT) @NonNull public List<UriPermission> getOutgoingPersistedUriPermissions() {
return mBase.getOutgoingPersistedUriPermissions();
}
示例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;
}