Example usage for android.content Intent setClass

List of usage examples for android.content Intent setClass

Introduction

In this page you can find the example usage for android.content Intent setClass.

Prototype

public @NonNull Intent setClass(@NonNull Context packageContext, @NonNull Class<?> cls) 

Source Link

Document

Convenience for calling #setComponent(ComponentName) with the name returned by a Class object.

Usage

From source file:com.android.calendar.alerts.AlarmScheduler.java

/**
 * Schedules an alarm for the EVENT_REMINDER_APP broadcast, for the specified
 * alarm time with a slight delay (to account for the possible duplicate broadcast
 * from the provider).//from w w  w  . java  2  s .c o m
 */
private static void scheduleAlarm(Context context, long eventId, long alarmTime, long currentMillis,
        AlarmManagerInterface alarmManager) {
    // Max out the alarm time to 1 day out, so an alert for an event far in the future
    // (not present in our event query results for a limited range) can only be at
    // most 1 day late.
    long maxAlarmTime = currentMillis + MAX_ALARM_ELAPSED_MS;
    if (alarmTime > maxAlarmTime) {
        alarmTime = maxAlarmTime;
    }

    // Add a slight delay (see comments on the member var).
    alarmTime += ALARM_DELAY_MS;

    if (AlertService.DEBUG) {
        Time time = new Time();
        time.set(alarmTime);
        String schedTime = time.format("%a, %b %d, %Y %I:%M%P");
        Log.d(TAG, "Scheduling alarm for EVENT_REMINDER_APP broadcast for event " + eventId + " at " + alarmTime
                + " (" + schedTime + ")");
    }

    // Schedule an EVENT_REMINDER_APP broadcast with AlarmManager.  The extra is
    // only used by AlertService for logging.  It is ignored by Intent.filterEquals,
    // so this scheduling will still overwrite the alarm that was previously pending.
    // Note that the 'setClass' is required, because otherwise it seems the broadcast
    // can be eaten by other apps and we somehow may never receive it.
    Intent intent = new Intent(AlertReceiver.EVENT_REMINDER_APP_ACTION);
    intent.setClass(context, AlertReceiver.class);
    intent.putExtra(CalendarContract.CalendarAlerts.ALARM_TIME, alarmTime);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
    alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, pi);
}

From source file:com.yutong.axxc.parents.view.common.ActivityUtils.java

/**
 * activity/*  w w  w . ja v a2  s  . c o  m*/
 * @param from ?activity
 * @param to activity
 * @param extras ??
 */
public static void changeActivity(Activity from, Class<?> to, Bundle extras) {
    // Intent intent = setIntent(from, to, extras);
    Intent intent = new Intent();
    if (extras != null)
        intent.putExtras(extras);
    intent.setClass(from.getBaseContext(), to);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    from.startActivity(intent);
    //from.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
    from.overridePendingTransition(R.anim.enter_righttoleft, R.anim.exit_righttoleft);
}

From source file:bander.notepad.Notepad.java

/**
 * Sets the theme for AppCompat. There is really no dark theme at the moment, it is mainly for
 * the Toolbar Color Chooser./*from w  ww. j  a  v a2  s  . co  m*/
 *
 * @param activity ActionBarActivity acting as a Context
 * @param classType Launch a new activity.
 */
public static void setAppCompatThemeFromPreferences(ActionBarActivity activity, String classType) {
    SharedPreferences mSettings = PreferenceManager.getDefaultSharedPreferences(activity);
    if (mSettings.getString("themeType", "0").equals("0")) {
        final int abc = mSettings.getInt("actionBarColor", 0);

        /**
         * In case you are wondering, the random numbers are the 500 colors that show up with
         * black text from here:
         * {@link http://www.google.com/design/spec/style/color.html}
         * The black text means that I have to use a light theme.
         */
        if (abc >= 11 && abc <= 15 || abc == 18) {
            mSettings.edit().putBoolean("darkAppCompatTheme", false).apply();
        } else {
            mSettings.edit().putBoolean("darkAppCompatTheme", true).apply();
        }
    } else {
        /**
         * Somehow, we ended up with the wrong theme, so let's launch the right activity.
         */
        switch (classType) {
        case "Prefs": {
            Intent intent = new Intent();
            intent.setClass(activity, PrefsActivity.class);
            activity.startActivity(intent);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_NEW_TASK);
            new PrefsActivityAppCompat().finish();
            break;
        }
        case "Edit": {
            Intent intent = new Intent();
            intent.setClass(activity, NoteEdit.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_NEW_TASK);
            activity.startActivity(intent);
            new NoteEditAppCompat().finish();
            break;
        }
        case "NoteList": {
            Intent intent = new Intent();
            intent.setClass(activity, NoteList.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_NEW_TASK);
            activity.startActivity(intent);
            new NoteListAppCompat().finish();
            break;
        }
        default: {
            Intent intent = new Intent();
            intent.setClass(activity, Notepad.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_NEW_TASK);
            activity.startActivity(intent);
            break;
        }
        }
    }
}

