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.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 a  va  2  s.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:com.javielinux.utils.Utils.java

public static void sendLastCrash(Activity cnt) {
    try {/*from   ww  w  .j a v a  2 s .  co  m*/
        Intent gmail = new Intent(Intent.ACTION_VIEW);
        gmail.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
        gmail.putExtra(Intent.EXTRA_EMAIL, new String[] { cnt.getString(R.string.email_send_errors) });
        gmail.setData(Uri.parse(cnt.getString(R.string.email_send_errors)));
        gmail.putExtra(Intent.EXTRA_SUBJECT, "TweetTopics crash");
        gmail.setType("plain/text");
        gmail.putExtra(Intent.EXTRA_TEXT, ErrorReporter.getErrors(cnt));
        cnt.startActivity(gmail);
    } catch (ActivityNotFoundException e) {
        Intent msg = new Intent(Intent.ACTION_SEND);
        msg.putExtra(Intent.EXTRA_EMAIL, new String[] { cnt.getString(R.string.email_send_errors) });
        msg.putExtra(Intent.EXTRA_SUBJECT, "TweetTopics crash");
        msg.setType("plain/text");
        msg.putExtra(Intent.EXTRA_TEXT, ErrorReporter.getErrors(cnt));
        cnt.startActivity(msg);
    }
}

From source file:br.com.hotforms.usewaze.UseWaze.java

private void callWaze(final String url) {
    final Activity activity = this.cordova.getActivity();
    activity.runOnUiThread(new Runnable() {
        @Override//from   ww w .  j  a va 2 s  . c  om
        public void run() {
            try {
                Intent intent = null;
                intent = new Intent(Intent.ACTION_VIEW);
                // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
                // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
                Uri uri = Uri.parse(url);
                if ("file".equals(uri.getScheme())) {
                    intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
                } else {
                    intent.setData(uri);
                }

                activity.startActivity(intent);
            } catch (ActivityNotFoundException ex) {
                String urlMarket = "market://details?id=com.waze";
                Intent intent = null;
                intent = new Intent(Intent.ACTION_VIEW);
                // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
                // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
                Uri uri = Uri.parse(urlMarket);
                if ("file".equals(uri.getScheme())) {
                    intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
                } else {
                    intent.setData(uri);
                }

                activity.startActivity(intent);
            }
        }
    });
}

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

/**
 * Opens the correct intent to start editing the channel.
 *
 * @param activity The activity you're calling this from.
 * @param channelUrl The channel's media url.m
 *//*from w w w.j  a va 2 s  .  c o m*/
public static void editChannel(final Activity activity, final String channelUrl) {
    ChannelDatabase cdn = ChannelDatabase.getInstance(activity);
    final JsonChannel jsonChannel = cdn.findChannelByMediaUrl(channelUrl);
    if (channelUrl == null || jsonChannel == null) {
        try {
            Toast.makeText(activity, R.string.toast_error_channel_invalid, Toast.LENGTH_SHORT).show();
        } catch (RuntimeException e) {
            Log.e(TAG, activity.getString(R.string.toast_error_channel_invalid));
        }
        return;
    }
    if (jsonChannel.getPluginSource() != null) {
        // Search through all plugins for one of a given source
        PackageManager pm = activity.getPackageManager();

        try {
            pm.getPackageInfo(jsonChannel.getPluginSource().getPackageName(), PackageManager.GET_ACTIVITIES);
            // Open up this particular activity
            Intent intent = new Intent();
            intent.setComponent(jsonChannel.getPluginSource());
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EDIT);
            Log.d(TAG, "Editing channel " + jsonChannel.toString());
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_JSON, jsonChannel.toString());
            activity.startActivity(intent);
        } catch (PackageManager.NameNotFoundException e) {
            new MaterialDialog.Builder(activity)
                    .title(activity.getString(R.string.plugin_not_installed_title,
                            jsonChannel.getPluginSource().getPackageName()))
                    .content(R.string.plugin_not_installed_question).positiveText(R.string.download_app)
                    .negativeText(R.string.open_in_another_plugin)
                    .callback(new MaterialDialog.ButtonCallback() {
                        @Override
                        public void onPositive(MaterialDialog dialog) {
                            super.onPositive(dialog);
                            Intent i = new Intent(Intent.ACTION_VIEW);
                            i.setData(Uri.parse("http://play.google.com/store/apps/details?id="
                                    + jsonChannel.getPluginSource().getPackageName()));
                            activity.startActivity(i);
                        }

                        @Override
                        public void onNegative(MaterialDialog dialog) {
                            super.onNegative(dialog);
                            openPluginPicker(false, channelUrl, activity);
                        }
                    }).show();
            Toast.makeText(activity, activity.getString(R.string.toast_msg_pack_not_installed,
                    jsonChannel.getPluginSource().getPackageName()), Toast.LENGTH_SHORT).show();
            openPluginPicker(false, channelUrl, activity);
        }
    } else {
        if (DEBUG) {
            Log.d(TAG, "No specified source");
        }
        openPluginPicker(false, channelUrl, activity);
    }
}

