Example usage for android.app Activity startActivity

List of usage examples for android.app Activity startActivity

Introduction

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

Prototype

@Override
public void startActivity(Intent intent) 

Source Link

Document

Same as #startActivity(Intent,Bundle) with no options specified.

Usage

From source file:com.android.messaging.ui.UIIntentsImpl.java

@Override
public void launchFullScreenPhotoViewer(final Activity activity, final Uri initialPhoto,
        final Rect initialPhotoBounds, final Uri photosUri) {
    final PhotoViewIntentBuilder builder = com.android.ex.photo.Intents.newPhotoViewIntentBuilder(activity,
            BuglePhotoViewActivity.class);
    builder.setPhotosUri(photosUri.toString());
    builder.setInitialPhotoUri(initialPhoto.toString());
    builder.setProjection(ConversationImagePartsView.PhotoViewQuery.PROJECTION);

    // Set the location of the imageView so that the photoviewer can animate from that location
    // to full screen.
    builder.setScaleAnimation(initialPhotoBounds.left, initialPhotoBounds.top, initialPhotoBounds.width(),
            initialPhotoBounds.height());

    builder.setDisplayThumbsFullScreen(false);
    builder.setMaxInitialScale(8);//from  w w w . j a  v a2s. c o m
    activity.startActivity(builder.build());
    activity.overridePendingTransition(0, 0);
}

From source file:com.auth0.lock.react.LockReactModule.java

/**
 * This method is exported to JS/*  ww  w.j  a v a 2s.com*/
 * Called from JS to show the Lock.Android login/signup activities. It will display the
 * corresponding activity based on the requested connections and other options.
 *
 * @param options the map with the values passed when invoked from JS. Some of the supported
 *                fields are "closable", "connections", "useMagicLink" and "authParams"
 *                @see com.auth0.lock.react.bridge.ShowOptions
 * @param callback the JS callback that will be invoked with the results. It should be a function
 *                 of the form callback(error, profile, token)
 */
@ReactMethod
public void show(@Nullable ReadableMap options, Callback callback) {
    authCallback = callback;
    authenticationReceiver.registerIn(this.broadcastManager);

    ShowOptions showOptions = new ShowOptions(options);

    lockBuilder.closable(showOptions.isClosable()).disableSignUp(showOptions.isDisableSignUp())
            .disableChangePassword(showOptions.isDisableResetPassword())
            .authenticationParameters(showOptions.getAuthParams());

    if (showOptions.getConnections() != null) {
        lockBuilder.useConnections(showOptions.getConnections());
    }

    LockContext.configureLock(lockBuilder);

    Activity activity = getCurrentActivity();

    if (activity == null) {
        invokeAuthCallback(getReactApplicationContext()
                .getString(R.string.com_auth0_android_react_native_lock_no_activity), null, null);
        return;
    }

    Intent intent;
    switch (showOptions.getConnectionType()) {
    case CONNECTION_SMS:
        intent = new Intent(activity, LockPasswordlessActivity.class);
        intent.putExtra(LockPasswordlessActivity.PASSWORDLESS_TYPE_PARAMETER,
                showOptions.useMagicLink() ? LockPasswordlessActivity.MODE_SMS_MAGIC_LINK
                        : LockPasswordlessActivity.MODE_SMS_CODE);
        break;
    case CONNECTION_EMAIL:
        intent = new Intent(activity, LockPasswordlessActivity.class);
        intent.putExtra(LockPasswordlessActivity.PASSWORDLESS_TYPE_PARAMETER,
                showOptions.useMagicLink() ? LockPasswordlessActivity.MODE_EMAIL_MAGIC_LINK
                        : LockPasswordlessActivity.MODE_EMAIL_CODE);
        break;
    case CONNECTION_NATIVE:
    default:
        intent = new Intent(activity, LockActivity.class);
    }

    activity.startActivity(intent);
}

From source file:ch.uzh.supersede.feedbacklibrary.utils.Utils.java

/**
 * This method takes a screenshot of the current screen automatically and opens the FeedbackActivity from the feedback library in case if a PUSH feedback is triggered.
 *
 * @param baseURL       the base URL/*  ww w.ja  v a2 s  .co m*/
 * @param activity      the activity in which the method is called
 * @param applicationId the application id
 * @param language      the language
 */