From source file:org.openremote.android.console.net.ORControllerServerSwitcher.java

/**
 * Switch to the controller identified by the availableGroupMemberURL
 *
 * @param context                 global Android application context
 * @param availableGroupMemberURL TODO//from w w w  .j  ava2  s .  c  om
 */
private static void switchControllerWithURL(Context context, String availableGroupMemberURL) {
    if (availableGroupMemberURL.equals(AppSettingsModel.getCurrentServer(context))) {
        Log.i(LOG_CATEGORY,
                "The current server is already: " + availableGroupMemberURL + ", should not switch to self.");

        return;
    }

    Main.prepareToastForSwitchingController();

    Log.i(LOG_CATEGORY, "ControllerServerSwitcher is switching controller to " + availableGroupMemberURL);

    AppSettingsModel.setCurrentServer(context, availableGroupMemberURL);

    Intent intent = new Intent();
    intent.setClass(context, Main.class);
    context.startActivity(intent);
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppObj.java

public static Intent getLaunchIntent(Context context, DbObj obj) {
    JSONObject content = obj.getJson();/*from   ww  w .  j  a  va2 s. c o  m*/
    if (content.has(ANDROID_PACKAGE_NAME)) {
        Uri appFeed = obj.getContainingFeed().getUri();
        String action = content.optString(ANDROID_ACTION);
        String pkgName = content.optString(ANDROID_PACKAGE_NAME);
        String className = content.optString(ANDROID_CLASS_NAME);

        Intent launch = new Intent(action);
        launch.setClassName(pkgName, className);
        launch.addCategory(Intent.CATEGORY_LAUNCHER);
        // TODO: feed for related objs, not parent feed
        launch.putExtra(AppState.EXTRA_FEED_URI, appFeed);
        launch.putExtra(AppState.EXTRA_OBJ_HASH, obj.getHash());
        // TODO: Remove
        launch.putExtra("obj", content.toString());

        List<ResolveInfo> resolved = context.getPackageManager().queryIntentActivities(launch, 0);
        if (resolved.size() > 0) {
            return launch;
        }

        Intent market = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + pkgName));
        return market;
    } else if (content.has(WEB_URL)) {
        Intent app = new Intent(Intent.ACTION_VIEW, Uri.parse(content.optString(WEB_URL)));
        app.setClass(context, AppFinderActivity.class);
        app.putExtra(Musubi.EXTRA_FEED_URI, Feed.uriForName(obj.getFeedName()));
        return app;
    }
    return null;
}

From source file:cn.whereyougo.framework.utils.PackageManagerUtil.java

/**
 * ????/*from  ww  w.jav  a 2s  .com*/
 * 
 * @param mContext
 *            
 * @param TagClass
 *            ???
 * @param iconResId
 *            ??
 * @param iconName
 *            ??
 */
public static void addShortCut2Desktop(Context mContext, Class<?> TagClass, int iconResId, String iconName) {
    SharedPreferences sp = mContext.getSharedPreferences("appinfo", Context.MODE_PRIVATE);
    if (!sp.getBoolean("shortcut_flag_icon", false)) {
        sp.edit().putBoolean("shortcut_flag_icon", true).commit();
        LogUtil.d("shortcut", "first create successfull");
    } else {
        LogUtil.d("shortcut", "no created");
        return;
    }

    String ACTION_ADD_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";
    Intent intent = new Intent();
    intent.setClass(mContext, TagClass);
    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

    Intent addShortcut = new Intent(ACTION_ADD_SHORTCUT);
    Parcelable icon = Intent.ShortcutIconResource.fromContext(mContext, iconResId);// ???
    addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, iconName);// ??
    addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);// ??
    addShortcut.putExtra("duplicate", false);// ????
    addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);// ??

    mContext.sendBroadcast(addShortcut);// ??
}

From source file:com.facebook.internal.DialogPresenter.java

