本文整理汇总了Java中android.provider.DocumentsContract.getTreeDocumentId方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentsContract.getTreeDocumentId方法的具体用法?Java DocumentsContract.getTreeDocumentId怎么用?Java DocumentsContract.getTreeDocumentId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.provider.DocumentsContract
的用法示例。
在下文中一共展示了DocumentsContract.getTreeDocumentId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkPersistUriPermissionsAndUpdate
import android.provider.DocumentsContract; //导入方法依赖的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;
}
示例2: onActivityResult
import android.provider.DocumentsContract; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
protected void onActivityResult(final int requestCode, int resultCode, final Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode)
{
// Grab the selected permission so we can generate valid test files paths
case REQUEST_CODE_WRITE_PERMISSION:
if (resultCode == RESULT_OK && data != null)
{
Snackbar.make(findViewById(android.R.id.content), data.getDataString(), Snackbar.LENGTH_SHORT).show();
String root = DocumentsContract.getTreeDocumentId(data.getData());
test1Uri = DocumentsContract.buildDocumentUriUsingTree(data.getData(), root + documentId1);
test2Uri = DocumentsContract.buildDocumentUriUsingTree(data.getData(), root + documentId2);
}
break;
}
}
示例3: getDocumentId
import android.provider.DocumentsContract; //导入方法依赖的package包/类
public String getDocumentId()
{
try
{
if (DocumentsContract.isDocumentUri(mContext, mUri))
{
return DocumentsContract.getDocumentId(mUri);
} else
{
return DocumentsContract.getTreeDocumentId(mUri);
}
}
catch (IllegalArgumentException e)
{
// This is not a document uri, for now I'll try to handle this gracefully.
// While it may be convenient for a user to be able to use this object for all uri,
// it may be difficult to manage all aspects gracefully.
return null;
}
}
示例4: prepareTreeUri
import android.provider.DocumentsContract; //导入方法依赖的package包/类
public static Uri prepareTreeUri(Uri treeUri) {
String documentId;
try {
documentId = DocumentsContract.getDocumentId(treeUri);
if (documentId == null) {
throw new IllegalArgumentException();
}
} catch (Exception e) {
// IllegalArgumentException will be raised
// if DocumentsContract.getDocumentId() failed.
// But it isn't mentioned the document,
// catch all kinds of Exception for safety.
documentId = DocumentsContract.getTreeDocumentId(treeUri);
}
return DocumentsContract.buildDocumentUriUsingTree(treeUri, documentId);
}
示例5: isTreeUri
import android.provider.DocumentsContract; //导入方法依赖的package包/类
private boolean isTreeUri(Uri possibleTreeUri) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return DocumentsContract.isTreeUri(possibleTreeUri);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Prior to N we can't directly check if the URI is a tree URI, so we have to just try it
try {
String treeDocumentId = DocumentsContract.getTreeDocumentId(possibleTreeUri);
return !TextUtils.isEmpty(treeDocumentId);
} catch (IllegalArgumentException e) {
// Definitely not a tree URI
return false;
}
}
// No tree URIs prior to Lollipop
return false;
}
示例6: getAbsolutePathFromFolderPickerResultUri
import android.provider.DocumentsContract; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private String getAbsolutePathFromFolderPickerResultUri(Uri resultUri) {
if ("com.android.externalstorage.documents".equals(resultUri.getAuthority())) {
final String documentId = DocumentsContract.getTreeDocumentId(resultUri);
final String[] idParts = documentId.split(":"); // e.g. "primary:Podcasts"
// Default: internal storage
String rootPath = Environment.getExternalStorageDirectory().getAbsolutePath();
// If not on internal storage -> SD card
if (!"primary".equals(idParts[0]))
// Make sure there is only one storage besides the internal one (i.e. the SD card),
// other setups are just too complicated and rare for us to care about
if (getExternalMediaDirs().length == 2)
// Set root path to absolute path for SD card
rootPath = getExternalMediaDirs()[1].getAbsolutePath().split("/Android")[0];
else throw new IllegalArgumentException("Unknown storage setup");
return rootPath + File.separator + idParts[1];
} else
throw new IllegalArgumentException("Not a real local folder");
}
示例7: getVolumeIdFromTreeUri
import android.provider.DocumentsContract; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static String getVolumeIdFromTreeUri(final Uri treeUri) {
final String docId = DocumentsContract.getTreeDocumentId(treeUri);
final String[] split = docId.split(":");
if (split.length > 0) {
return split[0];
}
else {
return null;
}
}
示例8: getDocumentPathFromTreeUri
import android.provider.DocumentsContract; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static String getDocumentPathFromTreeUri(final Uri treeUri) {
final String docId = DocumentsContract.getTreeDocumentId(treeUri);
final String[] split = docId.split(":");
if ((split.length >= 2) && (split[1] != null)) {
return split[1];
}
else {
return File.separator;
}
}
示例9: getPermissibleRoot
import android.provider.DocumentsContract; //导入方法依赖的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: getVolumeIdFromTreeUri
import android.provider.DocumentsContract; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static String getVolumeIdFromTreeUri(final Uri treeUri) {
final String docId = DocumentsContract.getTreeDocumentId(treeUri);
final String[] split = docId.split(":");
if (split.length > 0) {
return split[0];
} else {
return null;
}
}
示例11: getDocumentPathFromTreeUri
import android.provider.DocumentsContract; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static String getDocumentPathFromTreeUri(final Uri treeUri) {
final String docId = DocumentsContract.getTreeDocumentId(treeUri);
final String[] split = docId.split(":");
if ((split.length >= 2) && (split[1] != null)) {
return split[1];
} else {
return File.separator;
}
}
示例12: getVolumeIdFromTreeUri
import android.provider.DocumentsContract; //导入方法依赖的package包/类
private static String getVolumeIdFromTreeUri(final Uri treeUri) {
final String docId = DocumentsContract.getTreeDocumentId(treeUri);
final String[] split = docId.split(":");
if (split.length > 0) {
return split[0];
}
else {
return null;
}
}
示例13: getDocumentPathFromTreeUri
import android.provider.DocumentsContract; //导入方法依赖的package包/类
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
private static String getDocumentPathFromTreeUri(final Uri treeUri) {
final String docId = DocumentsContract.getTreeDocumentId(treeUri);
final String[] split = docId.split(":");
if ((split.length >= 2) && (split[1] != null)) {
return split[1];
} else {
return File.separator;
}
}
示例14: getVolumeIdFromTreeUri
import android.provider.DocumentsContract; //导入方法依赖的package包/类
/**
* Get the volume ID from the tree URI.
*
* @param treeUri The tree URI.
* @return The volume ID.
*/
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
private static String getVolumeIdFromTreeUri(final Uri treeUri) {
final String docId = DocumentsContract.getTreeDocumentId(treeUri);
final String[] split = docId.split(":");
if (split.length > 0) {
return split[0];
}
else {
return null;
}
}
示例15: getDocumentPathFromTreeUri
import android.provider.DocumentsContract; //导入方法依赖的package包/类
/**
* Get the document path (relative to volume name) for a tree URI (LOLLIPOP).
*
* @param treeUri The tree URI.
* @return the document path.
*/
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
private static String getDocumentPathFromTreeUri(final Uri treeUri) {
final String docId = DocumentsContract.getTreeDocumentId(treeUri);
final String[] split = docId.split(":");
if ((split.length >= 2) && (split[1] != null)) {
return split[1];
}
else {
return File.separator;
}
}