public static void startActivityWithScreenshotCapture(@NonNull final String baseURL,
        @NonNull final Activity activity, final long applicationId, @NonNull final String language) {
    Retrofit rtf = new Retrofit.Builder().baseUrl(baseURL).addConverterFactory(GsonConverterFactory.create())
            .build();
    feedbackAPI fbAPI = rtf.create(feedbackAPI.class);
    Call<ResponseBody> checkUpAndRunning = fbAPI.pingOrchestrator();

    if (checkUpAndRunning != null) {
        checkUpAndRunning.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Log.e(TAG, "Failed to ping the server. onFailure method called", t);
                DialogUtils.showInformationDialog(activity,
                        new String[] { activity.getResources().getString(
                                R.string.supersede_feedbacklibrary_feedback_application_unavailable_text) },
                        true);
            }

            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                if (response.code() == 200) {
                    Intent intent = new Intent(activity, FeedbackActivity.class);
                    String defaultImagePath = Utils.captureScreenshot(activity);
                    intent.putExtra(FeedbackActivity.DEFAULT_IMAGE_PATH, defaultImagePath);
                    intent.putExtra(FeedbackActivity.EXTRA_KEY_APPLICATION_ID, applicationId);
                    intent.putExtra(FeedbackActivity.EXTRA_KEY_BASE_URL, baseURL);
                    intent.putExtra(FeedbackActivity.EXTRA_KEY_LANGUAGE, language);
                    activity.startActivity(intent);
                } else {
                    Log.e(TAG, "The server is not up and running. Response code == " + response.code());
                    DialogUtils.showInformationDialog(activity,
                            new String[] { activity.getResources().getString(
                                    R.string.supersede_feedbacklibrary_feedback_application_unavailable_text) },
                            true);
                }
            }
        });
    } else {
        Log.e(TAG, "Failed to ping the server. Call<ResponseBody> checkUpAndRunning result is null");
        DialogUtils.showInformationDialog(activity,
                new String[] { activity.getResources()
                        .getString(R.string.supersede_feedbacklibrary_feedback_application_unavailable_text) },
                true);
    }
}

From source file:com.vuze.android.remote.AppPreferences.java

public void showRateDialog(final Activity mContext) {

    if (!shouldShowRatingReminder()) {
        return;//from   w w w .  j  a v  a 2 s  .c  o  m
    }

    // skip showing if they are adding a torrent (or anything else)
    Intent intent = mContext.getIntent();
    if (intent != null) {
        Uri data = intent.getData();
        if (data != null) {
            return;
        }
    }

    // even if something goes wrong, we want to set that we asked, so
    // it doesn't continue to pop up
    setAskedRating();

    Dialog dialog = new Dialog(mContext);

    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
    builder.setMessage(R.string.ask_rating_message).setCancelable(false)
            .setPositiveButton(R.string.rate_now, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    final String appPackageName = mContext.getPackageName();
                    try {
                        mContext.startActivity(new Intent(Intent.ACTION_VIEW,
                                Uri.parse("market://details?id=" + appPackageName)));
                    } catch (android.content.ActivityNotFoundException anfe) {
                        mContext.startActivity(new Intent(Intent.ACTION_VIEW,
                                Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
                    }
                    VuzeEasyTracker.getInstance(mContext).sendEvent("uiAction", "Rating", "AskStoreClick",
                            null);
                }
            }).setNeutralButton(R.string.later, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).setNegativeButton(R.string.no_thanks, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    setNeverAskRatingAgain();
                }
            });
    dialog = builder.create();

    VuzeEasyTracker.getInstance(mContext).sendEvent("uiAction", "Rating", "AskShown", null);
    dialog.show();
}

From source file:com.felkertech.n.ActivityUtils.java

