private void onFinished(Uri... uris) { final Intent intent = new Intent(); if (uris.length == 1) { intent.setData(uris[0]); } else if (uris.length > 1) { final ClipData clipData = new ClipData(null, mState.acceptMimes, new ClipData.Item(uris[0])); for (int i = 1; i < uris.length; i++) { clipData.addItem(new ClipData.Item(uris[i])); } intent.setClipData(clipData); } if (mState.action == ACTION_GET_CONTENT) { intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else if (mState.action == ACTION_OPEN_TREE) { intent.addFlags( Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION | Intent.FLAG_GRANT_PREFIX_URI_PERMISSION); } else { intent.addFlags( Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION); } setResult(Activity.RESULT_OK, intent); finish(); Log.d(TAG, "onFinished: uri=" + Arrays.toString(uris) + ", data=" + intent); }
/** * Populate an intent object with the results gathered from remote input. This method should only * be called by remote input collection services when sending results to a pending intent. * * @param remoteInputs The remote inputs for which results are being provided * @param intent The intent to add remote inputs to. The {@link ClipData} field of the intent will * be modified to contain the results. * @param results A bundle holding the remote input results. This bundle should be populated with * keys matching the result keys specified in {@code remoteInputs} with values being the * result per key. */ public static void addResultsToIntent(RemoteInput[] remoteInputs, Intent intent, Bundle results) { Bundle resultsBundle = new Bundle(); for (RemoteInput remoteInput : remoteInputs) { Object result = results.get(remoteInput.getResultKey()); if (result instanceof CharSequence) { resultsBundle.putCharSequence(remoteInput.getResultKey(), (CharSequence) result); } } Intent clipIntent = new Intent(); clipIntent.putExtra(EXTRA_RESULTS_DATA, resultsBundle); intent.setClipData(ClipData.newIntent(RESULTS_CLIP_LABEL, clipIntent)); }