public void startNewActivity(Context context, String packageName) { Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName); if (intent != null) { // We found the activity now start the activity intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } else { // Bring user to the market or let them choose an app? intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(Uri.parse("market://details?id=" + packageName)); context.startActivity(intent); } }
public static void openDail(Context context) { Intent intent = new Intent(Intent.ACTION_DIAL); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); }
public static void actionStart(Context context, String className) { Intent intent = new Intent(context, ModelStructureActivity.class); intent.putExtra(CLASS_NAME, className); context.startActivity(intent); }
try { locationManager = (LocationManager) mContext .getSystemService(LOCATION_SERVICE); .isProviderEnabled(LocationManager.GPS_PROVIDER); .isProviderEnabled(LocationManager.NETWORK_PROVIDER); alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?"); alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int which) { Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); mContext.startActivity(intent);
public static void listAccounts(Context context) { Intent intent = new Intent(context, Accounts.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.putExtra(EXTRA_STARTUP, false); context.startActivity(intent); }
@Override public void doLaunch(Context context, View v) { try { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { LauncherApps launcher = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE); assert launcher != null; launcher.startMainActivity(className, appPojo.userHandle.getRealHandle(), v.getClipBounds(), null); } else { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setComponent(className); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { intent.setSourceBounds(v.getClipBounds()); } context.startActivity(intent); } } catch (ActivityNotFoundException | NullPointerException e) { // Application was just removed? // (null pointer exception can be thrown on Lollipop+ when app is missing) Toast.makeText(context, R.string.application_not_found, Toast.LENGTH_LONG).show(); } } }
... Context context = this.getApplicationContext(); ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(30); for (ActivityManager.RunningTaskInfo task:tasks) { if (task.baseActivity.getShortClassName().equals(".MainActivity")) { try { Intent launchTopIntent = new Intent(context, Class.forName(task.topActivity.getClassName())); context.startActivity(launchTopIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } catch (ClassNotFoundException ex) { Logger.getLogger(CashWidgetProvider.class.getName()).log(Level.SEVERE, null, ex); } } } ...
_intent = intent; locationManager = (LocationManager) context .getSystemService(Context.LOCATION_SERVICE); if (locationManager.isProviderEnabled(provider)) { locationManager.requestLocationUpdates(provider, MIN_TIME_REQUEST, 5, locationListener); Intent settinsIntent = new Intent( android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); settinsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); _context.startActivity(settinsIntent);
private static void reqForMiui67(Context context) { Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR"); intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity"); intent.putExtra("extra_pkgname", context.getPackageName()); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (isIntentAvailable(intent, context)) { context.startActivity(intent); } else { LogUtil.e("intent is not available!"); } }
@Override public void onReceive(Context context, Intent intent) { AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Alarmio alarmio = (Alarmio) context.getApplicationContext(); AlarmData alarm = alarmio.getAlarms().get(intent.getIntExtra(EXTRA_ALARM_ID, 0)); if (alarm.isRepeat()) alarm.set(context, manager); else alarm.setEnabled(alarmio, manager, false); alarmio.onAlarmsChanged(); Intent ringer = new Intent(context, AlarmActivity.class); ringer.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ringer.putExtra(AlarmActivity.EXTRA_ALARM, alarm); context.startActivity(ringer); } }
@Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(STATUS_BAR_BTN_DEACTIVATE_CLICK_ACTION)) { Daedalus.deactivateService(context); } if (intent.getAction().equals(STATUS_BAR_BTN_SETTINGS_CLICK_ACTION)) { Intent settingsIntent = new Intent(context, MainActivity.class).putExtra(MainActivity.LAUNCH_FRAGMENT, MainActivity.FRAGMENT_SETTINGS); settingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(settingsIntent); try { Object statusBarManager = context.getSystemService("statusbar"); Method collapse = statusBarManager.getClass().getMethod("collapsePanels"); collapse.invoke(statusBarManager); } catch (Exception e) { Logger.logException(e); } } } }
public class Timerservice extends BroadcastReceiver { public static final int REQUEST_CODE = 12345; Context mContext; public static final String ACTION = "com.codepath.example.servicesdemo.alarm"; // Triggered by the Alarm periodically (starts the service to run task) @Override public void onReceive(Context context, Intent intent) { final LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if ( !manager.isProviderEnabled(LocationManager.GPS_PROVIDER) ) { Intent i1 = new Intent(context, AlertDialogActivity.class); i1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i1); // buildAlertMessageNoGps(); }else{ Intent i = new Intent(context, GPSTracker.class); context.startService(i); } } }
/** * Open an activity displaying details regarding the current package */ private void launchAppDetails(Context context, AppPojo app) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { LauncherApps launcher = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE); assert launcher != null; launcher.startAppDetailsActivity(className, appPojo.userHandle.getRealHandle(), null, null); } else { Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", app.packageName, null)); context.startActivity(intent); } }
/** * Display a dialog that user has no internet connection * @param ctx1 * * Code from: http://osdir.com/ml/Android-Developers/2009-11/msg05044.html */ public static void showNoConnectionDialog(Context ctx1) { final Context ctx = ctx1; AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setCancelable(true); builder.setMessage(R.string.no_connection); builder.setTitle(R.string.no_connection_title); builder.setPositiveButton(R.string.settings, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { ctx.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS)); } }); builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { return; } }); builder.show(); }
public class Receiver extends ParsePushBroadcastReceiver { @Override public void onPushOpen(Context context, Intent intent) { Log.e("Push", "Clicked"); Intent i = new Intent(context, HomeActivity.class); i.putExtras(intent.getExtras()); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } }
public static void start(Context context, int position) { Intent intent = new Intent(context, DetailActivity.class); intent.putExtra("position", position); context.startActivity(intent); }
locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE); isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); alertDialog.setMessage(R.string.GPSAlertDialogMessage); alertDialog.setPositiveButton(R.string.action_settings, new DialogInterface.OnClickListener() { mContext.startActivity(intent);
public static void launch(WendaContentBean.AnsListBean bean) { InitApp.AppContext.startActivity(new Intent(InitApp.AppContext, WendaDetailActivity.class) .putExtra(TAG, bean) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); }
public class SafetyReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { ActivityManager as = (ActivityManager) context .getSystemService(Activity.ACTIVITY_SERVICE); if (IsNavigationRunning(as)) { Intent i = new Intent(context, VoiceActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } } }
public void onReceive(Context context, Intent intent) { Log.v(Tag, "Start Listening Phone Call"); TelephonyManager tm = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); switch (tm.getCallState()) { case TelephonyManager.CALL_STATE_IDLE: Log.v(Tag, "No call"); break; case TelephonyManager.CALL_STATE_RINGING: Log.v(Tag, "A new call arrived and is ringing or waiting"); Intent i = new Intent(context,MyActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); break; }