public static void browsePlugins(final Activity activity) {
    //Same opening
    final PackageManager pm = activity.getPackageManager();
    final Intent plugin_addchannel = new Intent(CumulusTvPlugin.ACTION_ADD_CHANNEL);
    final List<ResolveInfo> plugins = pm.queryIntentActivities(plugin_addchannel, 0);
    ArrayList<String> plugin_names = new ArrayList<>();
    for (ResolveInfo ri : plugins) {
        plugin_names.add(ri.loadLabel(pm).toString());
    }//from ww w . ja v a  2  s  . c o  m
    String[] plugin_names2 = plugin_names.toArray(new String[plugin_names.size()]);

    new MaterialDialog.Builder(activity).title(R.string.installed_plugins).items(plugin_names2)
            .itemsCallback(new MaterialDialog.ListCallback() {
                @Override
                public void onSelection(MaterialDialog materialDialog, View view, int i,
                        CharSequence charSequence) {
                    // Load the given plugin with some additional info
                    ChannelDatabase cd = ChannelDatabase.getInstance(activity);
                    String s = cd.toString();
                    Intent intent = new Intent();
                    if (DEBUG) {
                        Log.d(TAG, "Try to start");
                    }
                    ResolveInfo plugin_info = plugins.get(i);
                    Log.d(TAG, plugin_info.activityInfo.applicationInfo.packageName + " "
                            + plugin_info.activityInfo.name);

                    intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                            plugin_info.activityInfo.name);
                    intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EXTRA_READ_ALL);
                    intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ALL_CHANNELS, s);
                    activity.startActivity(intent);
                }
            }).positiveText(R.string.download_more_plugins)
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse("http://play.google.com/store/search?q=cumulustv&c=apps"));
                    activity.startActivity(i);
                }
            }).show();
}

From source file:com.arellomobile.android.push.PushManager.java

boolean onHandlePush(Activity activity) {
    Bundle pushBundle = activity.getIntent().getBundleExtra("pushBundle");
    if (null == pushBundle || null == mContext) {
        return false;
    }/*from w ww.j  av  a2 s.  c o  m*/

    mLastBundle = pushBundle;

    JSONObject dataObject = new JSONObject();
    try {
        if (pushBundle.containsKey("title")) {
            dataObject.put("title", pushBundle.get("title"));
        }
        if (pushBundle.containsKey("u")) {
            dataObject.put("userdata", pushBundle.get("u"));
        }
        if (pushBundle.containsKey("local")) {
            dataObject.put("local", pushBundle.get("local"));
        }
    } catch (JSONException e) {
        // pass
    }

    PushEventsTransmitter.onMessageReceive(mContext, dataObject.toString(), pushBundle);

    // push message handling
    String url = (String) pushBundle.get("h");

    if (url != null) {
        url = String.format(HTML_URL_FORMAT, url);

        // show browser
        Intent intent = new Intent(activity, PushWebview.class);
        intent.putExtra("url", url);
        activity.startActivity(intent);
    }

    // send pushwoosh callback
    sendPushStat(mContext, pushBundle.getString("p"));

    return true;
}

From source file:com.realtek.simpleconfig.SCTest.java

/**
 * Try to launch Wifi Connecter with {@link #hostspot}.
 * @param activity/*  w w  w .  j  ava2 s . co  m*/
 * @param hotspot
 */
private void launchWifiConnecter(final Activity activity, final ScanResult hotspot) {
    final Intent openWifiItemIntent = new Intent("com.wifi.connecter.CONNECT_OR_EDIT");
    openWifiItemIntent.putExtra("com.wifi.connecter.HOTSPOT", hotspot);
    try {
        activity.startActivity(openWifiItemIntent);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(activity, "WiFi", Toast.LENGTH_LONG).show();
        Log.e(TAG, "Wifi Connecter is not installed.");
    }
}

From source file:com.felkertech.n.ActivityUtils.java

