List of usage examples for android.app Activity startActivityForResult
public void startActivityForResult(@RequiresPermission Intent intent, int requestCode)
From source file:com.android.launcher3.Utilities.java
public static void startActivityForResultSafely(Activity activity, Intent intent, int requestCode) { try {/*from ww w.j ava 2s . c om*/ activity.startActivityForResult(intent, requestCode); } catch (ActivityNotFoundException e) { Toast.makeText(activity, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); } catch (SecurityException e) { Toast.makeText(activity, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); Log.e(TAG, "Launcher does not have the permission to launch " + intent + ". Make sure to create a MAIN intent-filter for the corresponding activity " + "or use the exported attribute for this activity.", e); } }
From source file:org.totschnig.myexpenses.dialog.ExportDialogFragment.java
@Override public void onClick(DialogInterface dialog, int which) { Bundle args = getArguments();/* www .j a v a2s . c o m*/ Long accountId = args != null ? args.getLong("accountId") : null; Intent i; Activity ctx = getActivity(); AlertDialog dlg = (AlertDialog) dialog; String format = ((RadioGroup) dlg.findViewById(R.id.format)).getCheckedRadioButtonId() == R.id.csv ? "CSV" : "QIF"; String dateFormat = ((EditText) dlg.findViewById(R.id.date_format)).getText().toString(); MyApplication.getInstance().getSettings().edit().putString(MyApplication.PREFKEY_EXPORT_FORMAT, format) .putString(PREFKEY_EXPORT_DATE_FORMAT, dateFormat).commit(); boolean deleteP = ((CheckBox) dlg.findViewById(R.id.export_delete)).isChecked(); boolean notYetExportedP = ((CheckBox) dlg.findViewById(R.id.export_not_yet_exported)).isChecked(); if (Utils.isExternalStorageAvailable()) { if (accountId == null) Feature.RESET_ALL.recordUsage(); i = new Intent(ctx, Export.class).putExtra(KEY_ROWID, accountId).putExtra("format", format) .putExtra("deleteP", deleteP).putExtra("notYetExportedP", notYetExportedP) .putExtra("dateFormat", dateFormat); ctx.startActivityForResult(i, 0); } else { Toast.makeText(ctx, ctx.getString(R.string.external_storage_unavailable), Toast.LENGTH_LONG).show(); } }
From source file:cx.ring.client.HomeActivity.java
private AlertDialog createAccountDialog() { final Activity ownerActivity = this; AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity); builder.setMessage(getResources().getString(R.string.create_new_account_dialog)) .setTitle(getResources().getString(R.string.create_new_account_dialog_title)).setPositiveButton( getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Intent in = new Intent(); in.setClass(ownerActivity, AccountWizard.class); ownerActivity.startActivityForResult(in, HomeActivity.REQUEST_CODE_PREFERENCES); }/*from ww w. j av a 2 s . c o m*/ }) .setNegativeButton(getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }); AlertDialog alertDialog = builder.create(); alertDialog.setOwnerActivity(ownerActivity); return alertDialog; }
From source file:com.etalio.android.EtalioBase.java
/** * Redirects the end user to Etalio sign in. Sign in will happen through the * Etalio app if installed, else through the web browser. * * <code>mEtalio.initiateEtalioSignIn(this, "profile.basic.r profile.email.r");</code> * * @param activity the activity used to call Etalio sign in. * @param scope scopes for the sign in. The scopes should be separated by spaces, like "profile.basic.r profile.email.r" *///w w w . j ava 2s. com public void initiateEtalioSignIn(Activity activity, String scope) { resetState(); if (!isEtalioInstalled(activity)) { activity.startActivity(new Intent(Intent.ACTION_VIEW, getSignInUrl(scope))); } else { Intent etalio = new Intent(); etalio.setClassName("com.etalio.android", "com.etalio.android.app.ui.activity.SingleSignOnActivity"); etalio.putExtra(EXTRA_CLIENT_ID, mClientId); etalio.putExtra(EXTRA_PACKAGE_NAME, activity.getPackageName()); etalio.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); activity.startActivityForResult(etalio, REQUEST_CODE_SSO); } }
From source file:at.flack.MailOutActivity.java
public void openMessageActivity(Activity activity, int arg2) { if (arg2 < 0 || mailOutList.size() == 0) return;//from ww w . ja va 2 s . c o m Intent mailIntent = new Intent(activity, MailOverview.class); mailIntent.putExtra("CONTACT_MAIL", mailOutList.get(arg2).getFromMail()); mailIntent.putExtra("CONTACT_NAME", mailOutList.get(arg2).getFromName()); mailIntent.putExtra("MY_MAIL", mailOutList.get(arg2).getToMail()); mailIntent.putExtra("profilePicture", mailOutList.get(arg2).getPicture()); mailIntent.putExtra("MAIL_TEXT", mailOutList.get(arg2).getLastMessage()); mailIntent.putExtra("MAIL_TITLE", mailOutList.get(arg2).getTitle()); mailIntent.putExtra("MAIL_DATE", mailOutList.get(arg2).getDate().toString()); mailIntent.putExtra("ALLOW_KEY_EXCHANGE", false); try { KeyEntity key = KeySafe.getInstance(activity).get(mailOutList.get(arg2).getFromMail()); if (key != null && key.getVersion() != KeyEntity.ECDH_PRIVATE_KEY) mailIntent.putExtra("CONTACT_KEY", key); } catch (NullPointerException e) { } activity.startActivityForResult(mailIntent, 2); }
From source file:io.flutter.plugins.imagepicker.ImagePickerPlugin.java
@Override public void onMethodCall(MethodCall call, MethodChannel.Result result) { if (pendingResult != null) { result.error("ALREADY_ACTIVE", "Image picker is already active", null); return;/*from w ww. j a v a 2s. c om*/ } Activity activity = registrar.activity(); if (activity == null) { result.error("no_activity", "image_picker plugin requires a foreground activity.", null); return; } pendingResult = result; methodCall = call; if (call.method.equals("pickImage")) { int imageSource = call.argument("source"); switch (imageSource) { case SOURCE_GALLERY: pickImageFromGallery(activity); break; case SOURCE_CAMERA: if (ContextCompat.checkSelfPermission(activity, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE }, REQUEST_CAMERA_PERMISSIONS); break; } activity.startActivityForResult( // TODO: Refactor to use the native camera. After that, remove the // com.esafirm.imagepicker depency. cameraModule.getCameraIntent(activity), REQUEST_CODE_CAMERA); break; default: throw new IllegalArgumentException("Invalid image source: " + imageSource); } } else { throw new IllegalArgumentException("Unknown method " + call.method); } }
From source file:at.flack.FacebookMainActivity.java
public void openMessageActivity(Activity activity, int arg2) { if (arg2 < 0 || activity == null || MainActivity.getFbcontacts() == null || MainActivity.getFbcontacts().size() == 0) return;/*from www .j av a2 s .co m*/ Intent smsIntent = new Intent(activity, FbMessageOverview.class); smsIntent.putExtra("CONTACT_ID", MainActivity.getFbcontacts().get(arg2).getFbId()); smsIntent.putExtra("MY_ID", MainActivity.fb_api.getMyID()); smsIntent.putExtra("CONTACT_NAME", MainActivity.getFbcontacts().get(arg2).getName()); smsIntent.putExtra("CONTACT_TID", MainActivity.getFbcontacts().get(arg2).getTid()); smsIntent.putExtra("isGroupChat", MainActivity.getFbcontacts().get(arg2).getFbId().equals("")); try { KeyEntity key = KeySafe.getInstance(activity).get(MainActivity.getFbcontacts().get(arg2).getTid()); if (key != null) smsIntent.putExtra("CONTACT_KEY", key); } catch (NullPointerException e) { } activity.startActivityForResult(smsIntent, 2); }
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 w w w . j a va 2 s.co 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.facebook.AuthorizationClient.java
void setContext(final Activity activity) { this.context = activity; // If we are used in the context of an activity, we will always use that activity to // call startActivityForResult. startActivityDelegate = new StartActivityDelegate() { @Override/*w ww . ja v a2s.c o m*/ public void startActivityForResult(Intent intent, int requestCode) { activity.startActivityForResult(intent, requestCode); } @Override public Activity getActivityContext() { return activity; } }; }
From source file:org.opendatakit.tables.utils.CollectUtil.java
/** * Launch Collect with the given Intent. This method should be used rather * than launching the Intent yourself if the row is going to be added into a * table other than that which you are currently displaying. This method * handles storing the table id of that table so that it can be reclaimed when * the activity returns./* w w w . ja v a 2 s. c om*/ * <p> * Launches with the return code * {@link Constants.RequestCodes.ADD_ROW_COLLECT}. * * @param activityToAwaitReturn * @param collectAddIntent * @param tableId */ public static void launchCollectToAddRow(Activity activityToAwaitReturn, Intent collectAddIntent, String tableId) { // We want to save the id of the table that is going to receive the row // that returns from Collect. We'll store it in a SharedPreference so // that we can get at it. SharedPreferences preferences = activityToAwaitReturn.getSharedPreferences(SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); preferences.edit().putString(PREFERENCE_KEY_TABLE_ID_ADD, tableId).commit(); activityToAwaitReturn.startActivityForResult(collectAddIntent, Constants.RequestCodes.ADD_ROW_COLLECT); }