Example usage for android.app Activity startActivityForResult

List of usage examples for android.app Activity startActivityForResult

Introduction

In this page you can find the example usage for android.app Activity startActivityForResult.

Prototype

public void startActivityForResult(@RequiresPermission Intent intent, int requestCode) 

Source Link

Document

Same as calling #startActivityForResult(Intent,int,Bundle) with no options.

Usage

From source file:org.ieatta.activity.gallery.GalleryActivity.java

/**
 * Launch the image gallery activity, and start with the provided image.
 *
 * @param imageTitle Image with which to begin the gallery.
 *//* www . j av  a2  s. co  m*/
public static void showGallery(Activity activity, PageTitle pageTitle, PageTitle imageTitle, int source) {
    Intent galleryIntent = new Intent();
    galleryIntent.setClass(activity, GalleryActivity.class);
    galleryIntent.putExtra(EXTRA_IMAGETITLE, imageTitle);
    galleryIntent.putExtra(EXTRA_PAGETITLE, pageTitle);
    galleryIntent.putExtra(EXTRA_SOURCE, source);
    activity.startActivityForResult(galleryIntent, PageActivity.ACTIVITY_REQUEST_GALLERY);
}

From source file:com.alivenet.dmv.driverapplication.fragment.MyAccount.java

public static void openGallery(final Activity context) {

    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
    photoPickerIntent.setType("image/*");
    context.startActivityForResult(photoPickerIntent, ConstantUtil.REQUEST_CODE_GALLERY);
}

From source file:com.ruesga.rview.misc.ActivityHelper.java

public static void openChangeListByFilterActivity(Activity activity, String title, ChangeQuery filter,
        boolean dirty, boolean clearStack) {
    Intent intent = new Intent(activity, ChangeListByFilterActivity.class);
    if (clearStack) {
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    } else {/*w w  w. j  a va 2s  . c o m*/
        intent.putExtra(Constants.EXTRA_HAS_PARENT, true);
    }
    intent.putExtra(Constants.EXTRA_TITLE, title);
    intent.putExtra(Constants.EXTRA_FILTER, filter.toString());
    intent.putExtra(Constants.EXTRA_DIRTY, dirty);
    activity.startActivityForResult(intent, LIST_RESULT_CODE);
}

From source file:com.enstage.wibmo.sdk.inapp.InAppInitActivity.java

public static void startInAppFlowInBrowser(Activity activity, W2faInitRequest w2faInitRequest,
        W2faInitResponse w2faInitResponse) {
    Intent intent = new Intent(activity, InAppBrowserActivity.class);
    intent.putExtra("W2faInitRequest", w2faInitRequest);
    intent.putExtra("W2faInitResponse", w2faInitResponse);
    activity.startActivityForResult(intent, WibmoSDK.REQUEST_CODE_IAP_2FA);
}

From source file:com.enstage.wibmo.sdk.inapp.InAppInitActivity.java

public static void startInAppFlowInBrowser(Activity activity, WPayInitRequest wPayInitRequest,
        WPayInitResponse wPayInitResponse) {
    Intent intent = new Intent(activity, InAppBrowserActivity.class);
    intent.putExtra("WPayInitRequest", wPayInitRequest);
    intent.putExtra("WPayInitResponse", wPayInitResponse);
    activity.startActivityForResult(intent, WibmoSDK.REQUEST_CODE_IAP_PAY);
}

From source file:Main.java

public static Pair<BluetoothManager, BluetoothAdapter> checkBT(final Activity activity) {
    // Use this check to determine whether BLE is supported on the device. Then
    // you can selectively disable BLE-related features.
    if (!btleSupport(activity)) {
        return null;
    }/*from w ww.ja v  a  2 s .  c  o  m*/
    final BluetoothManager bluetoothManager = (BluetoothManager) activity
            .getSystemService(Context.BLUETOOTH_SERVICE);
    BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();

    //On some devices this does not work
    try {
        bluetoothAdapter.getBluetoothLeScanner();
    } catch (NoSuchMethodError e) {
        return null;
    }

    // Ensures Bluetooth is available on the device and it is enabled. If not,
    // displays a dialog requesting user permission to enable Bluetooth.
    if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) {
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        activity.startActivityForResult(enableBtIntent, 1);
        bluetoothAdapter = bluetoothManager.getAdapter();
    }
    return new Pair<BluetoothManager, BluetoothAdapter>(bluetoothManager, bluetoothAdapter);
}

From source file:com.facebook.notifications.NotificationsManager.java

/**
 * Present an intent from a given activity to show the notification bundle contained in notificationBundle.
 *
 * @param activity           The activity to present from
 * @param notificationBundle The bundle containing the notification payload to present
 * @return whether or not the activity could successfully be presented
 *///  www  .ja  v a  2  s  .co  m
public static boolean presentCard(@NonNull Activity activity, @NonNull Bundle notificationBundle) {
    try {
        JSONObject cardJSON = getCardJSON(notificationBundle);
        if (cardJSON == null) {
            return false;
        }

        JSONObject pushJSON = getPushJSON(notificationBundle);

        Intent presentationIntent = intentForBundle(activity, pushJSON, cardJSON, getAssetManager(activity),
                getContentManager(activity));
        if (presentationIntent == null) {
            return false;
        }

        activity.startActivityForResult(presentationIntent, REQUEST_CODE);
        return true;
    } catch (JSONException ex) {
        Log.e(LOG_TAG, "Error while parsing JSON", ex);
        return false;
    }
}

From source file:org.totschnig.myexpenses.activity.CommonCommands.java

