List of usage examples for android.content Intent setFlags
public @NonNull Intent setFlags(@Flags int flags)
From source file:net.ben.subsonic.androidapp.util.Util.java
public static void showErrorNotification(final Context context, Handler handler, String title, Exception error) {//from w w w . j av a2 s. c om final NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); StringBuilder text = new StringBuilder(); if (error.getMessage() != null) { text.append(error.getMessage()).append(" ("); } text.append(error.getClass().getSimpleName()); if (error.getMessage() != null) { text.append(")"); } // Set the icon, scrolling text and timestamp final Notification notification = new Notification(android.R.drawable.stat_sys_warning, title, System.currentTimeMillis()); notification.flags |= Notification.FLAG_AUTO_CANCEL; // The PendingIntent to launch our activity if the user selects this notification Intent intent = new Intent(context, ErrorActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(Constants.INTENT_EXTRA_NAME_ERROR, title + ".\n\n" + text); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, title, text, contentIntent); // Send the notification. handler.post(new Runnable() { @Override public void run() { notificationManager.cancel(Constants.NOTIFICATION_ID_ERROR); notificationManager.notify(Constants.NOTIFICATION_ID_ERROR, notification); } }); }
From source file:Main.java
private static void shareImageOnFacebook(String imagePath, Context context) { Log.d("CitationsManager-ShareOnFb", "sharing the image " + imagePath); Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); shareIntent.setType("image/*"); // shareIntent.putExtra(Intent.EXTRA_TEXT, "www.google.com"); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imagePath))); PackageManager pm = context.getPackageManager(); List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0); for (final ResolveInfo app : activityList) { Log.d("CitationsManager-ShareOnFb", app.activityInfo.name); if ((app.activityInfo.name).contains("com.facebook") && !(app.activityInfo.name).contains("messenger") && !(app.activityInfo.name).contains("pages")) { final ActivityInfo activity = app.activityInfo; final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name); shareIntent.addCategory(Intent.CATEGORY_LAUNCHER); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP); shareIntent.setComponent(name); context.startActivity(shareIntent); break; }/* w ww . j ava 2s.c o m*/ } }
From source file:com.farmerbb.secondscreen.util.U.java
public static void checkForUpdates(Context context) { // If Google Play Store is installed, direct the user to the Play Store page for SecondScreen. // Otherwise, direct them to the Downloads page on the xda thread. String url;/*w w w . ja va 2s.c o m*/ try { context.getPackageManager().getPackageInfo("com.android.vending", 0); url = "https://play.google.com/store/apps/details?id=" + context.getPackageName(); } catch (PackageManager.NameNotFoundException e) { url = "http://forum.xda-developers.com/devdb/project/?id=5032#downloads"; } Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); }
From source file:br.com.arlsoft.pushclient.PushClientModule.java
public static Intent getLauncherIntent(Bundle extras) { TiApplication appContext = TiApplication.getInstance(); PackageManager pm = appContext.getPackageManager(); Intent launch = pm.getLaunchIntentForPackage(appContext.getPackageName()); launch.addCategory(Intent.CATEGORY_LAUNCHER); launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (extras != null && !extras.isEmpty()) { launch.putExtra(PROPERTY_EXTRAS, extras); }/*w ww. j a va 2 s.c o m*/ return launch; }
From source file:com.example.util.Utils.java
/** * Android /*from w w w. ja v a2 s.c o m*/ * * @param context Application Context * @param filePath APK */ public static void installApk(Context context, File file) { if (file.exists()) { Intent i = new Intent(Intent.ACTION_VIEW); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); ((ContextWrapper) context).startActivity(i); } else { //makeEventToast(context, context.getString(R.string.install_fail_file_not_exist), false); } }
From source file:com.mappn.gfan.common.util.Utils.java
/** * Android /*w w w .j av a 2 s . co m*/ * * @param context Application Context * @param filePath APK */ public static void installApk(Context context, File file) { if (file.exists()) { Intent i = new Intent(Intent.ACTION_VIEW); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); ((ContextWrapper) context).startActivity(i); } else { makeEventToast(context, context.getString(R.string.install_fail_file_not_exist), false); } }
From source file:cn.ttyhuo.view.UserView.java
/** * //from w w w . j a v a 2 s . c o m * @param context * @param activityTitle Activity?? * @param msgTitle ? * @param msgText ? * @param imgPath ?null */ public static void shareMsg(Context context, String activityTitle, String msgTitle, String msgText, File f) { Intent intent = new Intent(Intent.ACTION_SEND); if (f == null || !f.exists() || !f.isFile()) { intent.setType("text/plain"); // } else { intent.setType("image/png"); Uri u = Uri.fromFile(f); //Uri u = Uri.parse(imgPath); intent.putExtra(Intent.EXTRA_STREAM, u); } intent.putExtra(Intent.EXTRA_SUBJECT, msgTitle); intent.putExtra(Intent.EXTRA_TEXT, msgText); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(Intent.createChooser(intent, activityTitle)); }
From source file:com.danielhalupka.imageviewer.ImageViewer.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { try {//from w w w.jav a 2 s . c o m if (ACTION_VIEW_IMAGE.equals(action)) { JSONObject arg_object = args.getJSONObject(0); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); String filePath = arg_object.getString("filepath"); intent.setDataAndType(Uri.parse(filePath), "image/*"); this.cordova.getActivity().startActivity(intent); callbackContext.success(); return true; } callbackContext.error("Invalid action"); return false; } catch (JSONException e) { System.err.println("Exception: " + e.getMessage()); callbackContext.error(e.getMessage()); return false; } }
From source file:com.farmerbb.secondscreen.util.U.java
public static String uiRefreshCommand2(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); // For better reliability, we execute the UI refresh while on the home screen Intent homeIntent = new Intent(Intent.ACTION_MAIN); homeIntent.addCategory(Intent.CATEGORY_HOME); homeIntent.addCategory(Intent.CATEGORY_DEFAULT); homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(homeIntent);/* w ww .ja v a 2s .c o m*/ // Kill all background processes, in order to fully refresh UI PackageManager pm = context.getPackageManager(); List<ApplicationInfo> packages = pm.getInstalledApplications(0); for (ApplicationInfo packageInfo : packages) { if (!packageInfo.packageName.equalsIgnoreCase(context.getPackageName())) am.killBackgroundProcesses(packageInfo.packageName); } // Get launcher package name final ResolveInfo mInfo = pm.resolveActivity(homeIntent, 0); return "sleep 1 && am force-stop " + mInfo.activityInfo.applicationInfo.packageName; }
From source file:com.vrem.wifianalyzer.navigation.items.ExportItem.java
private Intent createIntent(String title, String data) { Intent intent = createSendIntent(); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TITLE, title); intent.putExtra(Intent.EXTRA_SUBJECT, title); intent.putExtra(Intent.EXTRA_TEXT, data); return intent; }