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


Java DocumentsContract.deleteDocument方法代码示例

本文整理汇总了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;
}
 
开发者ID:ciubex,项目名称:dscautorename,代码行数:33,代码来源:FileRenameThread.java

示例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);
}
 
开发者ID:SecrecySupportTeam,项目名称:secrecy,代码行数:19,代码来源:DeleteFileJob.java

示例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;
    }
}
 
开发者ID:gigabytedevelopers,项目名称:FireFiles,代码行数:9,代码来源:DocumentsContractApi19.java

示例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;
}
 
开发者ID:mkulesh,项目名称:microMathematics,代码行数:12,代码来源:AdapterDocuments.java

示例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;
	}
}
 
开发者ID:saki4510t,项目名称:libcommon,代码行数:17,代码来源:SDUtils.java

示例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
    }
}
 
开发者ID:rcketscientist,项目名称:DocumentActivity,代码行数:8,代码来源:DocumentsContractApi19.java

示例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;
    }
}
 
开发者ID:seven332,项目名称:UniFile,代码行数:10,代码来源:DocumentsContractApi19.java

示例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);
}
 
开发者ID:SecrecySupportTeam,项目名称:Secrecy_fDroid_DEPRECIATED,代码行数:16,代码来源:DeleteFileJob.java

示例9: delete

import android.provider.DocumentsContract; //导入方法依赖的package包/类
public static boolean delete(Context context, Uri self) {
    return DocumentsContract.deleteDocument(context.getContentResolver(), self);
}
 
开发者ID:commonsguy,项目名称:cwac-document,代码行数:4,代码来源:DocumentsContractApi19.java

示例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;
}
 
开发者ID:ciubex,项目名称:dscautorename,代码行数:59,代码来源:FileRenameThread.java

示例11: delete

import android.provider.DocumentsContract; //导入方法依赖的package包/类
public static boolean delete(Context context, Uri uri)
{
    return DocumentsContract.deleteDocument(context.getContentResolver(), uri);
}
 
开发者ID:Hamz-a,项目名称:MyCTFWriteUps,代码行数:5,代码来源:DocumentsContractApi19.java


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