List of usage examples for android.content Intent setComponent
public @NonNull Intent setComponent(@Nullable ComponentName component)
From source file:org.restcomm.app.utillib.Utils.Global.java
public static void startService(Context context, boolean bUI) { String packagename = context.getPackageName(); // See if this app is yeilded to another app if (bUI) {//from ww w. j a v a 2 s.c om PreferenceManager.getDefaultSharedPreferences(context).edit() .putString(PreferenceKeys.Miscellaneous.YEILDED_SERVICE, packagename).commit(); Intent intent = new Intent(CommonIntentActionsOld.ACTION_START_UI); intent.putExtra("packagename", packagename); context.sendBroadcast(intent); } if (!isServiceYeilded(context)) { Intent bgServiceIntent = new Intent(); //bgServiceIntent.setComponent(new ComponentName(context.getPackageName(), "com.cortxt.app.corelib.MainService")); bgServiceIntent.setComponent( new ComponentName(context.getPackageName(), "org.restcomm.app.qoslib.MainService")); LoggerUtil.logToFile(LoggerUtil.Level.ERROR, "Global", "isServiceYeilded", "MMC Service started for " + packagename); context.startService(bgServiceIntent); } }
From source file:com.pdftron.pdf.utils.ViewerUtils.java
public static Uri openImageIntent(Fragment fragment, int requestCode) { // Determine Uri of camera image to save. final String fname = "IMG_" + System.currentTimeMillis() + ".jpg"; File sdImageMainDirectory = new File(fragment.getActivity().getExternalCacheDir(), fname); Uri outputFileUri = Uri.fromFile(sdImageMainDirectory); // Camera.//from w w w . j a v a 2s . c o m final List<Intent> cameraIntents = new ArrayList<>(); final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); final PackageManager packageManager = fragment.getActivity().getPackageManager(); final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0); for (ResolveInfo res : listCam) { final String packageName = res.activityInfo.packageName; final Intent intent = new Intent(captureIntent); intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); intent.setPackage(packageName); intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); cameraIntents.add(intent); } // Filesystem. final Intent galleryIntent = new Intent(Intent.ACTION_PICK); galleryIntent.setType("image/*"); //galleryIntent.setAction(Intent.ACTION_GET_CONTENT); // Chooser of filesystem options. final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source"); // Add the camera options. chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {})); fragment.startActivityForResult(chooserIntent, requestCode); return outputFileUri; }
From source file:org.c99.wear_imessage.GCMIntentService.java
public static void notify(Context context, int notification_id, JSONArray msgs, Intent intent, boolean updateOnly) throws JSONException { String lastMsg = intent.getStringExtra("msg"); Spanned msg;/*w w w . j a va 2 s. c om*/ String name = intent.getStringExtra("name"); if (name.contains(" ")) name = name.substring(0, name.indexOf(" ")); StringBuilder sb = new StringBuilder(); for (int i = 0; i < msgs.length(); i++) { if (sb.length() > 0) sb.append("<br/><br/>"); String body; String from = name; try { JSONObject o = msgs.getJSONObject(i); body = o.getString("msg"); if (o.has("type")) { if (o.getString("type").equals("file") || o.getString("type").equals("sent_file")) body = "[File: " + o.getString("msg") + "]"; if (o.getString("type").equals("sent") || o.getString("type").equals("sent_file")) from = "Me"; else lastMsg = body; } else { from = name; lastMsg = body; } } catch (JSONException e1) { from = name; body = msgs.getString(i); lastMsg = body; } sb.append("<b>").append(Html.escapeHtml(from)).append(":</b> ").append(Html.escapeHtml(body)); } msg = Html.fromHtml(sb.toString()); int msg_count = msgs.length(); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setAutoCancel(true); if (name.length() > 0) { builder.setSmallIcon(R.drawable.ic_notification).setContentTitle(intent.getStringExtra("name")) .setContentText(lastMsg).setNumber(msg_count); } if (updateOnly) { builder.setVibrate(null); } else { builder.setPriority(NotificationCompat.PRIORITY_HIGH); builder.setTicker(Html.fromHtml("<b>" + Html.escapeHtml(intent.getStringExtra("name")) + ":</b> " + Html.escapeHtml(intent.getStringExtra("msg")))).setDefaults(Notification.DEFAULT_ALL); } NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(); style.bigText(lastMsg); builder.setStyle(style); NotificationCompat.WearableExtender extender = new NotificationCompat.WearableExtender(); if (ENABLE_REPLIES) { Intent replyIntent = new Intent(RemoteInputService.ACTION_REPLY); replyIntent .setComponent(new ComponentName(context.getPackageName(), RemoteInputService.class.getName())); replyIntent.putExtras(intent.getExtras()); replyIntent.putExtra("notification_id", notification_id); PendingIntent replyPendingIntent = PendingIntent.getService(context, notification_id + 1, replyIntent, PendingIntent.FLAG_CANCEL_CURRENT); extender.addAction( new NotificationCompat.Action.Builder(R.drawable.ic_reply, "Reply", replyPendingIntent) .addRemoteInput(new RemoteInput.Builder("extra_reply").setLabel("Reply").build()) .build()); Intent launchIntent = new Intent(context, QuickReplyActivity.class); launchIntent.putExtras(intent.getExtras()); launchIntent.putExtra("notification_id", notification_id); builder.setContentIntent(PendingIntent.getActivity(context, notification_id + 2, launchIntent, PendingIntent.FLAG_CANCEL_CURRENT)); builder.addAction(R.drawable.ic_action_reply, "Reply", PendingIntent.getActivity(context, notification_id + 3, launchIntent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT)); } if (msg_count > 1) extender.addPage(new NotificationCompat.Builder(context).setContentText(msg) .extend(new NotificationCompat.WearableExtender().setStartScrollBottom(true)).build()); Cursor c = null; if (intent.getStringExtra("handle").contains("@")) c = context.getContentResolver().query(ContactsContract.Data.CONTENT_URI, new String[] { ContactsContract.Data.CONTACT_ID }, ContactsContract.CommonDataKinds.Email.ADDRESS + "=?" + " AND " + ContactsContract.Data.MIMETYPE + "=?", new String[] { intent.getStringExtra("handle"), ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE }, null); if (c != null && c.moveToFirst()) { long contactId = c.getLong(0); c.close(); Bitmap b = BitmapFactory.decodeStream( ContactsContract.Contacts.openContactPhotoInputStream(context.getContentResolver(), ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId), true)); if (b != null) { builder.setLargeIcon(b); extender.setBackground(b); } } NotificationManagerCompat m = NotificationManagerCompat.from(context); m.notify(notification_id, builder.extend(extender).build()); }
From source file:cn.whereyougo.framework.utils.PackageManagerUtil.java
/** * /* w w w. j ava 2s. c om*/ * * @param context */ public static void exitApp(final Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (context.getPackageName().equals(service.service.getPackageName())) { Intent stopIntent = new Intent(); ComponentName serviceCMP = service.service; stopIntent.setComponent(serviceCMP); context.stopService(stopIntent); break; } } android.os.Process.killProcess(android.os.Process.myPid()); System.exit(0); }
From source file:github.daneren2005.dsub.util.Notifications.java
private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean expanded, boolean playing, boolean remote) { // Use the same text for the ticker and the expanded notification String title = song.getTitle(); String arist = song.getArtist(); String album = song.getAlbum(); // Set the album art. try {// w ww . j a va2s. c o m ImageLoader imageLoader = SubsonicActivity.getStaticImageLoader(context); Bitmap bitmap = null; if (imageLoader != null) { bitmap = imageLoader.getCachedImage(context, song, false); } if (bitmap == null) { // set default album art rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } else { rv.setImageViewBitmap(R.id.notification_image, bitmap); } } catch (Exception x) { Log.w(TAG, "Failed to get notification cover art", x); rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } // set the text for the notifications rv.setTextViewText(R.id.notification_title, title); rv.setTextViewText(R.id.notification_artist, arist); rv.setTextViewText(R.id.notification_album, album); boolean persistent = Util.getPreferences(context) .getBoolean(Constants.PREFERENCES_KEY_PERSISTENT_NOTIFICATION, false); if (persistent) { if (expanded) { rv.setImageViewResource(R.id.control_pause, playing ? R.drawable.notification_pause : R.drawable.notification_start); } else { rv.setImageViewResource(R.id.control_previous, playing ? R.drawable.notification_pause : R.drawable.notification_start); rv.setImageViewResource(R.id.control_pause, R.drawable.notification_forward); rv.setImageViewResource(R.id.control_next, R.drawable.notification_close); } } // Create actions for media buttons PendingIntent pendingIntent; int previous = 0, pause = 0, next = 0, close = 0; if (persistent && !expanded) { pause = R.id.control_previous; next = R.id.control_pause; close = R.id.control_next; } else { previous = R.id.control_previous; pause = R.id.control_pause; next = R.id.control_next; } if ((remote || persistent) && close == 0 && expanded) { close = R.id.notification_close; rv.setViewVisibility(close, View.VISIBLE); } if (previous > 0) { Intent prevIntent = new Intent("KEYCODE_MEDIA_PREVIOUS"); prevIntent.setComponent(new ComponentName(context, DownloadService.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(previous, pendingIntent); } if (pause > 0) { if (playing) { Intent pauseIntent = new Intent("KEYCODE_MEDIA_PLAY_PAUSE"); pauseIntent.setComponent(new ComponentName(context, DownloadService.class)); pauseIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); pendingIntent = PendingIntent.getService(context, 0, pauseIntent, 0); rv.setOnClickPendingIntent(pause, pendingIntent); } else { Intent prevIntent = new Intent("KEYCODE_MEDIA_START"); prevIntent.setComponent(new ComponentName(context, DownloadService.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(pause, pendingIntent); } } if (next > 0) { Intent nextIntent = new Intent("KEYCODE_MEDIA_NEXT"); nextIntent.setComponent(new ComponentName(context, DownloadService.class)); nextIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT)); pendingIntent = PendingIntent.getService(context, 0, nextIntent, 0); rv.setOnClickPendingIntent(next, pendingIntent); } if (close > 0) { Intent prevIntent = new Intent("KEYCODE_MEDIA_STOP"); prevIntent.setComponent(new ComponentName(context, DownloadService.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_STOP)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(close, pendingIntent); } }
From source file:cz.maresmar.sfm.service.plugin.PluginUtils.java
/** * Prepares plugin intent from plugin name * @param plugin Name of plugin/*from www . j a v a 2s.c om*/ * @return Intent that can start plugin * @see #startPlugin(Context, Intent) */ @NonNull public static Intent buildPluginIntent(@NonNull String plugin) { // Creates the intent Intent intent = new Intent(); ComponentName componentName = PublicProviderContract.parsePluginText(plugin); // Test result validity if (componentName == null) { Timber.e("Plugin name \"%s\" is badly formatted", plugin); throw new IllegalArgumentException("Plugin name is badly formatted " + plugin); } // Explicitly select service to communicate with intent.setComponent(componentName); return intent; }
From source file:com.android.tv.tuner.setup.TunerSetupActivity.java
/** * Returns a {@link Intent} to launch the tuner TV input service. * * @param context a {@link Context} instance *//*from www.ja va 2 s . c om*/ public static Intent createSetupActivity(Context context) { String inputId = TvContract .buildInputId(new ComponentName(context.getPackageName(), TunerTvInputService.class.getName())); // Make an intent to launch the setup activity of TV tuner input. Intent intent = TvCommonUtils.createSetupIntent(new Intent(context, TunerSetupActivity.class), inputId); intent.putExtra(TvCommonConstants.EXTRA_INPUT_ID, inputId); Intent tvActivityIntent = new Intent(); tvActivityIntent.setComponent(new ComponentName(context, TV_ACTIVITY_CLASS_NAME)); intent.putExtra(TvCommonConstants.EXTRA_ACTIVITY_AFTER_COMPLETION, tvActivityIntent); return intent; }
From source file:br.org.funcate.dynamicforms.markers.MarkersUtilities.java
private static Intent prepareIntent(Context context, File image, double[] gpsLocation) { Intent sketchIntent = null; if (MARKERS_IS_INTEGRATED) { try {/* w ww. j ava 2 s. c o m*/ sketchIntent = new Intent(context, Class.forName(APP_MAIN_ACTIVITY)); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } else { sketchIntent = new Intent(); sketchIntent.setComponent( new ComponentName(MarkersUtilities.APP_PACKAGE, MarkersUtilities.APP_MAIN_ACTIVITY)); } sketchIntent.putExtra(MarkersUtilities.EXTRA_KEY, image.getAbsolutePath()); if (gpsLocation != null) { sketchIntent.putExtra(LibraryConstants.LATITUDE, gpsLocation[1]); sketchIntent.putExtra(LibraryConstants.LONGITUDE, gpsLocation[0]); sketchIntent.putExtra(LibraryConstants.ELEVATION, gpsLocation[2]); } return sketchIntent; }
From source file:at.diamonddogs.util.Utils.java
/** * Brings up the MAIN/LAUNCHER activity and clears the top * * @param context a {@link Context}//from ww w . jav a2 s . c o m */ public static void returnToHome(Context context) { PackageManager pm = context.getPackageManager(); Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setPackage(context.getPackageName()); List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0); Intent homeIntent = new Intent("android.intent.action.MAIN"); homeIntent.addCategory("android.intent.category.LAUNCHER"); homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); homeIntent.setComponent(new ComponentName(context.getPackageName(), activities.get(0).activityInfo.name)); context.startActivity(homeIntent); }
From source file:com.mods.grx.settings.utils.Utils.java
public static boolean is_activity_installed(Context context, String packagename, String activityname) { boolean t = false; try {/*from ww w . ja v a 2 s.c om*/ ComponentName componentName = new ComponentName(packagename, activityname); Intent intent = new Intent(); intent.setComponent(componentName); ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(intent, 0); if (resolveInfo != null) t = true; } catch (Exception e) { } return t; }