本文整理汇总了Java中android.provider.DocumentsContract.deleteDocument方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentsContract.deleteDocument方法的具体用法?Java DocumentsContract.deleteDocument怎么用?Java DocumentsContract.deleteDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.provider.DocumentsContract
的用法示例。
在下文中一共展示了DocumentsContract.deleteDocument方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doMoveFilesAPI21
import android.provider.DocumentsContract; //导入方法依赖的package包/类
/**
* Move a file using the new API 21 methods.
*
* @param data File rename data info.
* @param oldFile Old file reference.
* @param newFile New file reference.
* @return True if the file was moved.
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private boolean doMoveFilesAPI21(Uri oldUri, FileRenameData data, File oldFile, File newFile) throws FileNotFoundException {
File newParent = newFile.getParentFile();
Uri newParentUri = mApplication.getDocumentUri(mSelectedFolders, newParent.getAbsolutePath());
Uri newUri = DocumentsContract.createDocument(mContentResolver, newParentUri,
data.getMimeType(), newFile.getName());
boolean result = false;
long size = 0;
try {
if (oldUri != null && newUri != null) {
size = copyFileWithStreams(oldUri, newUri);
}
result = (size > 0);
} catch (Exception e) {
mApplication.logE(TAG, "doMoveFilesNewAPI " + oldFile + " to " + newFile, e);
}
if (result) {
result = DocumentsContract.deleteDocument(mContentResolver, oldUri);
if (result && newFile.exists()) {
newFile.setLastModified(data.getDateAdded());
}
}
return result;
}
示例2: onRun
import android.provider.DocumentsContract; //导入方法依赖的package包/类
@Override
public void onRun() throws Throwable {
os = new FileOutputStream(file);
if (file != null)
size = file.length();
Util.log("Delete ", file);
file.delete();
FileUtils.forceDelete(file);
if (uri != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
DocumentsContract.deleteDocument(context.getContentResolver(), uri); //For kitkat users
context.getContentResolver().delete(uri, null, null); //Try to delete under content resolver
}
new SingleMediaScanner(context, file); //Rescan and remove from gallery
Storage.shredFile(os, size, file);
file.delete();
FileUtils.forceDelete(file);
}
示例3: delete
import android.provider.DocumentsContract; //导入方法依赖的package包/类
public static boolean delete(Context context, Uri self) {
try {
return DocumentsContract.deleteDocument(context.getContentResolver(), self);
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
}
}
示例4: deleteFiles
import android.provider.DocumentsContract; //导入方法依赖的package包/类
private final int deleteFiles(Uri dir_uri, Item[] l) throws Exception
{
int cnt = 0;
for (int i = 0; i < l.length; i++)
{
Item item = l[i];
DocumentsContract.deleteDocument(a.ctx.getContentResolver(), (Uri) item.origin);
cnt++;
}
return cnt;
}
示例5: requestDeleteDocument
import android.provider.DocumentsContract; //导入方法依赖的package包/类
/**
* ファイル削除要求
* KITKAT以降で個別のファイル毎にパーミッション要求する場合
* @param context
* @param uri
* @return
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
public static boolean requestDeleteDocument(@NonNull final Context context, final Uri uri) {
try {
return BuildCheck.isKitKat()
&& DocumentsContract.deleteDocument(context.getContentResolver(), uri);
} catch (final FileNotFoundException e) {
return false;
}
}
示例6: delete
import android.provider.DocumentsContract; //导入方法依赖的package包/类
public static boolean delete(Context context, Uri self) {
try {
return DocumentsContract.deleteDocument(context.getContentResolver(), self);
} catch (FileNotFoundException e) {
return true; // It's gone after all
}
}
示例7: delete
import android.provider.DocumentsContract; //导入方法依赖的package包/类
public static boolean delete(Context context, Uri self) {
try {
return DocumentsContract.deleteDocument(context.getContentResolver(), self);
} catch (Exception e) {
// Maybe user ejects tf card
Log.e(TAG, "Failed to renameTo", e);
return false;
}
}
示例8: onRun
import android.provider.DocumentsContract; //导入方法依赖的package包/类
@Override
public void onRun() throws Throwable {
os = new FileOutputStream(file);
if (file != null)
size = file.length();
Util.log("Delete ", file);
FileUtils.forceDelete(file);
if (uri != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
DocumentsContract.deleteDocument(context.getContentResolver(), uri); //For kitkat users
context.getContentResolver().delete(uri, null, null); //Try to delete under content resolver
}
new SingleMediaScanner(context, file); //Rescan and remove from gallery
storage.shredFile(os, size);
}
示例9: delete
import android.provider.DocumentsContract; //导入方法依赖的package包/类
public static boolean delete(Context context, Uri self) {
return DocumentsContract.deleteDocument(context.getContentResolver(), self);
}
示例10: copyFileWithStreams
import android.provider.DocumentsContract; //导入方法依赖的package包/类
/**
* Method used to copy a file from a source to a destination.
*
* @param source The source file URI.
* @param destination The destination file URI.
* @return The copy size.
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
private long copyFileWithStreams(Uri source, Uri destination) throws FileNotFoundException {
ParcelFileDescriptor sourceFileDesc = null;
ParcelFileDescriptor destFileDesc = null;
FileChannel inChannel = null;
FileChannel outChannel = null;
long size = 0;
long expectedSize;
boolean copyError = false;
try {
sourceFileDesc = mContentResolver.openFileDescriptor(source, "r", null);
destFileDesc = mContentResolver.openFileDescriptor(destination, "w", null);
if (sourceFileDesc != null && destFileDesc != null) {
FileInputStream fis = new FileInputStream(sourceFileDesc.getFileDescriptor());
FileOutputStream fos = new FileOutputStream(destFileDesc.getFileDescriptor());
inChannel = fis.getChannel();
outChannel = fos.getChannel();
expectedSize = inChannel.size();
size = outChannel.transferFrom(inChannel, 0, expectedSize);
if (size != expectedSize) {
copyError = true;
mApplication.logE(TAG, "Copy error, different size, expected: " + expectedSize
+ " but copied: " + size + " from: " + source.toString()
+ " to " + destination.toString());
size = 0;
}
}
} catch (IOException e) {
copyError = true;
size = 0;
if (destFileDesc != null) {
try {
destFileDesc.closeWithError(e.getMessage());
} catch (IOException e1) {
mApplication.logE(TAG, "Error closing destination: " + destination.toString(),
e1);
}
}
mApplication.logE(TAG, "copyFileWithStreams " + source.toString()
+ " to " + destination.toString(), e);
} finally {
Utilities.doClose(sourceFileDesc);
Utilities.doClose(destFileDesc);
Utilities.doClose(inChannel);
Utilities.doClose(outChannel);
}
if (copyError) { // delete wrong destination file
DocumentsContract.deleteDocument(mContentResolver, destination);
}
return size;
}
示例11: delete
import android.provider.DocumentsContract; //导入方法依赖的package包/类
public static boolean delete(Context context, Uri uri)
{
return DocumentsContract.deleteDocument(context.getContentResolver(), uri);
}