List of usage examples for android.content Intent getType
public @Nullable String getType()
From source file:com.android.gallery3d.app.PhotoPage.java
private void setCurrentPhotoByIntent(Intent intent) { if (intent == null) return;/*from w w w . ja v a2 s.com*/ Path path = mApplication.getDataManager().findPathByUri(intent.getData(), intent.getType()); if (path != null) { Path albumPath = mApplication.getDataManager().getDefaultSetOf(path); if (albumPath == null) { return; } if (!albumPath.equalsIgnoreCase(mOriginalSetPathString)) { // If the edited image is stored in a different album, we need // to start a new activity state to show the new image Bundle data = new Bundle(getData()); data.putString(KEY_MEDIA_SET_PATH, albumPath.toString()); data.putString(PhotoPage.KEY_MEDIA_ITEM_PATH, path.toString()); mActivity.getStateManager().startState(SinglePhotoPage.class, data); return; } mModel.setCurrentPhoto(path, mCurrentIndex); } }
From source file:com.android.gallery3d.app.PhotoPage.java
private void setRefocusCurrentPhotoByIntent(Intent intent) { if (intent == null) { Log.i(TAG, "<setRefocusCurrentPhotoByIntent> intent is null, return"); return;//from w ww .j a v a 2 s. c o m } Path path = mApplication.getDataManager().findPathByUri(intent.getData(), intent.getType()); if (null != path) { String string = path.toString(); if (null != string) { mModel.setCurrentPhoto(Path.fromString(string), mCurrentIndex); } } }
From source file:com.android.gallery3d.app.PhotoPage.java
private void setCurrentPhotoByIntentEx(Intent intent) { if (intent == null) { Log.i(TAG, "<setCurrentPhotoByIntentEx> inetnt is null, return"); return;//from w w w .j a va2s .c om } Path photoEditPath = mApplication.getDataManager().findPathByUri(intent.getData(), intent.getType()); if (photoEditPath != null) { String string = photoEditPath.toString(); if (string != null) { // mark the cache for edited image out of date ImageCacheService.sForceObsoletePath = string; mModel.setCurrentPhoto(Path.fromString(string), mCurrentIndex); } } Log.d(TAG, "<setCurrentPhotoByIntentEx> intent.getData()=" + intent.getData()); Intent shareIntent = createShareIntent(intent.getData(), MediaObject.MEDIA_TYPE_IMAGE); if (mActionBar != null) { mActionBar.setShareIntents(null, shareIntent, PhotoPage.this); } }
From source file:cgeo.geocaching.CacheListActivity.java
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE_IMPORT_GPX && resultCode == Activity.RESULT_OK) { // The document selected by the user won't be returned in the intent. // Instead, a URI to that document will be contained in the return intent // provided to this method as a parameter. Pull that uri using "resultData.getData()" if (data != null) { final Uri uri = data.getData(); new GPXImporter(this, listId, importGpxAttachementFinishedHandler).importGPX(uri, null, getDisplayName(uri)); }/* w w w .j a va 2s. c o m*/ } else if (requestCode == REQUEST_CODE_IMPORT_PQ && resultCode == Activity.RESULT_OK) { if (data != null) { final Uri uri = data.getData(); new GPXImporter(this, listId, importGpxAttachementFinishedHandler).importGPX(uri, data.getType(), null); } } else if (requestCode == FilterActivity.REQUEST_SELECT_FILTER && resultCode == Activity.RESULT_OK) { final int[] filterIndex = data.getIntArrayExtra(FilterActivity.EXTRA_FILTER_RESULT); setFilter(FilterActivity.getFilterFromPosition(filterIndex[0], filterIndex[1])); } else if (requestCode == REQUEST_CODE_RESTART && resultCode == Activity.RESULT_OK) { restartActivity(); } if (type == CacheListType.OFFLINE && requestCode != REQUEST_CODE_RESTART) { refreshCurrentList(); } }
From source file:com.android.gallery3d.app.PhotoPage.java
private void redirectCurrentMedia(Uri uri, boolean fromActivityResult) { Log.d(TAG, "<redirectCurrentMedia> uri=" + uri + ", fromActivity=" + fromActivityResult); if (uri == null) { Log.e(TAG, "<redirectCurrentMedia> redirect current media, null uri"); return;/* ww w. ja v a 2 s . c o m*/ } final Intent intent = new Intent().setData(uri); if (fromActivityResult) { setCurrentPhotoByIntentEx(intent); } else { // switch photo to avoid un-predicated jump error // the switch method need sth. about camera, so I just wait camera's patch first Path path = mApplication.getDataManager().findPathByUri(intent.getData(), intent.getType()); Log.d(TAG, "<redirectCurrentMedia> type=" + intent.getType() + ", path=" + path); if (path != null) { mData.putString(PhotoPage.KEY_MEDIA_ITEM_PATH, path.toString()); mData.putBoolean(PhotoPage.KEY_START_IN_FILMSTRIP, mPhotoView.getFilmMode()); mData.putInt(PhotoPage.KEY_INDEX_HINT, mCurrentIndex); Log.d(TAG, "<redirectCurrentMedia> mSetPathString=" + mSetPathString); mHandler.post(new Runnable() { public void run() { StateManager stateManager = mActivity.getStateManager(); // the following condition is logically same to say // if (!PhotoPage.this.isDestroyed()) { if ((stateManager.getStateCount() > 0) && (stateManager.getTopState() == PhotoPage.this)) { mActivity.getStateManager().switchState(PhotoPage.this, SinglePhotoPage.class, mData); } } }); } } }
From source file:de.azapps.mirakel.main_activity.MainActivity.java
private void handleIntent(final Intent intent) { if ((intent == null) || (intent.getAction() == null)) { Log.d(MainActivity.TAG, "action null"); } else if (DefinitionsHelper.SHOW_TASK.equals(intent.getAction()) || DefinitionsHelper.SHOW_TASK_REMINDER.equals(intent.getAction()) || DefinitionsHelper.SHOW_TASK_FROM_WIDGET.equals(intent.getAction())) { final Optional<Task> task = TaskHelper.getTaskFromIntent(intent); if (task.isPresent()) { this.currentList = task.get().getList(); if (this.mDrawerLayout != null) { this.mDrawerLayout.postDelayed(new Runnable() { @Override/*ww w .ja v a 2 s .c o m*/ public void run() { setCurrentTask(task.get(), true); } }, 10L); } } else { Log.d(MainActivity.TAG, "task null"); } if (intent.getAction().equals(DefinitionsHelper.SHOW_TASK_FROM_WIDGET)) { this.closeOnBack = true; } } else if (intent.getAction().equals(Intent.ACTION_SEND) || intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) { this.closeOnBack = true; this.newTaskContent = intent.getStringExtra(Intent.EXTRA_TEXT); this.newTaskSubject = intent.getStringExtra(Intent.EXTRA_SUBJECT); // If from google now, the content is the subject if ((intent.getCategories() != null) && intent.getCategories().contains("com.google.android.voicesearch.SELF_NOTE") && !this.newTaskContent.isEmpty()) { this.newTaskSubject = this.newTaskContent; this.newTaskContent = ""; } if (!"text/plain".equals(intent.getType()) && (this.newTaskSubject == null)) { this.newTaskSubject = MirakelCommonPreferences.getImportFileTitle(); } final Optional<ListMirakel> listFromSharing = MirakelModelPreferences.getImportDefaultList(); if (listFromSharing.isPresent()) { addTaskFromSharing(listFromSharing.get(), intent); } else { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.import_to); final List<CharSequence> items = new ArrayList<>(); final List<Long> list_ids = new ArrayList<>(); final int currentItem = 0; for (final ListMirakel list : ListMirakel.all()) { if (list.getId() > 0) { items.add(list.getName()); list_ids.add(list.getId()); } } builder.setSingleChoiceItems(items.toArray(new CharSequence[items.size()]), currentItem, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { final Optional<ListMirakel> listMirakelOptional = ListMirakel .get(list_ids.get(which)); withOptional(listMirakelOptional, new OptionalUtils.Procedure<ListMirakel>() { @Override public void apply(final ListMirakel input) { addTaskFromSharing(input, intent); dialog.dismiss(); } }); } }); builder.create().show(); } } else if (intent.getAction().equals(DefinitionsHelper.SHOW_LIST) || intent.getAction().contains(DefinitionsHelper.SHOW_LIST_FROM_WIDGET)) { final Optional<ListMirakel> listMirakelOptional = ListHelper.getListMirakelFromIntent(intent); if (listMirakelOptional.isPresent()) { final ListMirakel list = listMirakelOptional.get(); setCurrentList(list); final Optional<Task> taskOptional = list.getFirstTask(); if (taskOptional.isPresent()) { this.currentTask = taskOptional.get(); } if (getTaskFragment() != null) { getTaskFragment().update(this.currentTask); } } else { Log.d(TAG, "show_list does not pass list, so ignore this"); } } else if (intent.getAction().equals(DefinitionsHelper.SHOW_LISTS)) { this.mDrawerLayout.openDrawer(DefinitionsHelper.GRAVITY_LEFT); } else if (intent.getAction().equals(Intent.ACTION_SEARCH)) { final String query = intent.getStringExtra(SearchManager.QUERY); search(query); } else if (intent.getAction().contains(DefinitionsHelper.ADD_TASK_FROM_WIDGET)) { final int listId = Integer .parseInt(intent.getAction().replace(DefinitionsHelper.ADD_TASK_FROM_WIDGET, "")); final Optional<ListMirakel> listMirakelOptional = ListMirakel.get(listId); if (listMirakelOptional.isPresent()) { setCurrentList(listMirakelOptional.get()); } else { setCurrentList(ListMirakel.safeFirst()); } this.mDrawerLayout.postDelayed(new Runnable() { @Override public void run() { if ((getTasksFragment() != null) && getTasksFragment().isReady()) { getTasksFragment().focusNew(true); } else if (!MirakelCommonPreferences.isTablet()) { runOnUiThread(new Runnable() { @Override public void run() { if (getTasksFragment() != null) { getTasksFragment().focusNew(true); } else { Log.wtf(MainActivity.TAG, "Tasksfragment null"); } } }); } } }, 10); } else if (intent.getAction().equals(DefinitionsHelper.SHOW_MESSAGE)) { final String message = intent.getStringExtra(Intent.EXTRA_TEXT); String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT); if (message != null) { if (subject == null) { subject = getString(R.string.message_notification); } final TextView msg = (TextView) getLayoutInflater().inflate(R.layout.alertdialog_textview, null); msg.setText(Html.fromHtml(message)); msg.setMovementMethod(LinkMovementMethod.getInstance()); msg.setClickable(true); new AlertDialog.Builder(this).setTitle(subject).setView(msg).show(); } } else { setCurrentItem(getTaskFragmentPosition()); } if (((intent == null) || (intent.getAction() == null) || !intent.getAction().contains(DefinitionsHelper.ADD_TASK_FROM_WIDGET)) && (getTasksFragment() != null)) { getTasksFragment().clearFocus(); } setIntent(null); if (this.currentList == null) { setCurrentList(SpecialList.firstSpecialSafe()); } }
From source file:com.vuze.android.remote.fragment.FilesFragment.java
@SuppressWarnings("unused") protected boolean reallyStreamFile(Map<?, ?> selectedFile) { final String contentURL = getContentURL(selectedFile); if (contentURL != null && contentURL.length() > 0) { Uri uri = Uri.parse(contentURL); Intent intent = new Intent(Intent.ACTION_VIEW, uri); String name = MapUtils.getMapString(selectedFile, "name", "video"); intent.putExtra("title", name); String extension = MimeTypeMap.getFileExtensionFromUrl(contentURL).toLowerCase(Locale.US); String mimetype = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); if (mimetype != null && tryLaunchWithMimeFirst) { intent.setType(mimetype);/*from w w w. j a v a 2 s.co m*/ } Class<?> fallBackIntentClass = VideoViewer.class; if (mimetype != null && mimetype.startsWith("image")) { fallBackIntentClass = ImageViewer.class; } final PackageManager packageManager = getActivity().getPackageManager(); List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (AndroidUtils.DEBUG) { Log.d(TAG, "num intents " + list.size()); for (ResolveInfo info : list) { ComponentInfo componentInfo = AndroidUtils.getComponentInfo(info); Log.d(TAG, info.toString() + "/" + (componentInfo == null ? "null" : (componentInfo.name + "/" + componentInfo))); } } if (list.size() == 0) { // Intent will launch, but show message to the user: // "Opening web browser links is not supported" intent.setClass(getActivity(), fallBackIntentClass); } if (list.size() == 1) { ResolveInfo info = list.get(0); ComponentInfo componentInfo = AndroidUtils.getComponentInfo(info); if (componentInfo != null && componentInfo.name != null) { if ("com.amazon.unifiedshare.actionchooser.BuellerShareActivity".equals(componentInfo.name) || componentInfo.name.startsWith("com.google.android.tv.frameworkpackagestubs.Stubs")) { intent.setClass(getActivity(), fallBackIntentClass); } } } try { startActivity(intent); if (AndroidUtils.DEBUG) { Log.d(TAG, "Started " + uri + " MIME: " + intent.getType()); } } catch (java.lang.SecurityException es) { if (AndroidUtils.DEBUG) { Log.d(TAG, "ERROR launching. " + es.toString()); } if (mimetype != null) { try { Intent intent2 = new Intent(Intent.ACTION_VIEW, uri); intent2.putExtra("title", name); if (!tryLaunchWithMimeFirst) { intent2.setType(mimetype); } list = packageManager.queryIntentActivities(intent2, PackageManager.MATCH_DEFAULT_ONLY); if (AndroidUtils.DEBUG) { Log.d(TAG, "num intents " + list.size()); for (ResolveInfo info : list) { ComponentInfo componentInfo = AndroidUtils.getComponentInfo(info); Log.d(TAG, info.toString() + "/" + (componentInfo == null ? "null" : (componentInfo.name + "/" + componentInfo))); } } startActivity(intent2); if (AndroidUtils.DEBUG) { Log.d(TAG, "Started with" + (intent2.getType() == null ? " no" : " ") + " mime: " + uri); } return true; } catch (Throwable ex2) { if (AndroidUtils.DEBUG) { Log.d(TAG, "no intent for view. " + ex2.toString()); } } } Toast.makeText(getActivity().getApplicationContext(), getActivity().getResources().getString(R.string.intent_security_fail), Toast.LENGTH_LONG) .show(); } catch (android.content.ActivityNotFoundException ex) { if (AndroidUtils.DEBUG) { Log.d(TAG, "no intent for view. " + ex.toString()); } if (mimetype != null) { try { Intent intent2 = new Intent(Intent.ACTION_VIEW, uri); intent2.putExtra("title", name); if (!tryLaunchWithMimeFirst) { intent2.setType(mimetype); } startActivity(intent2); if (AndroidUtils.DEBUG) { Log.d(TAG, "Started (no mime set) " + uri); } return true; } catch (android.content.ActivityNotFoundException ex2) { if (AndroidUtils.DEBUG) { Log.d(TAG, "no intent for view. " + ex2.toString()); } } } Toast.makeText(getActivity().getApplicationContext(), getActivity().getResources().getString(R.string.no_intent), Toast.LENGTH_SHORT).show(); } return true; } return true; }
From source file:org.runbuddy.tomahawk.activities.TomahawkMainActivity.java
private void handleIntent(Intent intent) { if (MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH.equals(intent.getAction())) { intent.setAction(null);// w ww. j a v a 2 s .c o m String playbackManagerId = getSupportMediaController().getExtras() .getString(PlaybackService.EXTRAS_KEY_PLAYBACKMANAGER); PlaybackManager playbackManager = PlaybackManager.getByKey(playbackManagerId); MediaPlayIntentHandler intentHandler = new MediaPlayIntentHandler( getSupportMediaController().getTransportControls(), playbackManager); intentHandler.mediaPlayFromSearch(intent.getExtras()); } if ("com.google.android.gms.actions.SEARCH_ACTION".equals(intent.getAction())) { intent.setAction(null); String query = intent.getStringExtra(SearchManager.QUERY); if (query != null && !query.isEmpty()) { DatabaseHelper.get().addEntryToSearchHistory(query); Bundle bundle = new Bundle(); bundle.putString(TomahawkFragment.QUERY_STRING, query); bundle.putInt(TomahawkFragment.CONTENT_HEADER_MODE, ContentHeaderFragment.MODE_HEADER_STATIC); FragmentUtils.replace(TomahawkMainActivity.this, SearchPagerFragment.class, bundle); } } if (SHOW_PLAYBACKFRAGMENT_ON_STARTUP.equals(intent.getAction())) { intent.setAction(null); // if this Activity is being shown after the user clicked the notification if (mSlidingUpPanelLayout != null) { mSlidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED); } } if (intent.hasExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE)) { intent.removeExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE); Bundle bundle = new Bundle(); bundle.putInt(TomahawkFragment.CONTENT_HEADER_MODE, ContentHeaderFragment.MODE_HEADER_STATIC_SMALL); FragmentUtils.replace(this, PreferencePagerFragment.class, bundle); } if (intent.getData() != null) { final Uri data = intent.getData(); intent.setData(null); List<String> pathSegments = data.getPathSegments(); String host = data.getHost(); String scheme = data.getScheme(); if ((scheme != null && (scheme.equals("spotify") || scheme.equals("tomahawk"))) || (host != null && (host.contains("spotify.com") || host.contains("hatchet.is") || host.contains("toma.hk") || host.contains("beatsmusic.com") || host.contains("deezer.com") || host.contains("rdio.com") || host.contains("soundcloud.com")))) { PipeLine.get().lookupUrl(data.toString()); } else if ((pathSegments != null && pathSegments.get(pathSegments.size() - 1).endsWith(".xspf")) || (intent.getType() != null && intent.getType().equals("application/xspf+xml"))) { TomahawkRunnable r = new TomahawkRunnable(TomahawkRunnable.PRIORITY_IS_INFOSYSTEM_HIGH) { @Override public void run() { Playlist pl = XspfParser.parse(data); if (pl != null) { final Bundle bundle = new Bundle(); bundle.putString(TomahawkFragment.PLAYLIST, pl.getCacheKey()); bundle.putInt(TomahawkFragment.CONTENT_HEADER_MODE, ContentHeaderFragment.MODE_HEADER_DYNAMIC); new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { FragmentUtils.replace(TomahawkMainActivity.this, PlaylistEntriesFragment.class, bundle); } }); } } }; ThreadManager.get().execute(r); } else if (pathSegments != null && (pathSegments.get(pathSegments.size() - 1).endsWith(".axe") || pathSegments.get(pathSegments.size() - 1).endsWith(".AXE"))) { InstallPluginConfigDialog dialog = new InstallPluginConfigDialog(); Bundle args = new Bundle(); args.putString(InstallPluginConfigDialog.PATH_TO_AXE_URI_STRING, data.toString()); dialog.setArguments(args); dialog.show(getSupportFragmentManager(), null); } else { String albumName; String trackName; String artistName; try { MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(this, data); albumName = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM); artistName = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST); trackName = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); retriever.release(); } catch (Exception e) { Log.e(TAG, "handleIntent: " + e.getClass() + ": " + e.getLocalizedMessage()); new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { String msg = TomahawkApp.getContext().getString(R.string.invalid_file); Toast.makeText(TomahawkApp.getContext(), msg, Toast.LENGTH_LONG).show(); } }); return; } if (TextUtils.isEmpty(trackName) && pathSegments != null) { trackName = pathSegments.get(pathSegments.size() - 1); } Query query = Query.get(trackName, albumName, artistName, false); Result result = Result.get(data.toString(), query.getBasicTrack(), UserCollectionStubResolver.get()); float trackScore = query.howSimilar(result); query.addTrackResult(result, trackScore); Bundle bundle = new Bundle(); List<Query> queries = new ArrayList<>(); queries.add(query); Playlist playlist = Playlist.fromQueryList(IdGenerator.getSessionUniqueStringId(), "", "", queries); playlist.setFilled(true); playlist.setName(artistName + " - " + trackName); bundle.putString(TomahawkFragment.PLAYLIST, playlist.getCacheKey()); bundle.putInt(TomahawkFragment.CONTENT_HEADER_MODE, ContentHeaderFragment.MODE_HEADER_DYNAMIC); FragmentUtils.replace(TomahawkMainActivity.this, PlaylistEntriesFragment.class, bundle); } } }
From source file:nya.miku.wishmaster.ui.GalleryActivity.java
private void share() { GalleryItemViewTag tag = getCurrentTag(); if (tag == null) return;//from w w w. j ava2s. com Intent shareIntent = new Intent(Intent.ACTION_SEND); String extension = Attachments.getAttachmentExtention(tag.attachmentModel); switch (tag.attachmentModel.type) { case AttachmentModel.TYPE_IMAGE_GIF: shareIntent.setType("image/gif"); break; case AttachmentModel.TYPE_IMAGE_STATIC: if (extension.equalsIgnoreCase(".png")) { shareIntent.setType("image/png"); } else if (extension.equalsIgnoreCase(".jpg") || extension.equalsIgnoreCase(".jpg")) { shareIntent.setType("image/jpeg"); } else { shareIntent.setType("image/*"); } break; case AttachmentModel.TYPE_VIDEO: if (extension.equalsIgnoreCase(".mp4")) { shareIntent.setType("video/mp4"); } else if (extension.equalsIgnoreCase(".webm")) { shareIntent.setType("video/webm"); } else if (extension.equalsIgnoreCase(".avi")) { shareIntent.setType("video/avi"); } else if (extension.equalsIgnoreCase(".mov")) { shareIntent.setType("video/quicktime"); } else if (extension.equalsIgnoreCase(".mkv")) { shareIntent.setType("video/x-matroska"); } else if (extension.equalsIgnoreCase(".flv")) { shareIntent.setType("video/x-flv"); } else if (extension.equalsIgnoreCase(".wmv")) { shareIntent.setType("video/x-ms-wmv"); } else { shareIntent.setType("video/*"); } break; case AttachmentModel.TYPE_AUDIO: if (extension.equalsIgnoreCase(".mp3")) { shareIntent.setType("audio/mpeg"); } else if (extension.equalsIgnoreCase(".mp4")) { shareIntent.setType("audio/mp4"); } else if (extension.equalsIgnoreCase(".ogg")) { shareIntent.setType("audio/ogg"); } else if (extension.equalsIgnoreCase(".webm")) { shareIntent.setType("audio/webm"); } else if (extension.equalsIgnoreCase(".flac")) { shareIntent.setType("audio/flac"); } else if (extension.equalsIgnoreCase(".wav")) { shareIntent.setType("audio/vnd.wave"); } else { shareIntent.setType("audio/*"); } break; case AttachmentModel.TYPE_OTHER_FILE: shareIntent.setType("application/octet-stream"); break; } Logger.d(TAG, shareIntent.getType()); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(tag.file)); startActivity(Intent.createChooser(shareIntent, getString(R.string.share_via))); }
From source file:org.kontalk.ui.AbstractComposeFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // image from storage/picture from camera // since there are like up to 3 different ways of doing this... if (requestCode == SELECT_ATTACHMENT_OPENABLE || requestCode == SELECT_ATTACHMENT_PHOTO) { if (resultCode == Activity.RESULT_OK) { Uri[] uris = null;//from www .j a v a2s .com String[] mimes = null; // returning from camera if (requestCode == SELECT_ATTACHMENT_PHOTO) { if (mCurrentPhoto != null) { Uri uri = Uri.fromFile(mCurrentPhoto); // notify media scanner Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); mediaScanIntent.setData(uri); getActivity().sendBroadcast(mediaScanIntent); mCurrentPhoto = null; uris = new Uri[] { uri }; } } else { if (mCurrentPhoto != null) { mCurrentPhoto.delete(); mCurrentPhoto = null; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && data.getClipData() != null) { ClipData cdata = data.getClipData(); uris = new Uri[cdata.getItemCount()]; for (int i = 0; i < uris.length; i++) { ClipData.Item item = cdata.getItemAt(i); uris[i] = item.getUri(); } } else { uris = new Uri[] { data.getData() }; mimes = new String[] { data.getType() }; } // SAF available, request persistable permissions if (MediaStorage.isStorageAccessFrameworkAvailable()) { for (Uri uri : uris) { if (uri != null && !"file".equals(uri.getScheme())) { MediaStorage.requestPersistablePermissions(getActivity(), uri); } } } } for (int i = 0; uris != null && i < uris.length; i++) { Uri uri = uris[i]; if (uri == null) continue; String mime = (mimes != null && mimes.length >= uris.length) ? mimes[i] : null; if (mime == null || mime.startsWith("*/") || mime.endsWith("/*")) { mime = MediaStorage.getType(getActivity(), uri); Log.v(TAG, "using detected mime type " + mime); } if (ImageComponent.supportsMimeType(mime)) sendBinaryMessage(uri, mime, true, ImageComponent.class); else if (VCardComponent.supportsMimeType(mime)) sendBinaryMessage(uri, VCardComponent.MIME_TYPE, false, VCardComponent.class); else Toast.makeText(getActivity(), R.string.send_mime_not_supported, Toast.LENGTH_LONG).show(); } } // operation aborted else { // delete photo :) if (mCurrentPhoto != null) { mCurrentPhoto.delete(); mCurrentPhoto = null; } } } // contact card (vCard) else if (requestCode == SELECT_ATTACHMENT_CONTACT) { if (resultCode == Activity.RESULT_OK) { Uri uri = data.getData(); if (uri != null) { Uri vcardUri = null; // get lookup key final Cursor c = getContext().getContentResolver().query(uri, new String[] { Contacts.LOOKUP_KEY }, null, null, null); if (c != null) { try { if (c.moveToFirst()) { String lookupKey = c.getString(0); vcardUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey); } } catch (Exception e) { Log.w(TAG, "unable to lookup selected contact. Did you grant me the permission?", e); ReportingManager.logException(e); } finally { c.close(); } } if (vcardUri != null) { sendBinaryMessage(vcardUri, VCardComponent.MIME_TYPE, false, VCardComponent.class); } else { Toast.makeText(getContext(), R.string.err_no_contact, Toast.LENGTH_LONG).show(); } } } } // invite user else if (requestCode == REQUEST_INVITE_USERS) { if (resultCode == Activity.RESULT_OK) { ArrayList<Uri> uris; Uri threadUri = data.getData(); if (threadUri != null) { String userId = threadUri.getLastPathSegment(); addUsers(new String[] { userId }); } else if ((uris = data.getParcelableArrayListExtra("org.kontalk.contacts")) != null) { String[] users = new String[uris.size()]; for (int i = 0; i < users.length; i++) users[i] = uris.get(i).getLastPathSegment(); addUsers(users); } } } }