List of usage examples for android.content Intent setAction
public @NonNull Intent setAction(@Nullable String action)
From source file:Main.java
private static Intent intentFromString(StringBuilder s) { CharSequence prefix = extract(s); Intent intent = null; if (prefix != null) { try {/*from w w w. j a v a2 s.com*/ String action = toString(extract(s)); String uri = toString(extract(s)); intent = Intent.parseUri(uri, Intent.URI_INTENT_SCHEME); intent.setAction(action); } catch (URISyntaxException e) { e.printStackTrace(); } } return intent; }
From source file:com.android.launcher4.InstallShortcutReceiver.java
private static ShortcutInfo getShortcutInfo(Context context, Intent data, Intent launchIntent) { if (launchIntent.getAction() == null) { launchIntent.setAction(Intent.ACTION_VIEW); } else if (launchIntent.getAction().equals(Intent.ACTION_MAIN) && launchIntent.getCategories() != null && launchIntent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) { launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); }// w w w . ja va 2 s .c o m LauncherAppState app = LauncherAppState.getInstance(); ShortcutInfo info = app.getModel().infoFromShortcutIntent(context, data, null); info.title = ensureValidName(context, launchIntent, info.title); return info; }
From source file:com.hippo.ehviewer.ui.CommonOperations.java
public static void startDownload(final MainActivity activity, final GalleryInfo galleryInfo, boolean forceDefault) { final DownloadManager dm = EhApplication.getDownloadManager(activity); boolean justStart = forceDefault || dm.containDownloadInfo(galleryInfo.gid); String label = null;/*from w ww . j a v a 2 s . c o m*/ // Get default download label if (!justStart && Settings.getHasDefaultDownloadLabel()) { label = Settings.getDefaultDownloadLabel(); justStart = label == null || dm.containLabel(label); } // If there is no other label, just use null label if (!justStart && 0 == dm.getLabelList().size()) { justStart = true; label = null; } if (justStart) { // Already in download list or get default label Intent intent = new Intent(activity, DownloadService.class); intent.setAction(DownloadService.ACTION_START); intent.putExtra(DownloadService.KEY_LABEL, label); intent.putExtra(DownloadService.KEY_GALLERY_INFO, galleryInfo); activity.startService(intent); // Notify activity.showTip(R.string.added_to_download_list, BaseScene.LENGTH_SHORT); } else { // Let use chose label List<DownloadLabel> list = dm.getLabelList(); final String[] items = new String[list.size() + 1]; items[0] = activity.getString(R.string.default_download_label_name); for (int i = 0, n = list.size(); i < n; i++) { items[i + 1] = list.get(i).getLabel(); } new ListCheckBoxDialogBuilder(activity, items, new ListCheckBoxDialogBuilder.OnItemClickListener() { @Override public void onItemClick(ListCheckBoxDialogBuilder builder, AlertDialog dialog, int position) { String label; if (position == 0) { label = null; } else { label = items[position]; if (!dm.containLabel(label)) { label = null; } } // Start download Intent intent = new Intent(activity, DownloadService.class); intent.setAction(DownloadService.ACTION_START); intent.putExtra(DownloadService.KEY_LABEL, label); intent.putExtra(DownloadService.KEY_GALLERY_INFO, galleryInfo); activity.startService(intent); // Save settings if (builder.isChecked()) { Settings.putHasDefaultDownloadLabel(true); Settings.putDefaultDownloadLabel(label); } else { Settings.putHasDefaultDownloadLabel(false); } // Notify activity.showTip(R.string.added_to_download_list, BaseScene.LENGTH_SHORT); } }, activity.getString(R.string.remember_download_label), false).setTitle(R.string.download).show(); } }
From source file:st.brothas.mtgoxwidget.MtGoxWidgetProvider.java
static void updateAppWidget(final Context context, AppWidgetManager appWidgetManager, int appWidgetId) { WidgetPreferences preferences = MtGoxPreferencesActivity.getWidgetPreferences(context, appWidgetId); if (preferences == null) { // Don't do anything unless the rate service has been chosen. // Show a "please remove this widget and add a new one" appWidgetManager.updateAppWidget(appWidgetId, new RemoteViews(context.getPackageName(), R.layout.appwidget_replace_me)); return;/*from w w w .j av a 2 s. c om*/ } RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider); Intent clickIntent = new Intent(context, GraphPopupActivity.class); clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); clickIntent.setAction("dummyAction"); // Needed to get the extra variables included in the call // Note: the appWidgetId needs to be sent in the pendingIntent as request code, otherwise only ONE // cached intent will be used for all widget instances! PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, clickIntent, 0); views.setOnClickPendingIntent(R.id.appwidget_box, pendingIntent); views.setTextViewText(R.id.appwidget_service_name, preferences.getRateService().getName()); MtGoxDataOpenHelper dbHelper = new MtGoxDataOpenHelper(context); MtGoxTickerData prevData = dbHelper.getLastTickerData(preferences); MtGoxTickerData newData; JSONObject latestQuoteJSON = getLatestQuoteJSON(preferences); if (latestQuoteJSON != null) { newData = preferences.getRateService().parseJSON(latestQuoteJSON); newData.setCurrencyConversion(preferences.getCurrencyConversion()); storeLastValueIfNotNull(dbHelper, newData); updateViews(views, prevData, newData, preferences); } else if (prevData != null) { newData = prevData; updateViews(views, prevData, newData, preferences); } else { updateViewsWithError(views, preferences); } appWidgetManager.updateAppWidget(appWidgetId, views); }
From source file:cn.apputest.ctria.service.UploadFailRecordService.java
public static void setServiceAlarm(Context context) { Log.i("ServiceUtil-AlarmManager", "invokeTimerPOIService wac called.."); PendingIntent alarmSender = null;//from ww w .j a v a 2s .com Intent startIntent = new Intent(context, UploadFailRecordService.class); startIntent.setAction(Constants.POI_SERVICE_ACTION); try { alarmSender = PendingIntent.getService(context, 0, startIntent, PendingIntent.FLAG_UPDATE_CURRENT); } catch (Exception e) { Log.i("ServiceUtil-AlarmManager", "failed to start " + e.toString()); } AlarmManager am = (AlarmManager) context.getSystemService(Activity.ALARM_SERVICE); am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), Constants.ELAPSED_TIME_F, alarmSender); }
From source file:com.krayzk9s.imgurholo.tools.ImageUtils.java
public static void gotoUser(android.support.v4.app.Fragment fragment, JSONParcelable imageData) { try {/*from w ww . java 2 s .c o m*/ Intent intent = new Intent(); intent.putExtra("username", imageData.getJSONObject().getString("account_url")); intent.setAction(ImgurHoloActivity.ACCOUNT_INTENT); intent.addCategory(Intent.CATEGORY_DEFAULT); fragment.startActivity(intent); } catch (JSONException e) { Log.e("Error!", e.toString()); } }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppStateObj.java
public static Intent getLaunchIntent(Context context, SignedObj obj) { JSONObject content = obj.getJson();/*w ww . j ava2 s.com*/ if (DBG) Log.d(TAG, "Getting launch intent for " + content); Uri appFeed; if (content.has(DbObject.CHILD_FEED_NAME)) { Log.d(TAG, "using child feed"); appFeed = Feed.uriForName(content.optString(DbObject.CHILD_FEED_NAME)); } else { Log.d(TAG, "using obj feed"); appFeed = Feed.uriForName(content.optString(DbObjects.FEED_NAME)); } String arg = content.optString(ARG); String state = content.optString(STATE); String appId = obj.getAppId(); // TODO: Hack for deprecated launch method if (appId.equals(DungBeetleContentProvider.SUPER_APP_ID)) { appId = content.optString(PACKAGE_NAME); } if (DBG) Log.d(TAG, "Preparing launch of " + appId + " on " + appFeed); Intent launch = new Intent(); if (content.has(AppReferenceObj.OBJ_INTENT_ACTION)) { launch.setAction(content.optString(AppReferenceObj.OBJ_INTENT_ACTION)); } else { launch.setAction(Intent.ACTION_MAIN); } if (state != null) { launch.putExtra("mobisocial.db.STATE", state); } launch.addCategory(Intent.CATEGORY_LAUNCHER); launch.putExtra(AppState.EXTRA_FEED_URI, appFeed); // TODO: hack until this obj is available in 'related' query. launch.putExtra("obj", content.toString()); // TODO: this is better. launch.putExtra(Musubi.EXTRA_OBJ_HASH, obj.getHash()); if (arg != null) { launch.putExtra(AppState.EXTRA_APPLICATION_ARGUMENT, arg); } // TODO: optimize! List<ResolveInfo> resolved = context.getPackageManager().queryIntentActivities(launch, 0); for (ResolveInfo r : resolved) { ActivityInfo activity = r.activityInfo; if (activity.packageName.equals(appId)) { launch.setClassName(activity.packageName, activity.name); launch.putExtra("mobisocial.db.PACKAGE", activity.packageName); return launch; } } Intent market = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appId)); return market; }
From source file:cn.whereyougo.framework.utils.PackageManagerUtil.java
/** * ????//from w w w .j ava 2 s. c o m * * @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.bt.download.android.gui.util.UIUtils.java
/** * Checks setting to show or not the transfers window right after a download has started. * This should probably be moved elsewhere (similar to GUIMediator on the desktop) * @param activity/* www . j a v a 2 s .c o m*/ */ public static void showTransfersOnDownloadStart(Context context) { if (ConfigurationManager.instance().showTransfersOnDownloadStart() && context != null) { Intent i = new Intent(context, MainActivity.class); i.setAction(Constants.ACTION_SHOW_TRANSFERS); i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); context.startActivity(i); } }
From source file:org.c99.SyncProviderDemo.ContactsSyncAdapterService.java
private static void generateNotification(Noticia noticia, Context context) { NotificationManager mNotificationManager; int numMessages = 0; Log.i("Start", "notification"); /* Invoking the default notification service */ NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context); mBuilder.setContentTitle("Nova noticia"); mBuilder.setContentText(noticia.getAssunto()); mBuilder.setTicker("Noticia !!!"); mBuilder.setSmallIcon(R.drawable.logo); /* Increase notification number every time a new notification arrives */ mBuilder.setNumber(++numMessages);//from w w w . j a v a 2s .c o m /* Creates an explicit intent for an Activity in your app */ Intent resultIntent = new Intent(context, NavigationDrawer.class); resultIntent.setAction("NOTICIA"); //tentando linkar Bundle bundle = new Bundle(); bundle.putSerializable("noticia", noticia); resultIntent.putExtras(bundle); // fim arrumar a inteao TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(NavigationDrawer.class); /* Adds the Intent that starts the Activity to the top of the stack */ stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mNotificationManager = // (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // (NotificationManager) getActivity().getApplication(). // getSystemService(getActivity().getApplication().NOTIFICATION_SERVICE); // (NotificationManager) getContext().getSystemService(getContext().NOTIFICATION_SERVICE); // (NotificationManager) getSystemService(NOTIFICATION_SERVICE); (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE); /* notificationID allows you to update the notification later on. */ mNotificationManager.notify(noticia.getCodigo(), mBuilder.build()); }