List of usage examples for android.content Intent getClipData
public @Nullable ClipData getClipData()
From source file:com.farmerbb.notepad.activity.MainActivity.java
@TargetApi(Build.VERSION_CODES.KITKAT) @Override//from w w w . j a v a 2 s . c om public void onActivityResult(int requestCode, int resultCode, Intent resultData) { if (resultCode == RESULT_OK && resultData != null) { successful = true; if (requestCode == IMPORT) { Uri uri = resultData.getData(); ClipData clipData = resultData.getClipData(); if (uri != null) successful = importNote(uri); else if (clipData != null) for (int i = 0; i < clipData.getItemCount(); i++) { successful = importNote(clipData.getItemAt(i).getUri()); } // Show toast notification showToast(successful ? (uri == null ? R.string.notes_imported_successfully : R.string.note_imported_successfully) : R.string.error_importing_notes); // Send broadcast to NoteListFragment to refresh list of notes Intent listNotesIntent = new Intent(); listNotesIntent.setAction("com.farmerbb.notepad.LIST_NOTES"); LocalBroadcastManager.getInstance(this).sendBroadcast(listNotesIntent); } else if (requestCode == EXPORT) { try { saveExportedNote(loadNote(filesToExport[fileBeingExported].toString()), resultData.getData()); } catch (IOException e) { successful = false; } fileBeingExported++; if (fileBeingExported < filesToExport.length) reallyExportNotes(); else showToast(successful ? (fileBeingExported == 1 ? R.string.note_exported_to : R.string.notes_exported_to) : R.string.error_exporting_notes); File fileToDelete = new File(getFilesDir() + File.separator + "exported_note"); fileToDelete.delete(); } else if (requestCode == EXPORT_TREE) { DocumentFile tree = DocumentFile.fromTreeUri(this, resultData.getData()); for (Object exportFilename : filesToExport) { try { DocumentFile file = tree.createFile("text/plain", generateFilename(loadNoteTitle(exportFilename.toString()))); if (file != null) saveExportedNote(loadNote(exportFilename.toString()), file.getUri()); else successful = false; } catch (IOException e) { successful = false; } } showToast(successful ? R.string.notes_exported_to : R.string.error_exporting_notes); } } }
From source file:com.Jsu.framework.image.imageChooser.ImageChooserManager.java
@SuppressLint("NewApi") private void processImageFromGallery(Intent data) { if (data != null && data.getDataString() != null) { String uri = data.getData().toString(); sanitizeURI(uri);/*from ww w . j av a 2 s . co m*/ if (filePathOriginal == null || TextUtils.isEmpty(filePathOriginal)) { onError("File path was null"); } else { if (BuildConfig.DEBUG) { Log.i(TAG, "File: " + filePathOriginal); } String path = filePathOriginal; ImageProcessorThread thread = new ImageProcessorThread(path, foldername, shouldCreateThumbnails); thread.clearOldFiles(clearOldFiles); thread.setListener(this); thread.setContext(getContext()); thread.start(); } } else if (data.getClipData() != null || data.hasExtra("uris")) { // Multiple Images String[] filePaths; if (data.hasExtra("uris")) { ArrayList<Uri> uris = data.getParcelableArrayListExtra("uris"); filePaths = new String[uris.size()]; for (int i = 0; i < uris.size(); i++) { filePaths[i] = uris.get(i).toString(); } } else { ClipData clipData = data.getClipData(); int count = clipData.getItemCount(); filePaths = new String[count]; for (int i = 0; i < count; i++) { ClipData.Item item = clipData.getItemAt(i); Log.i(TAG, "processImageFromGallery: Item: " + item.getUri()); filePaths[i] = item.getUri().toString(); } } ImageProcessorThread thread = new ImageProcessorThread(filePaths, foldername, shouldCreateThumbnails); thread.clearOldFiles(clearOldFiles); thread.setListener(this); thread.setContext(getContext()); thread.start(); // } else if () { } else { onError("Image Uri was null!"); } }
From source file:com.stfalcon.contentmanager.ContentManager.java
private void handleFileContent(final Intent intent) { List<String> uris = new ArrayList<>(); if (intent.getDataString() != null) { String uri = intent.getDataString(); uris.add(uri);/*from w w w.j av a 2s.c o m*/ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (intent.getClipData() != null) { ClipData clipData = intent.getClipData(); for (int i = 0; i < clipData.getItemCount(); i++) { ClipData.Item item = clipData.getItemAt(i); Log.d("TAG", "Item [" + i + "]: " + item.getUri().toString()); uris.add(item.getUri().toString()); } } } if (intent.hasExtra("uris")) { ArrayList<Uri> paths = intent.getParcelableArrayListExtra("uris"); for (int i = 0; i < paths.size(); i++) { uris.add(paths.get(i).toString()); } } //TODO Handle multiple file choose processFile(uris.get(0)); }
From source file:com.raspi.chatapp.ui.chatting.SendImageFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // if the user chose a image to be sent to the current buddy if (requestCode == ADD_PHOTO_CLICKED && resultCode == Activity.RESULT_OK) { if (data.getData() != null) { // one image was selected Message msg = new Message(data.getData()); images.add(msg);//www . j a v a2s.c om current = images.size() - 1; } else if (data.getClipData() != null) { // multiple images were selected ClipData clipData = data.getClipData(); for (int i = 0; i < clipData.getItemCount(); i++) images.add(new Message(clipData.getItemAt(i).getUri())); current = images.size() - 1; } } }
From source file:com.google.android.apps.muzei.gallery.GallerySettingsActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent result) { if (requestCode != REQUEST_CHOOSE_PHOTOS || resultCode != RESULT_OK) { super.onActivityResult(requestCode, resultCode, result); return;//from w ww . java2s .com } if (result == null) { return; } // Add chosen items final Set<Uri> uris = new HashSet<>(); if (result.getData() != null) { uris.add(result.getData()); } // When selecting multiple images, "Photos" returns the first URI in getData and all URIs // in getClipData. ClipData clipData = result.getClipData(); if (clipData != null) { int count = clipData.getItemCount(); for (int i = 0; i < count; i++) { uris.add(clipData.getItemAt(i).getUri()); } } // Update chosen URIs runOnHandlerThread(new Runnable() { @Override public void run() { ArrayList<ContentProviderOperation> operations = new ArrayList<>(); for (Uri uri : uris) { ContentValues values = new ContentValues(); values.put(GalleryContract.ChosenPhotos.COLUMN_NAME_URI, uri.toString()); operations.add(ContentProviderOperation.newInsert(GalleryContract.ChosenPhotos.CONTENT_URI) .withValues(values).build()); } try { getContentResolver().applyBatch(GalleryContract.AUTHORITY, operations); } catch (RemoteException | OperationApplicationException e) { Log.e(TAG, "Error writing uris to ContentProvider", e); } } }); }
From source file:com.raspi.chatapp.ui.chatting.ChatActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // if the user chose a image to be sent to the current buddy switch (requestCode) { case SEND_CAMERA_IMAGE_REQUEST_CODE: if (resultCode == RESULT_OK && data != null) sendImages(data.getData());// w ww . ja v a 2 s .com break; case SEND_LIBRARY_IMAGE_REQUEST_CODE: if (resultCode == Activity.RESULT_OK) { if (data.getData() != null) // only one image was selected sendImages(data.getData()); else if (data.getClipData() != null) { // multiple images were selected ArrayList<Uri> uris = new ArrayList<>(); ClipData clipData = data.getClipData(); for (int i = 0; i < clipData.getItemCount(); i++) uris.add(clipData.getItemAt(i).getUri()); Uri[] array = new Uri[uris.size()]; sendImages(uris.toArray(array)); } } break; case PasswordActivity.ASK_PWD_REQUEST: // if the user has entered a password or exited the passwordActivity // otherwise. if (resultCode == Activity.RESULT_OK) { // if the pwd was correct do not request a new pwd. Yep this function // is called before onResume, therefore, this would end in an // infinity loop otherwise... getSharedPreferences(Constants.PREFERENCES, 0).edit().putBoolean(Constants.PWD_REQUEST, false) .apply(); // actually I am not sure, shouldn't the onResume function be called // which calls init? init(); } else { // if (PreferenceManager.getDefaultSharedPreferences(getApplication()) // .getBoolean( // getResources().getString(R.string.pref_key_enablepwd), // true)) // startActivityForResult(new Intent(this, PasswordActivity.class), // PasswordActivity.ASK_PWD_REQUEST); // I suppose I should finish the activity here as the user pressed // back. TODO: I am not sure whether on resume gets called and finish // will really finish if the passwordActivity is called... finish(); } break; } }
From source file:com.fbartnitzek.tasteemall.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Log.v(LOG_TAG, "onActivityResult, hashCode=" + this.hashCode() + ", " + "requestCode = [" + requestCode + "], resultCode = [" + resultCode + "], data = [" + data + "]"); if (requestCode == REQUEST_EXPORT_DIR_CODE || requestCode == REQUEST_IMPORT_FILES_CODE && resultCode == AppCompatActivity.RESULT_OK) { Uri uri;//w w w . ja v a 2 s. co m if (data.getBooleanExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false)) { List<File> files = new ArrayList<>(); // For JellyBean and above if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ClipData clip = data.getClipData(); if (clip != null) { for (int i = 0; i < clip.getItemCount(); i++) { uri = clip.getItemAt(i).getUri(); // Log.v(LOG_TAG, "onActivityResult, uri=" + uri + ", hashCode=" + this.hashCode() + ", " + "requestCode = [" + requestCode + "], resultCode = [" + resultCode + "], data = [" + data + "]"); files.add(new File(uri.getPath())); // Do something with the URI } } // For Ice Cream Sandwich } else { ArrayList<String> paths = data.getStringArrayListExtra(FilePickerActivity.EXTRA_PATHS); if (paths != null) { for (String path : paths) { uri = Uri.parse(path); // TODO: might be useless conversion... // Log.v(LOG_TAG, "onActivityResult, uri=" + uri + ", hashCode=" + this.hashCode() + ", " + "requestCode = [" + requestCode + "], resultCode = [" + resultCode + "], data = [" + data + "]"); files.add(new File(uri.getPath())); } } } if (!files.isEmpty() && requestCode == REQUEST_IMPORT_FILES_CODE) { // TODO: refactor afterwards without mFiles // new ImportFilesTask(MPA.this, MPA.this).execute(files.toArray(new File[files.size()])); mFiles = files; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("which import shall be used?") .setPositiveButton("class-based", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { new ImportFilesTask(MainActivity.this, MainActivity.this) .execute(mFiles.toArray(new File[mFiles.size()])); mFiles = null; } }) // .setNegativeButton("old", new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialog, int which) { // new ImportFilesOldFormatTask(MainActivity.this, MainActivity.this) // .execute(mFiles.toArray(new File[mFiles.size()])); // mFiles = null; // } // }); .setNegativeButton("all-in-1", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // multiple all-in-1-files? new ImportAllInOneFileTask(MainActivity.this, MainActivity.this) .execute(mFiles.get(0)); mFiles = null; // to get all easier: // either all ids are known or lots of parallel stuff... // dialog with warning! // task won't help => needs Dialog everywhere... => Task // merge is to complicated for now :-p } }); builder.show(); } } else { // Log.v(LOG_TAG, "onActivityResult - single file, hashCode=" + this.hashCode() + ", " + "requestCode = [" + requestCode + "], resultCode = [" + resultCode + "], data = [" + data + "]"); uri = data.getData(); // Do something with the URI if (uri != null && requestCode == REQUEST_EXPORT_DIR_CODE) { //somehow it returned a filepath (confusing use of multiple flag... new ExportToDirTask(this, this).execute(new File(uri.getPath())); } } } else if (requestCode == REQUEST_EDIT_PRODUCER_GEOCODE && resultCode == AppCompatActivity.RESULT_OK) { if (mProducerLocationUris == null) { Log.e(LOG_TAG, "onActivityResult mProducerLocationUris == null! - should never happen..."); return; } if (mProducerLocationUris.isEmpty()) { if (mReviewLocationUris != null && !mReviewLocationUris.isEmpty()) { showReviewLocationGeocodeDialog(true); } else { Toast.makeText(MainActivity.this, "all geocoding done", Toast.LENGTH_SHORT).show(); restartCurrentFragmentLoader(); } } else { showProducerGeocodeDialog(true); } } else if (requestCode == REQUEST_EDIT_REVIEW_LOCATION_GEOCODE && resultCode == AppCompatActivity.RESULT_OK) { if (mReviewLocationUris == null) { Log.e(LOG_TAG, "onActivityResult mReviewLocationUris == null! - should never happen"); return; } if (mReviewLocationUris.isEmpty()) { Toast.makeText(MainActivity.this, "all geocoding done", Toast.LENGTH_SHORT).show(); restartCurrentFragmentLoader(); } else { showReviewLocationGeocodeDialog(true); } } else if (requestCode == ADD_REVIEW_REQUEST && resultCode == Activity.RESULT_OK && data != null) { // TODO bugfix: refresh current pager startActivity(new Intent(this, ShowReviewActivity.class).setData(data.getData())); } super.onActivityResult(requestCode, resultCode, data); }
From source file:mgks.os.webview.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (Build.VERSION.SDK_INT >= 21) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimary)); Uri[] results = null;/*from w ww . j a v a2 s.c o m*/ if (resultCode == Activity.RESULT_OK) { if (requestCode == asw_file_req) { if (null == asw_file_path) { return; } if (intent == null || intent.getData() == null) { if (asw_cam_message != null) { results = new Uri[] { Uri.parse(asw_cam_message) }; } } else { String dataString = intent.getDataString(); if (dataString != null) { results = new Uri[] { Uri.parse(dataString) }; } else { if (ASWP_MULFILE) { if (intent.getClipData() != null) { final int numSelectedFiles = intent.getClipData().getItemCount(); results = new Uri[numSelectedFiles]; for (int i = 0; i < numSelectedFiles; i++) { results[i] = intent.getClipData().getItemAt(i).getUri(); } } } } } } } asw_file_path.onReceiveValue(results); asw_file_path = null; } else { if (requestCode == asw_file_req) { if (null == asw_file_message) return; Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData(); asw_file_message.onReceiveValue(result); asw_file_message = null; } } }
From source file:com.synox.android.ui.activity.FileDisplayActivity.java
/** * Called, when the user selected something for uploading *//* w ww. j a v a 2 s .c om*/ @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == ACTION_SELECT_CONTENT_FROM_APPS && (resultCode == RESULT_OK || resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) { //getClipData is only supported on api level 16+, Jelly Bean if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && data.getClipData() != null && data.getClipData().getItemCount() > 0) { for (int i = 0; i < data.getClipData().getItemCount(); i++) { Intent intent = new Intent(); intent.setData(data.getClipData().getItemAt(i).getUri()); requestSimpleUpload(intent, resultCode); } } else { requestSimpleUpload(data, resultCode); } } else if (requestCode == ACTION_SELECT_MULTIPLE_FILES && (resultCode == RESULT_OK || resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) { requestMultipleUpload(data, resultCode); } else if (requestCode == ACTION_MOVE_FILES && resultCode == RESULT_OK) { final Intent fData = data; final int fResultCode = resultCode; getHandler().postDelayed(new Runnable() { @Override public void run() { requestMoveOperation(fData, fResultCode); } }, DELAY_TO_REQUEST_OPERATIONS_LATER); } else if (requestCode == ACTION_COPY_FILES && resultCode == RESULT_OK) { final Intent fData = data; final int fResultCode = resultCode; getHandler().postDelayed(new Runnable() { @Override public void run() { requestCopyOperation(fData, fResultCode); } }, DELAY_TO_REQUEST_OPERATIONS_LATER); } else { super.onActivityResult(requestCode, resultCode, data); } }
From source file:im.vector.activity.RoomActivity.java
@SuppressLint("NewApi") private void sendMediasIntent(final Intent data) { // sanity check if ((null == data) && (null == mLatestTakePictureCameraUri)) { return;// www .j a va2 s . c o m } ArrayList<Uri> uris = new ArrayList<Uri>(); if (null != data) { ClipData clipData = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { clipData = data.getClipData(); } // multiple data if (null != clipData) { int count = clipData.getItemCount(); for (int i = 0; i < count; i++) { ClipData.Item item = clipData.getItemAt(i); Uri uri = item.getUri(); if (null != uri) { uris.add(uri); } } } else if (null != data.getData()) { uris.add(data.getData()); } } else if (null != mLatestTakePictureCameraUri) { uris.add(Uri.parse(mLatestTakePictureCameraUri)); mLatestTakePictureCameraUri = null; } // check the extras if (0 == uris.size()) { Bundle bundle = data.getExtras(); // sanity checks if (null != bundle) { if (bundle.containsKey(Intent.EXTRA_STREAM)) { Object streamUri = bundle.get(Intent.EXTRA_STREAM); if (streamUri instanceof Uri) { uris.add((Uri) streamUri); } } else if (bundle.containsKey(Intent.EXTRA_TEXT)) { this.sendMessage(bundle.getString(Intent.EXTRA_TEXT)); } } else { uris.add(mLatestTakePictureCameraUri == null ? null : Uri.parse(mLatestTakePictureCameraUri)); mLatestTakePictureCameraUri = null; } } if (0 != uris.size()) { sendMedias(uris); } }