List of usage examples for android.app Activity startActivityForResult
public void startActivityForResult(@RequiresPermission Intent intent, int requestCode)
From source file:com.salmannazir.filemanager.businesslogic.EventHandler.java
private void showNewImageCreateDialog(final Activity mContext, final String directory) { boolean wrapInScrollView = true; new MaterialDialog.Builder(mContext).title("Create New Image File") .customView(R.layout.new_image_layout, wrapInScrollView).positiveText("Capture Image") .negativeText("Cancel").onPositive(new MaterialDialog.SingleButtonCallback() { @Override//from w ww .j av a2s.co m public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { // TODO Toast.makeText(mContext, "+ve Clicked", Toast.LENGTH_SHORT).show(); Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (cameraIntent.resolveActivity(mContext.getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { EditText imageNameEditText = (EditText) dialog.findViewById(R.id.image_name); photoFile = createImageFile(imageNameEditText.getText().toString(), directory); } catch (IOException ex) { // Error occurred while creating the File Log.i("MainActivity", "IOException"); } // Continue only if the File was successfully created if (photoFile != null) { cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); mContext.startActivityForResult(cameraIntent, Constants.CAMERA_REQUEST); } } } }).show(); }
From source file:com.android.mms.ui.MessageUtils.java
public static void capturePicture(Activity activity, int requestCode) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, TempFileProvider.SCRAP_CONTENT_URI); activity.startActivityForResult(intent, requestCode); }
From source file:com.android.mms.ui.MessageUtils.java
public static void recordSound(Activity activity, int requestCode, long sizeLimit) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType(MmsContentType.AUDIO_AMR); intent.setClassName("com.android.soundrecorder", "com.android.soundrecorder.SoundRecorder"); intent.putExtra(android.provider.MediaStore.Audio.Media.EXTRA_MAX_BYTES, sizeLimit); activity.startActivityForResult(intent, requestCode); }
From source file:jp.mixi.android.sdk.MixiContainerImpl.java
@Override public void logout(final Activity activity, int activityCode, final CallbackListener listener) { mRevokeCode = activityCode;//from ww w . j a v a 2 s . com // ?????????????????? mRevokeCallbackListener = new CallbackListener() { @Override public void onFatal(ErrorInfo e) { listener.onFatal(e); } @Override public void onError(ErrorInfo e) { listener.onError(e); } @Override public void onComplete(Bundle values) { deleteSession(activity); listener.onComplete(values); } @Override public void onCancel() { listener.onCancel(); } }; Map<String, String> param = new HashMap<String, String>(); param.put(CLIENT_ID, mClientId); String refreshToken = getRefreshToken(); if (refreshToken == null) { mRevokeCallbackListener.onFatal(new ErrorInfo("not authorized", ErrorInfo.REVOKE_AUTHORIZE)); return; } param.put("token", refreshToken); Intent intent = new Intent(); intent.putExtra("mode", "revoke"); intent.setClassName(OFFICIAL_PACKAGE, AUTH_ACTIVITY); intent.putExtra(CLIENT_ID, mClientId); intent.putExtra(REFRESH_TOKEN, refreshToken); if (!validateOfficialAppsForIntent(activity, intent, VALIDATE_OFFICIAL_FOR_ACTIVITY, SUPPORTED_VERSION)) { mRevokeCallbackListener .onFatal(new ErrorInfo("official application not found", ErrorInfo.OFFICIAL_APP_NOT_FOUND)); return; } try { activity.startActivityForResult(intent, activityCode); } catch (ActivityNotFoundException e) { Log.e(TAG, e.getMessage(), e); mRevokeCallbackListener.onFatal(new ErrorInfo(e)); } }
From source file:com.android.mms.ui.MessageUtils.java
public static void selectAudio(Activity activity, int requestCode) { // / M: Code analyze 027, new feature, to improve the performance of // Mms. @{//from w ww. j a v a 2s . c o m Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType(MmsContentType.AUDIO_UNSPECIFIED); String[] mimeTypess = new String[] { MmsContentType.AUDIO_UNSPECIFIED, MmsContentType.AUDIO_OGG, "application/x-ogg" }; intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypess); if (FeatureOption.MTK_DRM_APP) { intent.putExtra(OmaDrmStore.DrmIntentExtra.EXTRA_DRM_LEVEL, OmaDrmStore.DrmIntentExtra.LEVEL_SD); } /// @} activity.startActivityForResult(intent, requestCode); }
From source file:com.android.gallery3d.app.PhotoPage.java
public void playVideo(Activity activity, Uri uri, String title) { try {/* w w w.j a va 2s . c o m*/ Intent intent = new Intent(Intent.ACTION_VIEW).setDataAndType(uri, "video/*") .putExtra(Intent.EXTRA_TITLE, title).putExtra(MovieActivity.KEY_TREAT_UP_AS_BACK, true) /// M: [BUG.ADD] @{ .putExtra(MovieActivity.KEY_COME_FROM_CAMERA, mAppBridge != null); intent.putExtra(FeatureHelper.EXTRA_ENABLE_VIDEO_LIST, true); /// @} activity.startActivityForResult(intent, REQUEST_PLAY_VIDEO); } catch (ActivityNotFoundException e) { Toast.makeText(activity, activity.getString(R.string.video_err), Toast.LENGTH_SHORT).show(); } }
From source file:com.android.gallery3d.app.PhotoPage.java
@Override protected boolean onItemSelected(MenuItem item) { if (mModel == null) return true; refreshHidingMessage();/*from w w w.j a va 2 s . co m*/ MediaItem current = mModel.getMediaItem(0); // This is a shield for monkey when it clicks the action bar // menu when transitioning from filmstrip to camera if (current instanceof SnailItem) return true; // TODO: We should check the current photo against the MediaItem // that the menu was initially created for. We need to fix this // after PhotoPage being refactored. if (current == null) { // item is not ready, ignore return true; } int currentIndex = mModel.getCurrentIndex(); Path path = current.getPath(); DataManager manager = mActivity.getDataManager(); int action = item.getItemId(); /// M: [BUG.ADD] show toast before PhotoDataAdapter finishing loading to avoid JE @{ if (action != android.R.id.home && !mLoadingFinished && mSetPathString != null) { Toast.makeText(mActivity, mActivity.getString(R.string.please_wait), Toast.LENGTH_SHORT).show(); return true; } /// @} String confirmMsg = null; switch (action) { case android.R.id.home: { onUpPressed(); return true; } case R.id.action_slideshow: { Bundle data = new Bundle(); /// M: [BUG.MODIFY] fix bug: slideshow doesn't play again // when finish playing the last picture @{ String mediaSetPath = mMediaSet.getPath().toString(); if (mSnailSetPath != null) { mediaSetPath = mediaSetPath.replace(mSnailSetPath + ",", ""); Log.i(TAG, "<onItemSelected> action_slideshow | mediaSetPath: " + mediaSetPath); } /*data.putString(SlideshowPage.KEY_SET_PATH, mMediaSet.getPath().toString());*/ data.putString(SlideshowPage.KEY_SET_PATH, mediaSetPath); /// @} data.putString(SlideshowPage.KEY_ITEM_PATH, path.toString()); /// M: [BUG.ADD] currentIndex-- if it is in camera folder @{ if (mHasCameraScreennailOrPlaceholder) { currentIndex--; } /// @} data.putInt(SlideshowPage.KEY_PHOTO_INDEX, currentIndex); data.putBoolean(SlideshowPage.KEY_REPEAT, true); mActivity.getStateManager().startStateForResult(SlideshowPage.class, REQUEST_SLIDESHOW, data); return true; } case R.id.action_crop: { /// M: [BUG.ADD] disable cropping photo when file not exists or sdcard is full. @{ File srcFile = new File(current.getFilePath()); if (!srcFile.exists()) { Log.i(TAG, "<onItemSelected> abort cropping photo when not exists!"); return true; } if (!isSpaceEnough(srcFile)) { Log.i(TAG, "<onItemSelected> abort cropping photo when no enough space!"); Toast.makeText(mActivity, mActivity.getString(R.string.storage_not_enough), Toast.LENGTH_SHORT) .show(); return true; } /// @} Activity activity = mActivity; Intent intent = new Intent(CropActivity.CROP_ACTION); intent.setClass(activity, CropActivity.class); intent.setDataAndType(manager.getContentUri(path), current.getMimeType()) .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); activity.startActivityForResult(intent, PicasaSource.isPicasaImage(current) ? REQUEST_CROP_PICASA : REQUEST_CROP); return true; } case R.id.action_trim: { Intent intent = new Intent(mActivity, TrimVideo.class); intent.setData(manager.getContentUri(path)); // We need the file path to wrap this into a RandomAccessFile. intent.putExtra(KEY_MEDIA_ITEM_PATH, current.getFilePath()); /// M: [FEATURE.ADD] SlideVideo@{ if (FeatureConfig.SUPPORT_SLIDE_VIDEO_PLAY) { intent.putExtra(TrimVideo.KEY_COME_FROM_GALLERY, true); } /// @} mActivity.startActivityForResult(intent, REQUEST_TRIM); return true; } case R.id.action_mute: { /// M: [BUG.ADD] disable muting video when file not exists or sdcard is full. @{ File srcFile = new File(current.getFilePath()); if (!srcFile.exists()) { Log.i(TAG, "<onItemSelected> abort muting video when not exists!"); return true; } if (!isSpaceEnough(srcFile)) { Log.i(TAG, "<onItemSelected> abort muting video when no enough space!"); Toast.makeText(mActivity, mActivity.getString(R.string.storage_not_enough), Toast.LENGTH_SHORT) .show(); return true; } /// @} mMuteVideo = new MuteVideo(current.getFilePath(), manager.getContentUri(path), mActivity); mMuteVideo.muteInBackground(); /// M: [FEATURE.ADD] SlideVideo@{ mMuteVideo.setMuteDoneListener(new MuteDoneListener() { public void onMuteDone(Uri uri) { redirectCurrentMedia(uri, false); } }); /// @} return true; } case R.id.action_edit: { /// M: [BUG.ADD] disable editing photo when file not exists or sdcard is full. @{ File srcFile = new File(current.getFilePath()); if (!srcFile.exists()) { Log.i(TAG, "<onItemSelected> abort editing photo when not exists!"); return true; } if (!isSpaceEnough(srcFile)) { Log.i(TAG, "<onItemSelected> abort editing photo when no enough space!"); Toast.makeText(mActivity, mActivity.getString(R.string.storage_not_enough), Toast.LENGTH_SHORT) .show(); return true; } /// @} launchPhotoEditor(); return true; } /// M: [FEATURE.ADD] @{ case R.id.m_action_picture_quality: { Activity activity = (Activity) mActivity; Intent intent = new Intent(PictureQualityActivity.ACTION_PQ); intent.setClass(activity, PictureQualityActivity.class); intent.setData(manager.getContentUri(path)); Bundle pqBundle = new Bundle(); pqBundle.putString("PQUri", manager.getContentUri(path).toString()); pqBundle.putString("PQMineType", current.getMimeType()); pqBundle.putInt("PQViewWidth", mPhotoView.getWidth()); pqBundle.putInt("PQViewHeight", mPhotoView.getHeight()); intent.putExtras(pqBundle); Log.i(TAG, "<onItemSelected>startActivity PQ"); activity.startActivityForResult(intent, REQUEST_PQ); return true; } case R.id.m_action_image_dc: { ImageDC.resetStatus((Context) mActivity); ImageDC.setMenuItemTile(item); path.clearObject(); mActivity.getDataManager().forceRefreshAll(); Log.d(TAG, "< onStateResult > forceRefreshAll~~"); return true; } /// @} case R.id.action_simple_edit: { launchSimpleEditor(); return true; } case R.id.action_details: { if (mShowDetails) { hideDetails(); } else { showDetails(); } return true; } case R.id.print: { mActivity.printSelectedImage(manager.getContentUri(path)); return true; } case R.id.action_delete: confirmMsg = mActivity.getResources().getQuantityString(R.plurals.delete_selection, 1); case R.id.action_setas: case R.id.action_rotate_ccw: case R.id.action_rotate_cw: case R.id.action_show_on_map: mSelectionManager.deSelectAll(); mSelectionManager.toggle(path); mMenuExecutor.onMenuClicked(item, confirmMsg, mConfirmDialogListener); return true; /// M: [FEATURE.ADD] DRM & HotKnot @{ case R.id.m_action_protect_info: Log.d(TAG, "<onItemSelected> ProtectionInfo: do action_protection_info"); DrmHelper.showProtectionInfoDialog((Activity) mActivity, manager.getContentUri(path)); return true; case R.id.action_hotknot: Log.d(TAG, "<onItemSelected> HotKnot: do action_hotknot"); // for continuous shot, may share a group image, so getContentUris() Uri[] uris = null; ExtItem extItem = mCurrentPhoto.getExtItem(); if (extItem != null) { uris = extItem.getContentUris(); } if (uris != null) { mActivity.getHotKnot().sendZip(uris); } else { extHotKnot(); } return true; /// @} /// M: [FEATURE.ADD] entry to export as video @{ case R.id.action_export: mAnimatedContentSharer.exportCurrentPhoto(); return true; /// @} /// M: [FEATURE.ADD] Support BlueTooth print feature.@{ case R.id.action_print: mSelectionManager.deSelectAll(); mSelectionManager.toggle(path); mMenuExecutor.onMenuClicked(item, confirmMsg, mConfirmDialogListener); return true; /// @} default: /// M: [FEATURE.ADD] menu extension @{ // return false; return mPhotoView.onOptionsItemSelected(item); /// @} } }
From source file:com.android.mms.ui.MessageUtils.java
public static void recordVideo(Activity activity, int requestCode, long sizeLimit) { // The video recorder can sometimes return a file that's larger than the max we // say we can handle. Try to handle that overshoot by specifying an 85% limit. /// M: media recoder can handle this issue,so mark it. // sizeLimit *= .85F; int durationLimit = getVideoCaptureDurationLimit(); if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) { log("recordVideo: durationLimit: " + durationLimit + " sizeLimit: " + sizeLimit); }// www.j av a 2 s.com Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0); intent.putExtra("android.intent.extra.sizeLimit", sizeLimit); intent.putExtra("android.intent.extra.durationLimit", durationLimit); /// M: Code analyze 009, For fix bug ALPS00241707, You can not add // capture video to Messaging after you preview it in Gallery. @{ intent.putExtra(MediaStore.EXTRA_OUTPUT, TempFileProvider.SCRAP_VIDEO_URI); /// M: fix bug ALPS01043585 intent.putExtra("CanShare", false); activity.startActivityForResult(intent, requestCode); }
From source file:com.android.mms.ui.MessageUtils.java
public static void addNumberOrEmailtoContact(final String numberOrEmail, final int REQUEST_CODE, final Activity activity) { if (!TextUtils.isEmpty(numberOrEmail)) { String message = activity.getResources().getString(R.string.add_contact_dialog_message, numberOrEmail); AlertDialog.Builder builder = new AlertDialog.Builder(activity).setTitle(numberOrEmail) .setMessage(message);/*from w w w .j a va 2s . c o m*/ AlertDialog dialog = builder.create(); dialog.setButton(AlertDialog.BUTTON_POSITIVE, activity.getResources().getString(R.string.add_contact_dialog_existing), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); intent.setType(Contacts.CONTENT_ITEM_TYPE); if (Mms.isEmailAddress(numberOrEmail)) { intent.putExtra(ContactsContract.Intents.Insert.EMAIL, numberOrEmail); } else { intent.putExtra(ContactsContract.Intents.Insert.PHONE, numberOrEmail); } if (REQUEST_CODE > 0) { activity.startActivityForResult(intent, REQUEST_CODE); } else { activity.startActivity(intent); } } }); dialog.setButton(AlertDialog.BUTTON_NEGATIVE, activity.getResources().getString(R.string.add_contact_dialog_new), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub final Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI); if (Mms.isEmailAddress(numberOrEmail)) { intent.putExtra(ContactsContract.Intents.Insert.EMAIL, numberOrEmail); } else { intent.putExtra(ContactsContract.Intents.Insert.PHONE, numberOrEmail); } if (REQUEST_CODE > 0) { activity.startActivityForResult(intent, REQUEST_CODE); } else { activity.startActivity(intent); } } }); dialog.show(); } }
From source file:com.android.mms.ui.MessageUtils.java
public static void viewMmsMessageAttachment(final Activity activity, final Uri msgUri, final SlideshowModel slideshow, final int requestCode, AsyncDialog asyncDialog) { /// M: Code analyze 002, For fix bug ALPS00112553, system-server JE // happens and MS reboot when tap play in MMS. @{ final boolean isSimple = (slideshow == null) ? false : slideshow.isSimple(); if (isSimple) { SlideModel slideTemp = slideshow.get(0); // In attachment-editor mode, we only ever have one slide. /// M: fix bug ALPS00393187, play in gellay when simple slide only has picture or video if (slideTemp != null && !slideTemp.hasAudio() && (!slideTemp.hasText() || slideTemp.getText().getText().length() == 0)) { MessageUtils.viewSimpleSlideshow(activity, slideshow); return; }//from www. j a v a 2s. co m } /// @} // M: change feature ALPS01751464 if (isSimple) { SlideModel slideOne = slideshow.get(0); if (slideOne != null && slideOne.hasAudio()) { MediaModel model = slideOne.getAudio(); if (model != null && model.hasDrmContent()) { DrmUtilsEx.showDrmAlertDialog(activity); return; } } } // The user wants to view the slideshow. We have to persist the slideshow parts // in a background task. If the task takes longer than a half second, a progress dialog // is displayed. Once the PDU persisting is done, another runnable on the UI thread get // executed to start the SlideshowActivity. asyncDialog.runAsync(new Runnable() { @Override public void run() { // If a slideshow was provided, save it to disk first. if (slideshow != null) { PduPersister persister = PduPersister.getPduPersister(activity); try { PduBody pb = slideshow.toPduBody(); MessageUtils.updatePartsIfNeeded(slideshow, persister, msgUri, pb, null); //persister.updateParts(msgUri, pb, null); slideshow.sync(pb); } catch (MmsException e) { Log.e(TAG, "Unable to save message for preview"); return; } slide = slideshow.get(0); } } }, new Runnable() { @Override public void run() { // Launch the slideshow activity to play/view. Intent intent; if ((isSimple && slide.hasAudio()) || (requestCode == AttachmentEditor.MSG_PLAY_AUDIO)) { intent = new Intent(activity.getApplicationContext(), SlideshowActivity.class); } else { intent = new Intent(activity.getApplicationContext(), MmsPlayerActivity.class); } intent.setData(msgUri); if (requestCode > 0) { activity.startActivityForResult(intent, requestCode); } else { activity.startActivity(intent); } // // Once the above background thread is complete, this runnable is run // // on the UI thread to launch the slideshow activity. // launchSlideshowActivity(activity, msgUri, requestCode); } }, R.string.building_slideshow_title); }