public static void openPluginPicker(final boolean newChannel, final JsonChannel queriedChannel,
        final Activity activity) {
    final PackageManager pm = activity.getPackageManager();
    final Intent plugin_addchannel = new Intent(CumulusTvPlugin.ACTION_ADD_CHANNEL);
    final List<ResolveInfo> plugins = pm.queryIntentActivities(plugin_addchannel, 0);
    ArrayList<String> plugin_names = new ArrayList<String>();
    for (ResolveInfo ri : plugins) {
        plugin_names.add(ri.loadLabel(pm).toString());
    }/*from  w w w. j a v  a 2 s  . c  o m*/
    String[] plugin_names2 = plugin_names.toArray(new String[plugin_names.size()]);
    if (DEBUG) {
        Log.d(TAG, "Load plugins " + plugin_names.toString());
    }
    if (plugin_names.size() == 1) {
        Intent intent = new Intent();
        if (newChannel) {
            if (DEBUG) {
                Log.d(TAG, "Try to start ");
            }
            ResolveInfo plugin_info = plugins.get(0);
            if (DEBUG) {
                Log.d(TAG, plugin_info.activityInfo.applicationInfo.packageName + " "
                        + plugin_info.activityInfo.name);
            }

            intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                    plugin_info.activityInfo.name);
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_ADD);
        } else {
            ResolveInfo plugin_info = plugins.get(0);
            Log.d(TAG,
                    plugin_info.activityInfo.applicationInfo.packageName + " " + plugin_info.activityInfo.name);
            intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                    plugin_info.activityInfo.name);
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EDIT);
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_JSON, queriedChannel.toString());
        }
        activity.startActivity(intent);
    } else {
        new MaterialDialog.Builder(activity).items(plugin_names2).title(R.string.choose_an_app)
                .content(R.string.choose_default_app).itemsCallback(new MaterialDialog.ListCallback() {
                    @Override
                    public void onSelection(MaterialDialog materialDialog, View view, int i,
                            CharSequence charSequence) {
                        Intent intent = new Intent();
                        if (newChannel) {
                            if (DEBUG) {
                                Log.d(TAG, "Try to start");
                            }
                            ResolveInfo plugin_info = plugins.get(i);
                            if (DEBUG) {
                                Log.d(TAG, plugin_info.activityInfo.applicationInfo.packageName + " "
                                        + plugin_info.activityInfo.name);
                            }

                            intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                                    plugin_info.activityInfo.name);

                            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_ADD);
                        } else {
                            ResolveInfo plugin_info = plugins.get(i);
                            intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                                    plugin_info.activityInfo.name);
                            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EDIT);
                            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_JSON, queriedChannel.toString());
                        }
                        activity.startActivity(intent);
                    }
                }).show();
    }
}

From source file:com.google.plus.wigwamnow.social.FacebookProvider.java

/**
 * Handle a Facebook error and display an appropriate dialog to the user.
 *
 * @param error the error to handle./*from ww w .  j a v  a2  s . com*/
 */
private void handleError(FacebookRequestError error, final Activity activity) {
    String dialogBody = null;
    DialogInterface.OnClickListener listener = null;

    if (error == null) {
        // There was no response from the server
        dialogBody = activity.getString(R.string.error_dialog_default_text);
    } else {
        switch (error.getCategory()) {
        case AUTHENTICATION_RETRY:
            // Tell the user what happened by getting the message id and retry the operation
            // later
            String userAction = error.shouldNotifyUser() ? ""
                    : activity.getString(error.getUserActionMessageId());
            dialogBody = activity.getString(R.string.error_authentication_retry, userAction);

            listener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    // Go to the Facebook mobile site
                    Intent intent = new Intent(Intent.ACTION_VIEW, M_FACEBOOK_URL);
                    activity.startActivity(intent);
                }
            };
            break;

        case AUTHENTICATION_REOPEN_SESSION:
            // Close the session and reopen it
            dialogBody = activity.getString(R.string.error_authentication_reopen);
            listener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    Session session = Session.getActiveSession();
                    if (session != null && !session.isClosed()) {
                        session.closeAndClearTokenInformation();
                    }
                }
            };
            break;

        case PERMISSION:
            // Error related to permissions
            dialogBody = activity.getString(R.string.error_permission);
            listener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    // TODO(samstern): Set this in the activity
                    // mPendingStructuredShare = true;
                    requestPublishPermissions(Session.getActiveSession(), activity);
                }
            };
            break;

        case SERVER:
        case THROTTLING:
            // This error is usually temporary, just ask the user to try again
            dialogBody = activity.getString(R.string.error_server);
            break;

        case BAD_REQUEST:
            // Coding error, ask the user to file a bug if appropriate
            dialogBody = activity.getString(R.string.error_bad_request, error.getErrorMessage());
            break;

        case OTHER:
        case CLIENT:
        default:
            // An unknown issue occurred. Could be a coding error or server side.
            dialogBody = activity.getString(R.string.error_unknown, error.getErrorMessage());
            break;
        }

        // Show the error dialog
        new AlertDialog.Builder(activity).setPositiveButton("OK", listener).setTitle("Error")
                .setMessage(dialogBody).show();
    }
}