List of usage examples for android.app Activity startActivityForResult
public void startActivityForResult(@RequiresPermission Intent intent, int requestCode)
From source file:com.todoroo.astrid.actfm.ActFmCameraModule.java
public static void showPictureLauncher(final Activity activity, final ClearImageCallback clearImageOption) { ArrayList<String> options = new ArrayList<String>(); final Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); PackageManager pm = activity.getPackageManager(); final boolean cameraAvailable = pm.queryIntentActivities(cameraIntent, 0).size() > 0; if (cameraAvailable) options.add(activity.getString(R.string.actfm_picture_camera)); options.add(activity.getString(R.string.actfm_picture_gallery)); if (clearImageOption != null) options.add(activity.getString(R.string.actfm_picture_clear)); ArrayAdapter<String> adapter = new ArrayAdapter<String>(activity, android.R.layout.simple_spinner_dropdown_item, options.toArray(new String[options.size()])); DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { @SuppressWarnings("nls") @Override//from w ww . j av a 2s . c o m public void onClick(DialogInterface d, int which) { if (which == 0 && cameraAvailable) { lastTempFile = getTempFile(activity); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (lastTempFile != null) { intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(lastTempFile)); } activity.startActivityForResult(intent, REQUEST_CODE_CAMERA); } else if ((which == 1 && cameraAvailable) || (which == 0 && !cameraAvailable)) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); activity.startActivityForResult( Intent.createChooser(intent, activity.getString(R.string.actfm_TVA_tag_picture)), REQUEST_CODE_PICTURE); } else { if (clearImageOption != null) clearImageOption.clearImage(); } } }; // show a menu of available options new AlertDialog.Builder(activity).setAdapter(adapter, listener).show().setOwnerActivity(activity); }
From source file:com.frostwire.android.gui.util.DangerousPermissionsChecker.java
/** * This method will invoke an activity that shows the WRITE_SETTINGS capabilities * of our app./*from w w w . j a va 2s. c o m*/ * * More unnecessary distractions and time wasting for developers * courtesy of Google. * * https://commonsware.com/blog/2015/08/17/random-musings-android-6p0-sdk.html * * > Several interesting new Settings screens are now accessible * > via Settings action strings. One that will get a lot of * > attention is ACTION_MANAGE_WRITE_SETTINGS, where users can indicate * > whether apps can write to system settings or not. * > If your app requests the WRITE_SETTINGS permission, you may appear * > on this list, and you can call canWrite() on Settings.System to * > see if you were granted permission. * * Google geniuses, Make up your minds please. */ private void requestWriteSettingsPermissionsAPILevel23(Activity activity) { // Settings.ACTION_MANAGE_WRITE_SETTINGS - won't build if the // intellij sdk is set to API 16 Platform, so I'll just hardcode // the value. // Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS); Intent intent = new Intent("android.settings.action.MANAGE_WRITE_SETTINGS"); intent.setData(Uri.parse("package:" + activity.getPackageName())); activity.startActivityForResult(intent, DangerousPermissionsChecker.WRITE_SETTINGS_PERMISSIONS_REQUEST_CODE); }
From source file:io.nuclei.cyto.share.PackageTargetManager.java
/** * Send the startActivityForResult intent to an activity * * @param requestCode The request code to listen to in the onActivityResult *///w ww. ja v a 2 s .c o m public void onShare(Activity activity, Intent intent, int requestCode) { if (mWeights == null) mWeights = activity.getSharedPreferences(DEFAULT_SHARE_WEIGHTS, Context.MODE_PRIVATE); int weight = mWeights.getInt(intent.getComponent().getClassName(), 0) + 1; mWeights.edit().putInt(intent.getComponent().getClassName(), weight).apply(); activity.startActivityForResult(intent, requestCode); }
From source file:com.android.messaging.ui.UIIntentsImpl.java
@Override public void launchPeopleAndOptionsActivity(final Activity activity, final String conversationId) { final Intent intent = new Intent(activity, PeopleAndOptionsActivity.class); intent.putExtra(UI_INTENT_EXTRA_CONVERSATION_ID, conversationId); activity.startActivityForResult(intent, 0); }
From source file:com.microsoft.rightsmanagement.ui.UserPolicyViewerActivity.java
/** * Show UI./*from w w w. j av a 2s . c om*/ * * @param requestCode the request code for startActivityForResult * @param parentActivity the parent activity that invokes startActivityForResult * @param userPolicy user policy instance that provides data to display on the UI * @param supportedRights rights to check access for and display * @param policyViewerActivityRequestOption PolicyViewerActivityRequestOptions * @param policyViewerActivityCompletionCallback callback that's invoked upon completion of activity. * @throws InvalidParameterException the invalid parameter exception */ public static void show(int requestCode, Activity parentActivity, UserPolicy userPolicy, LinkedHashSet<String> supportedRights, int policyViewerActivityRequestOption, CompletionCallback<Integer> policyViewerActivityCompletionCallback) { Logger.ms(TAG, "show"); parentActivity = validateActivityInputParameter(parentActivity); userPolicy = validateUserPolicyInputParameter(userPolicy); policyViewerActivityCompletionCallback = validateCompletionCallbackInputParameter( policyViewerActivityCompletionCallback); policyViewerActivityRequestOption = validatePolicyViewerActivityRequestOption( policyViewerActivityRequestOption); // put callback int requestCallbackId = policyViewerActivityCompletionCallback.hashCode(); sCallbackManager.putWaitingRequest(requestCallbackId, policyViewerActivityCompletionCallback); // set launch intent Intent intent = new Intent(parentActivity, UserPolicyViewerActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(REQUEST_CALLBACK_ID, requestCallbackId); intent.putExtra(REQUEST_RESULT_POLICY_VIEWER_OPTIONS, policyViewerActivityRequestOption); intent.putExtra(REQUEST_RESULT_USER_POLICY_MODEL, (new UserPolicyModel(userPolicy, supportedRights, parentActivity.getApplicationContext()))); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); parentActivity.startActivityForResult(intent, requestCode); Logger.me(TAG, "show"); }
From source file:com.android.messaging.ui.UIIntentsImpl.java
@Override public void launchAttachmentChooserActivity(final Activity activity, final String conversationId, final int requestCode) { final Intent intent = new Intent(activity, AttachmentChooserActivity.class); intent.putExtra(UI_INTENT_EXTRA_CONVERSATION_ID, conversationId); activity.startActivityForResult(intent, requestCode); }
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 ww .j a v a 2 s . co m 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:org.totschnig.myexpenses.dialog.TransactionDetailFragment.java
@Override public void onClick(DialogInterface dialog, int which) { Activity ctx = getActivity(); if (ctx == null || mTransaction == null) { return;//ww w . j a v a 2 s.c o m } switch (which) { case AlertDialog.BUTTON_POSITIVE: if (mTransaction.transfer_peer != null && DbUtils.hasParent(mTransaction.transfer_peer)) { Toast.makeText(ctx, getString(R.string.warning_splitpartcategory_context), Toast.LENGTH_LONG) .show(); return; } Intent i = new Intent(ctx, ExpenseEdit.class); i.putExtra(KEY_ROWID, mTransaction.getId()); //i.putExtra("operationType", operationType); ctx.startActivityForResult(i, ProtectedFragmentActivity.EDIT_TRANSACTION_REQUEST); break; case AlertDialog.BUTTON_NEUTRAL: startActivity(Transaction.getViewIntent(mTransaction.getPictureUri())); break; case AlertDialog.BUTTON_NEGATIVE: dismiss(); } }
From source file:io.digibyte.tools.animation.BRAnimator.java
public static void openScanner(Activity app, int requestID) { try {/*from w w w . ja v a2 s . co m*/ if (app == null) return; // Check if the camera permission is granted if (ContextCompat.checkSelfPermission(app, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(app, Manifest.permission.CAMERA)) { BRDialog.showCustomDialog(app, app.getString(R.string.Send_cameraUnavailabeTitle_android), app.getString(R.string.Send_cameraUnavailabeMessage_android), app.getString(R.string.AccessibilityLabels_close), null, new BRDialogView.BROnClickListener() { @Override public void onClick(BRDialogView brDialogView) { brDialogView.dismiss(); } }, null, null, 0); } else { // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(app, new String[] { Manifest.permission.CAMERA }, BRConstants.CAMERA_REQUEST_ID); } } else { // Permission is granted, open camera Intent intent = new Intent(app, ScanQRActivity.class); app.startActivityForResult(intent, requestID); app.overridePendingTransition(R.anim.fade_up, R.anim.fade_down); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.deltadna.android.sdk.ImageMessage.java
/** * Opens the {@link ImageMessageActivity} for showing this Image Message. * * @param activity the {@link Activity} from which the request is * being started// w w w. j a v a 2 s .c o m * @param requestCode the request code that will be used in * {@link Activity#onActivityResult(int, int, Intent)} * for the result * * @throws IllegalStateException if the Image Message is not prepared */ public void show(Activity activity, int requestCode) { if (!prepared) throw new IllegalStateException("image message has not been prepared yet"); activity.startActivityForResult(ImageMessageActivity.createIntent(activity, this), requestCode); }