List of usage examples for android.content Intent getClipData
public @Nullable ClipData getClipData()
From source file:im.neon.util.VectorUtils.java
/** * Return a selected bitmap from an intent. * * @param intent the intent/* ww w . j a v a 2 s. c om*/ * @return the bitmap uri */ @SuppressLint("NewApi") public static Uri getThumbnailUriFromIntent(Context context, final Intent intent, MXMediasCache mediasCache) { // sanity check if ((null != intent) && (null != context) && (null != mediasCache)) { Uri thumbnailUri = null; ClipData clipData = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { clipData = intent.getClipData(); } // multiple data if (null != clipData) { if (clipData.getItemCount() > 0) { thumbnailUri = clipData.getItemAt(0).getUri(); } } else if (null != intent.getData()) { thumbnailUri = intent.getData(); } if (null != thumbnailUri) { try { ResourceUtils.Resource resource = ResourceUtils.openResource(context, thumbnailUri, null); // sanity check if ((null != resource) && resource.isJpegResource()) { InputStream stream = resource.mContentStream; int rotationAngle = ImageUtils.getRotationAngleForBitmap(context, thumbnailUri); String mediaUrl = ImageUtils.scaleAndRotateImage(context, stream, resource.mMimeType, 1024, rotationAngle, mediasCache); thumbnailUri = Uri.parse(mediaUrl); } return thumbnailUri; } catch (Exception e) { Log.e(LOG_TAG, "## etThumbnailUriFromIntent failed " + e.getMessage()); } } } return null; }
From source file:com.zql.android.clippings.device.view.MainActivity.java
private void parseClippings(Intent intent) { if (Intent.ACTION_SEND.equals(intent.getAction())) { ClipData clipData = intent.getClipData(); ClipData.Item item = clipData.getItemAt(0); if (item.getUri() != null) { String path = getFilePathByUri(item.getUri()); try { File file = new File(path); if (ClippingsParser.CLIPPINGS_NAME.equals(file.getName())) { InputStream inputStream = new FileInputStream(file); initDatabase(inputStream); }//from w w w . j av a 2s. c om } catch (FileNotFoundException e) { e.printStackTrace(); } Logly.d(" " + path); } } }
From source file:com.commonsware.android.tte.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_OPEN: if (resultCode == Activity.RESULT_OK) { if (data.getData() == null) { ClipData clip = data.getClipData(); for (int i = 0; i < clip.getItemCount(); i++) { openEditor(clip.getItemAt(i).getUri()); }/*from ww w . j ava 2 s . c o m*/ } else { openEditor(data.getData()); } } break; case REQUEST_CREATE: if (resultCode == Activity.RESULT_OK) { openEditor(data.getData()); } break; } }
From source file:jackpal.androidterm.RemoteInterface.java
protected void handleIntent() { TermService service = getTermService(); if (service == null) { finish();//from w w w . j a v a2 s. com return; } Intent myIntent = getIntent(); String action = myIntent.getAction(); if (action == null) { finish(); return; } ClipData clipData = myIntent.getClipData(); if ((AndroidCompat.SDK >= 19 && action.equals(Intent.ACTION_SEND) && myIntent.hasExtra(Intent.EXTRA_STREAM)) || (action.equals(Intent.ACTION_SEND) && clipData != null) || (action.equals("android.intent.action.VIEW")) || (action.equals("android.intent.action.EDIT")) || (action.equals("android.intent.action.PICK")) || (action.equals("com.googlecode.android_scripting.action.EDIT_SCRIPT"))) { String url = null; Uri uri = null; if (clipData != null) { uri = clipData.getItemAt(0).getUri(); if (uri == null) { openText(clipData.getItemAt(0).getText()); finish(); return; } } else if (AndroidCompat.SDK >= 19 && action.equals(Intent.ACTION_SEND) && myIntent.hasExtra(Intent.EXTRA_STREAM)) { Object extraStream = myIntent.getExtras().get(Intent.EXTRA_STREAM); if (extraStream instanceof Uri) { uri = (Uri) extraStream; } } else { uri = myIntent.getData(); } String intentCommand = "sh "; if (mSettings.getInitialCommand().matches("(.|\n)*(^|\n)-vim\\.app(.|\n)*")) { intentCommand = ":e "; } boolean flavorVim = intentCommand.matches("^:.*"); if (uri != null && uri.toString().matches("^file:///.*") && flavorVim) { String path = uri.getPath(); if (new File(path).canRead()) { path = path.replaceAll(Term.SHELL_ESCAPE, "\\\\$1"); String command = "\u001b" + intentCommand + path; // Find the target window mReplace = true; mHandle = switchToWindow(mHandle, command); mReplace = false; } finish(); } else if (AndroidCompat.SDK >= 19 && uri != null && uri.getScheme() != null && uri.getScheme().equals("content") && flavorVim) { Context context = this; String command = null; String path = Term.getPath(context, uri); if (path != null) { path = path.replaceAll(Term.SHELL_ESCAPE, "\\\\$1"); command = "\u001b" + intentCommand + path; } else if (getContentResolver() != null) { try { Cursor cursor = getContentResolver().query(uri, null, null, null, null, null); path = Term.handleOpenDocument(uri, cursor); } catch (Exception e) { alert(e.toString() + "\n" + this.getString(R.string.storage_read_error)); finish(); } if (path == null) { alert(this.getString(R.string.storage_read_error)); finish(); } else { File dir = Term.getScratchCacheDir(this); SyncFileObserver sfo = new SyncFileObserver(path); sfo.setConTentResolver(this.getContentResolver()); path = dir.toString() + path; String fname = new File(path).getName(); if (path.equals("") || !sfo.putUriAndLoad(uri, path)) { alert(fname + "\n" + this.getString(R.string.storage_read_error)); finish(); } path = path.replaceAll(Term.SHELL_ESCAPE, "\\\\$1"); command = "\u001b" + intentCommand + path; } } // Find the target window mReplace = true; mHandle = switchToWindow(mHandle, command); mReplace = false; finish(); } else if (action.equals("com.googlecode.android_scripting.action.EDIT_SCRIPT")) { url = myIntent.getExtras().getString("com.googlecode.android_scripting.extra.SCRIPT_PATH"); } else if (myIntent.getScheme() != null && myIntent.getScheme() != null && myIntent.getScheme().equals("file")) { if (myIntent.getData() != null) url = myIntent.getData().getPath(); } if (url != null) { String command = "sh "; if (mSettings.getInitialCommand().matches("(.|\n)*(^|\n)-vim\\.app(.|\n)*")) { command = ":e "; } if (command.matches("^:.*")) { url = url.replaceAll(Term.SHELL_ESCAPE, "\\\\$1"); command = "\u001b" + command + url; // Find the target window mReplace = true; mHandle = switchToWindow(mHandle, command); mReplace = false; } else if ((mHandle != null) && (url.equals(mFname))) { // Target the request at an existing window if open command = command + url; mHandle = switchToWindow(mHandle, command); } else { // Open a new window command = command + url; mHandle = openNewWindow(command); } mFname = url; Intent result = new Intent(); result.putExtra(EXTRA_WINDOW_HANDLE, mHandle); setResult(RESULT_OK, result); } } else if (action.equals(Intent.ACTION_SEND) && myIntent.hasExtra(Intent.EXTRA_TEXT)) { openText(myIntent.getExtras().getCharSequence(Intent.EXTRA_TEXT)); } else { } finish(); }
From source file:org.fs.galleon.presenters.ToolsFragmentPresenter.java
@Override public void activityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_PICK_GALLERY) { if (resultCode == Activity.RESULT_OK) { ClipData clipData = null;//from ww w . j a v a 2 s . c o m if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { clipData = data.getClipData(); } if (clipData != null) { //multi choice List<ImageEntity> items = IntStreams.range(0, clipData.getItemCount()) .mapToObj(clipData::getItemAt) .map(item -> Images.getPath(view.getContext(), item.getUri())) .map(xPath -> new ImageEntity.Builder().imageUri(Uri.fromFile(new File(xPath))).build()) .collect(Collectors.toList()); createIfImageListNotExists(); if (!Collections.isNullOrEmpty(items)) { images.addAll(items); } } else { //single choice Uri uri = data.getData(); if (uri != null) { String path = Images.getPath(view.getContext(), uri); ImageEntity entity = new ImageEntity.Builder().imageUri(Uri.fromFile(new File(path))) .build(); createIfImageListNotExists(); images.add(entity); } } } } else if (requestCode == REQUEST_TAKE_PHOTO) { if (resultCode == Activity.RESULT_OK) { if (tempTakenPhoto != null && tempTakenPhoto.exists()) { ImageEntity entity = new ImageEntity.Builder().imageUri(Uri.fromFile(tempTakenPhoto)).build(); //I might need to use orientation data and etc. createIfImageListNotExists();//create if its null if (view.isAvailable()) { images.add(entity); } tempTakenPhoto = null;//clear it now } } } }
From source file:org.alfresco.mobile.android.application.fragments.upload.UploadFormFragment.java
@Override public void onStart() { super.onStart(); Intent intent = getActivity().getIntent(); String action = intent.getAction(); String type = intent.getType(); if (files != null) { files.clear();//from ww w. j a v a 2 s.c o m } try { if (Intent.ACTION_SEND_MULTIPLE.equals(action)) { if (AndroidVersion.isJBOrAbove()) { ClipData clipdata = intent.getClipData(); if (clipdata != null && clipdata.getItemCount() > 1) { Item item = null; for (int i = 0; i < clipdata.getItemCount(); i++) { item = clipdata.getItemAt(i); Uri uri = item.getUri(); if (uri != null) { retrieveIntentInfo(uri); } else { String timeStamp = new SimpleDateFormat("yyyyddMM_HHmmss").format(new Date()); File localParentFolder = StorageManager.getCacheDir(getActivity(), "AlfrescoMobile/import"); File f = createFile(localParentFolder, timeStamp + ".txt", item.getText().toString()); if (f.exists()) { retrieveIntentInfo(Uri.fromFile(f)); } } if (!files.contains(file)) { files.add(file); } } } } else { if (intent.getExtras() != null && intent.getExtras().get(Intent.EXTRA_STREAM) instanceof ArrayList) { @SuppressWarnings("unchecked") List<Object> attachments = (ArrayList<Object>) intent.getExtras().get(Intent.EXTRA_STREAM); for (Object object : attachments) { if (object instanceof Uri) { Uri uri = (Uri) object; if (uri != null) { retrieveIntentInfo(uri); } if (!files.contains(file)) { files.add(file); } } } } else if (file == null || fileName == null) { MessengerManager.showLongToast(getActivity(), getString(R.string.import_unsupported_intent)); getActivity().finish(); return; } } } else { // Manage only one clip data. If multiple we ignore. if (AndroidVersion.isJBOrAbove() && (!Intent.ACTION_SEND.equals(action) || type == null)) { ClipData clipdata = intent.getClipData(); if (clipdata != null && clipdata.getItemCount() == 1 && clipdata.getItemAt(0) != null && (clipdata.getItemAt(0).getText() != null || clipdata.getItemAt(0).getUri() != null)) { Item item = clipdata.getItemAt(0); Uri uri = item.getUri(); if (uri != null) { retrieveIntentInfo(uri); } else { String timeStamp = new SimpleDateFormat("yyyyddMM_HHmmss").format(new Date()); File localParentFolder = StorageManager.getCacheDir(getActivity(), "AlfrescoMobile/import"); File f = createFile(localParentFolder, timeStamp + ".txt", item.getText().toString()); if (f.exists()) { retrieveIntentInfo(Uri.fromFile(f)); } } } } if (file == null && Intent.ACTION_SEND.equals(action) && type != null) { Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); retrieveIntentInfo(uri); } else if (action == null && intent.getData() != null) { retrieveIntentInfo(intent.getData()); } else if (file == null || fileName == null) { MessengerManager.showLongToast(getActivity(), getString(R.string.import_unsupported_intent)); getActivity().finish(); return; } if (!files.contains(file)) { files.add(file); } } } catch (AlfrescoAppException e) { org.alfresco.mobile.android.application.manager.ActionManager.actionDisplayError(this, e); getActivity().finish(); return; } if (adapter == null && files != null) { adapter = new FileExplorerAdapter(this, R.layout.app_list_progress_row, files); if (lv != null) { lv.setAdapter(adapter); } else if (spinnerDoc != null) { spinnerDoc.setAdapter(adapter); } } Button b = UIUtils.initCancel(rootView, R.string.cancel); b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { getActivity().finish(); } }); b = UIUtils.initValidation(rootView, R.string.next); b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { next(); } }); refreshImportFolder(); }
From source file:de.evilbrain.sendtosftp.Main.java
@SuppressLint("NewApi") private void handlePushFromApp() { // Push to this app Intent intent = getIntent(); String type = intent.getType(); if (type != null) { // Set all visible fileNameText.setVisibility(View.VISIBLE); fileName.setVisibility(View.VISIBLE); imagePreview.setVisibility(View.VISIBLE); buttonSend.setVisibility(View.VISIBLE); // get Content String contentString = ""; Object content = null;//from ww w. ja v a 2s. co m if (android.os.Build.VERSION.SDK_INT > 16) { content = intent.getClipData().getItemAt(0).getUri(); contentString = content.toString(); } else { content = intent.getExtras().get(Intent.EXTRA_STREAM); contentString = content.toString(); } // set filename fileName.setText(contentString); // Preview Image if (type.contains("image")) { imagePreview.setImageURI((Uri) content); } } }
From source file:ee.ria.DigiDoc.fragment.ContainerDetailsFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == CHOOSE_FILE_REQUEST_ID && resultCode == RESULT_OK && data != null) { ClipData clipData;//from w w w .j a va2s .co m Uri uriData; if ((clipData = data.getClipData()) != null) { for (int i = 0; i < clipData.getItemCount(); i++) { ClipData.Item item = clipData.getItemAt(i); Uri uri = item.getUri(); if (uri != null) { addToFileList(uri); } } } else if ((uriData = data.getData()) != null) { addToFileList(uriData); } } }
From source file:com.anjalimacwan.MainActivity.java
@TargetApi(Build.VERSION_CODES.KITKAT) @Override//from w w w . j a v a2s. co m 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.anjalimacwan.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) reallyExportNote(); else showToast(successful ? (fileBeingExported == 1 ? R.string.note_exported_to : R.string.notes_exported_to) : R.string.error_exporting_notes); } 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()))); saveExportedNote(loadNote(exportFilename.toString()), file.getUri()); } catch (IOException e) { successful = false; } } showToast(successful ? R.string.notes_exported_to : R.string.error_exporting_notes); } } }
From source file:org.sufficientlysecure.keychain.ui.EncryptFilesFragment.java
public void addInputUri(Intent data) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { mPendingInputUris.add(data.getData()); } else {//from w w w . j av a 2s . c o m if (data.getClipData() != null && data.getClipData().getItemCount() > 0) { for (int i = 0; i < data.getClipData().getItemCount(); i++) { Uri uri = data.getClipData().getItemAt(i).getUri(); if (uri != null) { mPendingInputUris.add(uri); } } } else { // fallback, try old method to get single uri mPendingInputUris.add(data.getData()); } } // process pending uris processPendingInputUris(); }