From source file:net.bible.android.control.link.LinkControl.java

private void showAllOccurrences(String ref, SearchBibleSection biblesection, String refPrefix) {
    Book currentBible = CurrentPageManager.getInstance().getCurrentBible().getCurrentDocument();
    Book strongsBible = null;/*  w ww .  j  av a  2s .  c  om*/

    // if current bible has no Strongs refs then try to find one that has
    if (currentBible.hasFeature(FeatureType.STRONGS_NUMBERS)) {
        strongsBible = currentBible;
    } else {
        strongsBible = SwordDocumentFacade.getInstance().getDefaultBibleWithStrongs();
    }

    // possibly no Strong's bible or it has not been indexed
    boolean needToDownloadIndex = false;
    if (strongsBible == null) {
        Dialogs.getInstance().showErrorMsg(R.string.no_indexed_bible_with_strongs_ref);
        return;
    } else if (currentBible.equals(strongsBible) && !checkStrongs(currentBible)) {
        Log.d(TAG, "Index status is NOT DONE");
        needToDownloadIndex = true;
    }

    // The below uses ANY_WORDS because that does not add anything to the search string
    //String noLeadingZeroRef = StringUtils.stripStart(ref, "0");
    String searchText = ControlFactory.getInstance().getSearchControl()
            .decorateSearchString("strong:" + refPrefix + ref, SearchType.ANY_WORDS, biblesection, null);
    Log.d(TAG, "Search text:" + searchText);

    Activity activity = CurrentActivityHolder.getInstance().getCurrentActivity();
    Bundle searchParams = new Bundle();
    searchParams.putString(SearchControl.SEARCH_TEXT, searchText);
    searchParams.putString(SearchControl.SEARCH_DOCUMENT, strongsBible.getInitials());
    searchParams.putString(SearchControl.TARGET_DOCUMENT, currentBible.getInitials());

    Intent intent = null;
    if (needToDownloadIndex) {
        intent = new Intent(activity, SearchIndex.class);
    } else {
        //If an indexed Strong's module is in place then do the search - the normal situation
        intent = new Intent(activity, SearchResults.class);
    }

    intent.putExtras(searchParams);
    activity.startActivity(intent);

    return;
}

From source file:com.github.yuqilin.qmediaplayerapp.util.Permissions.java

private static Dialog createSettingsDialogCompat(final Activity activity, int mode) {
    int titleId = 0, textId = 0;
    String action = Settings.ACTION_MANAGE_WRITE_SETTINGS;
    switch (mode) {
    case PERMISSION_SYSTEM_RINGTONE:
        titleId = R.string.allow_settings_access_ringtone_title;
        textId = R.string.allow_settings_access_ringtone_description;
        break;// w  ww  . j a  va 2 s  .c o  m
    case PERMISSION_SYSTEM_BRIGHTNESS:
        titleId = R.string.allow_settings_access_brightness_title;
        textId = R.string.allow_settings_access_brightness_description;
        break;
    case PERMISSION_SYSTEM_DRAW_OVRLAYS:
        titleId = R.string.allow_draw_overlays_title;
        textId = R.string.allow_sdraw_overlays_description;
        action = Settings.ACTION_MANAGE_OVERLAY_PERMISSION;
        break;
    }
    final String finalAction = action;
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity).setTitle(activity.getString(titleId))
            .setMessage(activity.getString(textId)).setIcon(android.R.drawable.ic_dialog_alert)
            .setPositiveButton(activity.getString(R.string.permission_ask_again),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int whichButton) {
                            SharedPreferences settings = PreferenceManager
                                    .getDefaultSharedPreferences(activity);
                            Intent i = new Intent(finalAction);
                            i.setData(Uri.parse("package:" + activity.getPackageName()));
                            try {
                                activity.startActivity(i);
                            } catch (Exception ex) {
                            }
                            SharedPreferences.Editor editor = settings.edit();
                            editor.putBoolean("user_declined_settings_access", true);
                            Util.commitPreferences(editor);
                        }
                    });
    return dialogBuilder.show();
}