public static void setupAppCallForWebDialog(AppCall appCall, String actionName, Bundle parameters) {
    Validate.hasFacebookActivity(FacebookSdk.getApplicationContext());
    Validate.hasInternetPermissions(FacebookSdk.getApplicationContext());

    Bundle intentParameters = new Bundle();
    intentParameters.putString(NativeProtocol.WEB_DIALOG_ACTION, actionName);
    intentParameters.putBundle(NativeProtocol.WEB_DIALOG_PARAMS, parameters);

    Intent webDialogIntent = new Intent();
    NativeProtocol.setupProtocolRequestIntent(webDialogIntent, appCall.getCallId().toString(), actionName,
            NativeProtocol.getLatestKnownVersion(), intentParameters);
    webDialogIntent.setClass(FacebookSdk.getApplicationContext(), FacebookActivity.class);
    webDialogIntent.setAction(FacebookDialogFragment.TAG);

    appCall.setRequestIntent(webDialogIntent);
}

From source file:com.facebook.internal.DialogPresenter.java

public static void setupAppCallForWebFallbackDialog(AppCall appCall, Bundle parameters, DialogFeature feature) {
    Validate.hasFacebookActivity(FacebookSdk.getApplicationContext());
    Validate.hasInternetPermissions(FacebookSdk.getApplicationContext());

    String featureName = feature.name();
    Uri fallbackUrl = getDialogWebFallbackUri(feature);
    if (fallbackUrl == null) {
        throw new FacebookException("Unable to fetch the Url for the DialogFeature : '" + featureName + "'");
    }/*from w w  w. ja  v  a2  s  .com*/

    // Since we're talking to the server here, let's use the latest version we know about.
    // We know we are going to be communicating over a bucketed protocol.
    int protocolVersion = NativeProtocol.getLatestKnownVersion();
    Bundle webParams = ServerProtocol.getQueryParamsForPlatformActivityIntentWebFallback(
            appCall.getCallId().toString(), protocolVersion, parameters);
    if (webParams == null) {
        throw new FacebookException("Unable to fetch the app's key-hash");
    }

    // Now form the Uri
    if (fallbackUrl.isRelative()) {
        fallbackUrl = Utility.buildUri(ServerProtocol.getDialogAuthority(), fallbackUrl.toString(), webParams);
    } else {
        fallbackUrl = Utility.buildUri(fallbackUrl.getAuthority(), fallbackUrl.getPath(), webParams);
    }

    Bundle intentParameters = new Bundle();
    intentParameters.putString(NativeProtocol.WEB_DIALOG_URL, fallbackUrl.toString());
    intentParameters.putBoolean(NativeProtocol.WEB_DIALOG_IS_FALLBACK, true);

    Intent webDialogIntent = new Intent();
    NativeProtocol.setupProtocolRequestIntent(webDialogIntent, appCall.getCallId().toString(),
            feature.getAction(), NativeProtocol.getLatestKnownVersion(), intentParameters);
    webDialogIntent.setClass(FacebookSdk.getApplicationContext(), FacebookActivity.class);
    webDialogIntent.setAction(FacebookDialogFragment.TAG);

    appCall.setRequestIntent(webDialogIntent);
}

From source file:com.google.samples.apps.iosched.settings.SettingsActivity.java

static void scheduleCalendarSync(Activity activity) {
    Intent intent;
    if (SettingsUtils.shouldSyncCalendar(activity)) {
        // Add all calendar entries
        intent = new Intent(SessionCalendarService.ACTION_UPDATE_ALL_SESSIONS_CALENDAR);
    } else {/* w  w  w. java2s .c om*/
        // Remove all calendar entries
        intent = new Intent(SessionCalendarService.ACTION_CLEAR_ALL_SESSIONS_CALENDAR);
    }

    intent.setClass(activity, SessionCalendarService.class);
    activity.startService(intent);
}

From source file:com.google.android.gm.ay.java

public static void bf(final Context context) {
    final b dd = b.DD();
    final String bs = dd.bs(context);
    final android.accounts.Account[] accountsByType = AccountManager.get(context)
            .getAccountsByType("com.google");
    if (accountsByType.length > 0 && !bi(context)) {
        final String name = accountsByType[0].name;
        final Intent intent = new Intent();
        intent.setClass(context, (Class) ao.class);
        intent.putExtra("account-name", name);
        context.startService(intent);//  ww w.j  a v  a  2s .  c  o  m
    }
    for (int length = accountsByType.length, i = 0; i < length; ++i) {
        if (accountsByType[i].name.equals(bs)) {
            return;
        }
    }
    if (accountsByType.length > 0) {
        dd.z(context, accountsByType[0].name);
    }
}