List of usage examples for android.support.v4.app Fragment startActivityForResult
public void startActivityForResult(Intent intent, int flag)
From source file:com.wanderfar.expander.Settings.SettingsActivity.java
private void requestSystemAlertPermission(Activity context, Fragment fragment, int requestCode) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { setFloatingUIEnabledorDisabled(); } else {/*from w w w . ja v a 2 s. c om*/ final String packageName = context == null ? fragment.getActivity().getPackageName() : context.getPackageName(); final Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + packageName)); if (fragment != null) fragment.startActivityForResult(intent, requestCode); else context.startActivityForResult(intent, requestCode); } }
From source file:com.todoroo.astrid.voice.VoiceInputAssistant.java
/** * Fire an intent to start the speech recognition activity. * This is fired by the listener on the microphone-button. * * @param prompt Specify the R.string.string_id resource for the prompt-text during voice-recognition here *//* w w w . j a va 2 s. co m*/ public void startVoiceRecognitionActivity(Fragment fragment, int prompt) { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, languageModel); intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, ContextManager.getContext().getString(prompt)); String detailMessage = "Error! No Fragment or Activity was registered to handle this voiceinput-request!"; if (activity != null) activity.startActivityForResult(intent, requestCode); else if (fragment != null) fragment.startActivityForResult(intent, requestCode); else Log.e("Astrid VoiceInputAssistant", detailMessage, new IllegalStateException(detailMessage)); }
From source file:com.pdftron.pdf.utils.ViewerUtils.java
public static Uri openImageIntent(Fragment fragment, int requestCode) { // Determine Uri of camera image to save. final String fname = "IMG_" + System.currentTimeMillis() + ".jpg"; File sdImageMainDirectory = new File(fragment.getActivity().getExternalCacheDir(), fname); Uri outputFileUri = Uri.fromFile(sdImageMainDirectory); // Camera./*from w w w.jav a 2 s . c o m*/ final List<Intent> cameraIntents = new ArrayList<>(); final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); final PackageManager packageManager = fragment.getActivity().getPackageManager(); final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0); for (ResolveInfo res : listCam) { final String packageName = res.activityInfo.packageName; final Intent intent = new Intent(captureIntent); intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); intent.setPackage(packageName); intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); cameraIntents.add(intent); } // Filesystem. final Intent galleryIntent = new Intent(Intent.ACTION_PICK); galleryIntent.setType("image/*"); //galleryIntent.setAction(Intent.ACTION_GET_CONTENT); // Chooser of filesystem options. final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source"); // Add the camera options. chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {})); fragment.startActivityForResult(chooserIntent, requestCode); return outputFileUri; }
From source file:com.pizidea.imagepicker.util.AndroidImagePicker.java
/** * take picture//from w w w . j av a 2s .co m */ public void takePicture(Fragment fragment, int requestCode) throws IOException { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //Intent takePictureIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); takePictureIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(fragment.getContext().getPackageManager()) != null) { // Create the File where the photo should go //File photoFile = createImageFile(); File photoFile = createImageSaveFile(fragment.getContext()); // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); Log.i(TAG, "=====file ready to take photo:" + photoFile.getAbsolutePath()); } } fragment.startActivityForResult(takePictureIntent, requestCode); }
From source file:com.lcl6.cn.imagepickerl.AndroidImagePicker.java
/** * take picture/*from w ww . j av a 2s .c om*/ */ public void takePicture(Fragment fragment, int requestCode) throws IOException { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //Intent takePictureIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); takePictureIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(fragment.getContext().getPackageManager()) != null) { // Create the File where the photo should go //File photoFile = createImageFile(); File photoFile = createImageSaveFile(fragment.getContext()); // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); Log.i(TAG, "=====file ready to take photo:" + photoFile.getAbsolutePath()); } } fragment.startActivityForResult(takePictureIntent, requestCode); }
From source file:com.groundupworks.wings.facebook.FacebookEndpoint.java
/** * Requests for permissions to publish publicly. Requires an opened active {@link Session}. * * @param activity the {@link Activity}. * @param fragment the {@link Fragment}. May be null. * @return true if the request is made; false if no opened {@link Session} is active. *//*from ww w . jav a 2 s . c o m*/ private boolean startSettingsRequest(Activity activity, Fragment fragment) { boolean isSuccessful = false; // State transition. mLinkRequestState = STATE_SETTINGS_REQUEST; Session session = Session.getActiveSession(); if (session != null && session.isOpened()) { // Start activity for result. Intent intent = new Intent(activity, FacebookSettingsActivity.class); if (fragment == null) { activity.startActivityForResult(intent, SETTINGS_REQUEST_CODE); } else { fragment.startActivityForResult(intent, SETTINGS_REQUEST_CODE); } isSuccessful = true; } return isSuccessful; }
From source file:com.pizidea.imagepicker.AndroidImagePicker.java
/** * take picture//from w w w . j av a2 s . co m */ public void takePicture(Fragment fragment, int requestCode) throws IOException { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //Intent takePictureIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); takePictureIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(fragment.getActivity().getPackageManager()) != null) { // Create the File where the photo should go //File photoFile = createImageFile(); File photoFile = createImageSaveFile(fragment.getActivity()); // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); Log.i(TAG, "=====file ready to take photo:" + photoFile.getAbsolutePath()); } } fragment.startActivityForResult(takePictureIntent, requestCode); }
From source file:com.kaichaohulian.baocms.ecdemo.ui.chatting.ChattingFragment.java
/** * ??//from www.j av a2s. com * * @param fragment * @param jsonObject * @param requestCode */ public static void startRedPacketActivityForResult(Fragment fragment, com.alibaba.fastjson.JSONObject jsonObject, int requestCode) { RedPacketInfo redPacketInfo = new RedPacketInfo(); redPacketInfo.fromAvatarUrl = jsonObject.getString(RedPacketConstant.KEY_FROM_AVATAR_URL); Intent intent = new Intent(fragment.getActivity(), SendingRedBagActivity.class); redPacketInfo.fromNickName = jsonObject.getString(RedPacketConstant.KEY_FROM_NICK_NAME); //IdId int chatType = jsonObject.getInteger(RedPacketConstant.KEY_CHAT_TYPE); if (chatType == 1) { redPacketInfo.toUserId = jsonObject.getString(RedPacketConstant.KEY_USER_ID); redPacketInfo.chatType = 1; intent.putExtra("type", 0); intent.putExtra("isGroup", "0"); } else if (chatType == 2) { redPacketInfo.toGroupId = jsonObject.getString(RedPacketConstant.KEY_GROUP_ID); redPacketInfo.groupMemberCount = jsonObject.getInteger(RedPacketConstant.KEY_GROUP_MEMBERS_COUNT); redPacketInfo.chatType = 2; intent.putExtra("type", 1); intent.putExtra("isGroup", "1"); intent.putExtra(RedPacketConstant.KEY_GROUP_ID, redPacketInfo.toGroupId); } intent.putExtra("fromchat", true); intent.putExtra(RPConstant.EXTRA_RED_PACKET_INFO, redPacketInfo); fragment.startActivityForResult(intent, requestCode); }
From source file:org.getlantern.firetweet.util.Utils.java
public static boolean handleMenuItemClick(Context context, Fragment fragment, FragmentManager fm, AsyncTwitterWrapper twitter, ParcelableStatus status, MenuItem item) { switch (item.getItemId()) { case MENU_COPY: { if (ClipboardUtils.setText(context, status.text_plain)) { showOkMessage(context, R.string.text_copied, false); }/*from www . j a v a 2s . c o m*/ break; } case MENU_RETWEET: { if (isMyRetweet(status)) { twitter.cancelRetweetAsync(status.account_id, status.id, status.my_retweet_id); } else { twitter.retweetStatusAsync(status.account_id, status.id); } break; } case MENU_QUOTE: { final Intent intent = new Intent(INTENT_ACTION_QUOTE); intent.putExtra(EXTRA_STATUS, status); context.startActivity(intent); break; } case MENU_REPLY: { final Intent intent = new Intent(INTENT_ACTION_REPLY); intent.putExtra(EXTRA_STATUS, status); context.startActivity(intent); break; } case MENU_FAVORITE: { if (status.is_favorite) { twitter.destroyFavoriteAsync(status.account_id, status.id); } else { twitter.createFavoriteAsync(status.account_id, status.id); } break; } case MENU_DELETE: { DestroyStatusDialogFragment.show(fm, status); break; } case MENU_ADD_TO_FILTER: { AddStatusFilterDialogFragment.show(fm, status); break; } case MENU_SET_COLOR: { final Intent intent = new Intent(context, ColorPickerDialogActivity.class); final int color = getUserColor(context, status.user_id, true); if (color != 0) { intent.putExtra(EXTRA_COLOR, color); } intent.putExtra(EXTRA_CLEAR_BUTTON, color != 0); intent.putExtra(EXTRA_ALPHA_SLIDER, false); if (fragment != null) { fragment.startActivityForResult(intent, REQUEST_SET_COLOR); } else if (context instanceof Activity) { ((Activity) context).startActivityForResult(intent, REQUEST_SET_COLOR); } break; } case MENU_CLEAR_NICKNAME: { clearUserNickname(context, status.user_id); break; } case MENU_SET_NICKNAME: { final String nick = getUserNickname(context, status.user_id, true); SetUserNicknameDialogFragment.show(fm, status.user_id, nick); break; } case MENU_TRANSLATE: { final ParcelableCredentials account = ParcelableAccount.getCredentials(context, status.account_id); if (isOfficialCredentials(context, account)) { StatusTranslateDialogFragment.show(fm, status); } else { final Resources resources = context.getResources(); final Locale locale = resources.getConfiguration().locale; try { final String template = "http://translate.google.com/#%s|%s|%s"; final String sourceLang = "auto"; final String targetLang = URLEncoder.encode(locale.getLanguage(), HTTP.UTF_8); final String text = URLEncoder.encode(status.text_unescaped, HTTP.UTF_8); final Uri uri = Uri.parse(String.format(Locale.ROOT, template, sourceLang, targetLang, text)); final Intent intent = new Intent(Intent.ACTION_VIEW, uri); intent.addCategory(Intent.CATEGORY_BROWSABLE); context.startActivity(intent); } catch (UnsupportedEncodingException ignore) { } } break; } case MENU_OPEN_WITH_ACCOUNT: { final Intent intent = new Intent(INTENT_ACTION_SELECT_ACCOUNT); intent.setClass(context, AccountSelectorActivity.class); intent.putExtra(EXTRA_SINGLE_SELECTION, true); if (fragment != null) { fragment.startActivityForResult(intent, REQUEST_SELECT_ACCOUNT); } else if (context instanceof Activity) { ((Activity) context).startActivityForResult(intent, REQUEST_SELECT_ACCOUNT); } break; } default: { if (item.getIntent() != null) { try { context.startActivity(item.getIntent()); } catch (final ActivityNotFoundException e) { Crashlytics.logException(e); Log.w(LOGTAG, e); return false; } } break; } } return true; }