From source file:com.shafiq.mytwittle.App.java

public void restartApp(Activity currentActivity) {
    Intent intent = getBaseContext().getPackageManager()
            .getLaunchIntentForPackage(getBaseContext().getPackageName());
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_ANIMATION
            | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    currentActivity.overridePendingTransition(0, 0);
    currentActivity.startActivity(intent);
}

From source file:com.bellman.bible.android.control.link.LinkControl.java

private void showAllOccurrences(String ref, SearchBibleSection biblesection, String refPrefix) {
    Book currentBible = getCurrentPageManager().getCurrentBible().getCurrentDocument();
    Book strongsBible = null;/*from w  ww .j  av  a2s.  com*/

    // if current bible has no Strongs refs then try to find one that has
    if (currentBible.hasFeature(FeatureType.STRONGS_NUMBERS)) {
        strongsBible = currentBible;
    } else {
        strongsBible = SwordDocumentFacade.getInstance().getDefaultBibleWithStrongs();
    }

    // possibly no Strong's bible or it has not been indexed
    boolean needToDownloadIndex = false;
    if (strongsBible == null) {
        Dialogs.getInstance().showErrorMsg(R.string.no_indexed_bible_with_strongs_ref);
        return;
    } else if (currentBible.equals(strongsBible) && !checkStrongs(currentBible)) {
        Log.d(TAG, "Index status is NOT DONE");
        needToDownloadIndex = true;
    }

    // The below uses ANY_WORDS because that does not add anything to the search string
    //String noLeadingZeroRef = StringUtils.stripStart(ref, "0");
    String searchText = ControlFactory.getInstance().getSearchControl()
            .decorateSearchString("strong:" + refPrefix + ref, SearchType.ANY_WORDS, biblesection, null);
    Log.d(TAG, "Search text:" + searchText);

    Activity activity = CurrentActivityHolder.getInstance().getCurrentActivity();
    Bundle searchParams = new Bundle();
    searchParams.putString(SearchControl.SEARCH_TEXT, searchText);
    searchParams.putString(SearchControl.SEARCH_DOCUMENT, strongsBible.getInitials());
    searchParams.putString(SearchControl.TARGET_DOCUMENT, currentBible.getInitials());

    Intent intent = null;
    if (needToDownloadIndex) {
        intent = new Intent(activity, SearchIndex.class);
    } else {
        //If an indexed Strong's module is in place then do the search - the normal situation
        intent = new Intent(activity, SearchResults.class);
    }

    intent.putExtras(searchParams);
    activity.startActivity(intent);

    return;
}

From source file:org.messic.android.controllers.LoginController.java

public void login(final Activity context, final boolean remember, final String username, final String password,
        final ProgressDialog pd) throws Exception {
    Network.nukeNetwork();//from   w  ww .  j a v  a  2 s.co  m

    final String baseURL = Configuration.getBaseUrl() + "/messiclogin";
    MultiValueMap<String, Object> formData = new LinkedMultiValueMap<String, Object>();
    formData.add("j_username", username);
    formData.add("j_password", password);
    try {
        RestJSONClient.post(baseURL, formData, MDMLogin.class, new RestJSONClient.RestListener<MDMLogin>() {
            public void response(MDMLogin response) {
                MessicPreferences mp = new MessicPreferences(context);
                mp.setRemember(remember, username, password);
                Configuration.setToken(response.getMessic_token());

                pd.dismiss();
                Intent ssa = new Intent(context, BaseActivity.class);
                context.startActivity(ssa);
            }

            public void fail(Exception e) {
                Log.e("Login", e.getMessage(), e);
                context.runOnUiThread(new Runnable() {
                    public void run() {
                        pd.dismiss();
                        Toast.makeText(context, "Error", Toast.LENGTH_LONG).show();
                    }
                });

            }
        });
    } catch (Exception e) {
        pd.dismiss();
        Log.e("login", e.getMessage(), e);
        throw e;
    }
}