Example usage for android.provider DocumentsContract deleteDocument

List of usage examples for android.provider DocumentsContract deleteDocument

Introduction

In this page you can find the example usage for android.provider DocumentsContract deleteDocument.

Prototype

public static void deleteDocument(ContentProviderClient client, Uri documentUri) throws RemoteException 

Source Link

Usage

From source file:de.j4velin.encrypter.PlaintextFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    RecyclerView recyclerView = (RecyclerView) inflater.inflate(R.layout.fragment_filelist, container, false);
    adapter = new FileAdapter(getContext(), new FileAdapter.ClickListener() {
        @Override//from ww w  .  jav  a  2  s . c om
        public void click(final File file) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(file.uri, file.mime);
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            startActivity(intent);
        }
    }, new FileAdapter.DeleteListener() {
        @Override
        public boolean delete(final File file) {
            boolean result = DocumentsContract.deleteDocument(getActivity().getContentResolver(), file.uri);
            if (!result) {
                java.io.File f = new java.io.File(file.uri.getPath());
                result = !f.exists() || f.delete();
            }
            if (!result) {
                Snackbar.make(((MainActivity) getActivity()).getCoordinatorLayout(),
                        getString(R.string.can_not_delete, file.name), Snackbar.LENGTH_LONG).show();
            }
            if (result && adapter.getSize() == 1) {
                // we're removing the last element -> hide the view
                ((MainActivity) getActivity()).showPlaintextLayout(false);
            }
            return result;
        }
    });
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    recyclerView.setAdapter(adapter);
    return recyclerView;
}

From source file:com.anthonymandra.support.v4.provider.DocumentsContractApi19.java

public static boolean delete(Context context, Uri self) {
    return DocumentsContract.deleteDocument(context.getContentResolver(), self);
}

From source file:com.uphyca.kitkat.storage.ui.MainFragment.java

/**
 * ??// w  w  w  .  j ava 2 s  . c o  m
 * 
 * @param resultCode
 * @param data
 */
void onDeleteRequestResult(int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK || data == null) {
        return;
    }

    new AsyncTask<Uri, Void, String>() {
        Context appContext = getActivity().getApplicationContext();

        @Override
        protected String doInBackground(Uri... params) {
            //FIXME ?????????
            DocumentsContract.deleteDocument(getActivity().getContentResolver(), params[0]);
            return "Delete...??????";
        }

        @Override
        protected void onPostExecute(String s) {
            Toast.makeText(appContext, s, Toast.LENGTH_SHORT).show();
        }
    }.execute(data.getData());
}