static boolean dispatchCommand(Activity ctx, int command, Object tag) {
    Intent i;//from   w ww. j  a  v a  2  s. c o  m
    switch (command) {
    case R.id.RATE_COMMAND:
        i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(MyApplication.getMarketSelfUri()));
        if (Utils.isIntentAvailable(ctx, i)) {
            ctx.startActivity(i);
        } else {
            Toast.makeText(ctx, R.string.error_accessing_market, Toast.LENGTH_LONG).show();
        }
        return true;
    case R.id.SETTINGS_COMMAND:
        i = new Intent(ctx, MyPreferenceActivity.class);
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (tag != null) {
            i.putExtra(MyPreferenceActivity.KEY_OPEN_PREF_KEY, (String) tag);
        }
        ctx.startActivityForResult(i, ProtectedFragmentActivity.PREFERENCES_REQUEST);
        return true;
    case R.id.FEEDBACK_COMMAND:
        i = new Intent(android.content.Intent.ACTION_SEND);
        i.setType("plain/text");
        i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { MyApplication.FEEDBACK_EMAIL });
        i.putExtra(android.content.Intent.EXTRA_SUBJECT, "[" + ctx.getString(R.string.app_name) + "] Feedback");
        i.putExtra(android.content.Intent.EXTRA_TEXT,
                getVersionInfo(ctx) + "\n" + ctx.getString(R.string.feedback_email_message));
        if (!Utils.isIntentAvailable(ctx, i)) {
            Toast.makeText(ctx, R.string.no_app_handling_email_available, Toast.LENGTH_LONG).show();
        } else {
            ctx.startActivity(i);
        }
        break;
    case R.id.CONTRIB_INFO_COMMAND:
        CommonCommands.showContribInfoDialog((FragmentActivity) ctx, -1);
        return true;
    case R.id.WEB_COMMAND:
        i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(ctx.getString(R.string.website)));
        ctx.startActivity(i);
        return true;
    case R.id.HELP_COMMAND:
        i = new Intent(ctx, Help.class);
        i.putExtra(HelpDialogFragment.KEY_VARIANT,
                tag != null ? (Enum<?>) tag : ((ProtectedFragmentActivity) ctx).helpVariant);
        //for result is needed since it allows us to inspect the calling activity
        ctx.startActivityForResult(i, 0);
        return true;
    case R.id.REQUEST_LICENCE_COMMAND:
        String androidId = Settings.Secure.getString(ctx.getContentResolver(), Settings.Secure.ANDROID_ID);
        i = new Intent(android.content.Intent.ACTION_SEND);
        i.setType("plain/text");
        i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { MyApplication.FEEDBACK_EMAIL });
        i.putExtra(android.content.Intent.EXTRA_SUBJECT,
                "[" + ctx.getString(R.string.app_name) + "] " + ctx.getString(R.string.contrib_key));
        String extraText = ctx.getString(R.string.request_licence_mail_head, androidId);
        if (tag != null) {
            extraText += " \n\n[" + ctx.getString(R.string.paypal_transaction_id) + ": " + tag + "]";
        }
        i.putExtra(android.content.Intent.EXTRA_TEXT, extraText);
        if (!Utils.isIntentAvailable(ctx, i)) {
            Toast.makeText(ctx, R.string.no_app_handling_email_available, Toast.LENGTH_LONG).show();
        } else {
            ctx.startActivity(i);
        }
        return true;
    case R.id.VERIFY_LICENCE_COMMAND:
        HashLicenceHandler licenceHandler = (HashLicenceHandler) MyApplication.getInstance()
                .getLicenceHandler();
        LicenceHandler.LicenceStatus licenceStatus = licenceHandler.verifyLicenceKey();
        if (licenceStatus != null) {
            Toast.makeText(ctx,
                    Utils.concatResStrings(ctx, " ", R.string.licence_validation_success,
                            (licenceStatus == LicenceHandler.LicenceStatus.EXTENDED
                                    ? R.string.licence_validation_extended
                                    : R.string.licence_validation_premium)),
                    Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(ctx, R.string.licence_validation_failure, Toast.LENGTH_LONG).show();
        }
        licenceHandler.invalidate();
        return true;
    case android.R.id.home:
        ctx.setResult(FragmentActivity.RESULT_CANCELED);
        ctx.finish();
        return true;
    }
    return false;
}

From source file:com.tweetlanes.android.core.view.DirectMessageActivity.java

public static void createAndStartActivity(Activity currentActivity, TwitterContentHandle contentHandle,
        long otherUserId, String otherUserScreenName, ArrayList<TwitterDirectMessage> requiredMessages) {

    Intent intent = new Intent(currentActivity, DirectMessageActivity.class);
    intent.putExtra(KEY_HANDLE_BASE, contentHandle);
    intent.putExtra(KEY_OTHER_USER_ID, otherUserId);
    intent.putExtra(KEY_OTHER_USER_SCREEN_NAME, otherUserScreenName);
    JSONArray statusArray = new JSONArray();
    int statusCount = requiredMessages.size();
    for (int i = 0; i < statusCount; ++i) {
        TwitterDirectMessage status = requiredMessages.get(i);
        statusArray.put(status.toString());
    }//from w w w.  j  a  v a  2  s  . c  o m
    intent.putExtra(KEY_CACHE_MESSAGES, statusArray.toString());
    currentActivity.startActivityForResult(intent, Constant.REQUEST_CODE_DM);
}

From source file:com.androidquery.simplefeed.activity.PostActivity.java

public static void start(Activity act, FeedItem item) {

    Intent intent = new Intent(act, PostActivity.class);
    intent.putExtra("item", item);

    act.startActivityForResult(intent, REQUEST);

}