List of usage examples for android.content Intent setComponent
public @NonNull Intent setComponent(@Nullable ComponentName component)
From source file:net.sourceforge.kalimbaradio.androidapp.util.NotificationUtil.java
private static RemoteViews createBigContentView(Context context, MusicDirectory.Entry song, Bitmap albumArt, boolean playing) { RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification_expanded); contentView.setTextViewText(R.id.notification_title, song.getTitle()); contentView.setTextViewText(R.id.notification_artist, song.getArtist()); contentView.setTextViewText(R.id.notification_album, song.getAlbum()); contentView.setImageViewBitmap(R.id.notification_image, albumArt); contentView.setImageViewResource(R.id.notification_playpause, playing ? R.drawable.media_pause : R.drawable.media_start); Intent intent = new Intent("1"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); contentView.setOnClickPendingIntent(R.id.notification_playpause, PendingIntent.getService(context, 0, intent, 0)); intent = new Intent("2"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT)); contentView.setOnClickPendingIntent(R.id.notification_next, PendingIntent.getService(context, 0, intent, 0)); intent = new Intent("3"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS)); contentView.setOnClickPendingIntent(R.id.notification_prev, PendingIntent.getService(context, 0, intent, 0)); intent = new Intent("4"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Constants.INTENT_EXTRA_NAME_HIDE_NOTIFICATION, true); contentView.setOnClickPendingIntent(R.id.notification_close, PendingIntent.getService(context, 0, intent, 0)); return contentView; }
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.gcm.MyGCMIntentService.java
public static void generateNotification(Context context) { String message = (String) context.getText(R.string.notification_body); String titleSingle = (String) context.getText(R.string.notification_title_single); String titlePlural = (String) context.getText(R.string.notification_title_plural); String titleFrom = (String) context.getText(R.string.notification_title_from); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher_light) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher)) .setVibrate(new long[] { 0, 1000, 0, 0, 0 }) // {delay, vibrate, sleep, vibrate, sleep} .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); if (newMessagesFromDifferentUsers) { mBuilder.setContentTitle(//from w w w . ja v a 2 s .c o m newMessages + " " + context.getText(R.string.notification_new_messages) + " " + titlePlural) .setContentText(message); } else { NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); if (newMessages == 1) { mBuilder.setContentTitle( newMessages + " " + titleSingle + " " + titleFrom + " " + newMessagePartyName) .setContentText(newMessageContent.get(0)); inboxStyle.setBigContentTitle( newMessages + " " + titleSingle + " " + titleFrom + " " + newMessagePartyName); inboxStyle.addLine(newMessageContent.get(0)); } else { mBuilder.setContentTitle( newMessages + " " + titlePlural + " " + titleFrom + " " + newMessagePartyName) .setContentText(message); inboxStyle.setBigContentTitle( newMessages + " " + titlePlural + " " + titleFrom + " " + newMessagePartyName); for (int i = 0; i < newMessageContent.size(); i++) { inboxStyle.addLine(newMessageContent.get(i)); } if (newMessages > 2) { inboxStyle.addLine((String) context.getText(R.string.notification_dots) + (newMessages - 2) + " " + context.getText(R.string.notification_more_messages) + context.getText(R.string.notification_dots)); } } mBuilder.setStyle(inboxStyle); } int myPackage = context.getResources().getIdentifier(NOTIFICATION_PACKAGE, ConstantKeys.STRING, context.getPackageName()); int myClass = context.getResources().getIdentifier(NOTIFICATION_CLASS, ConstantKeys.STRING, context.getPackageName()); ComponentName c = new ComponentName(context.getString(myPackage), context.getString(myClass)); Intent notificationIntent = new Intent(); notificationIntent.setComponent(c); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); notificationIntent.putExtra(ConstantKeys.NOTIFICATION, newMessageTimelineId); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(intent); NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE); mNotifyMgr.notify(0, mBuilder.build()); }
From source file:be.ac.ucl.lfsab1509.llncampus.ExternalAppUtility.java
/** * Start the Google Maps application and navigate the user to the specified location. * //w ww.j a v a 2 s .c o m * @param lat * Destination latitude. * @param lon * Destination longitude. * @param c * Current context. */ public static void startNavigation(float lat, float lon, Context c) { try { Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?daddr=" + lat + "," + lon + "&dirflg=w")); intent.setComponent( new ComponentName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity")); c.startActivity(intent); } catch (ActivityNotFoundException e) { // If we don't have Google Maps Log.e("ExternalAppUtility", c.getString(R.string.no_google_maps)); Toast t = Toast.makeText(LLNCampus.getContext().getApplicationContext(), R.string.no_google_maps, Toast.LENGTH_LONG); t.setGravity(Gravity.CENTER, 0, 0); t.show(); } }
From source file:net.sourceforge.kalimbaradio.androidapp.util.NotificationUtil.java
private static Notification createCustomNotification(Context context, MusicDirectory.Entry song, boolean playing) { Bitmap albumArt;// ww w. j ava 2 s . co m try { albumArt = FileUtil.getUnscaledAlbumArtBitmap(context, song); if (albumArt == null) { albumArt = Util.decodeBitmap(context, R.drawable.unknown_album_large); } } catch (Exception x) { LOG.warn("Failed to get notification cover art", x); albumArt = Util.decodeBitmap(context, R.drawable.unknown_album_large); } RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification); contentView.setTextViewText(R.id.notification_title, song.getTitle()); contentView.setTextViewText(R.id.notification_artist, song.getArtist()); contentView.setImageViewBitmap(R.id.notification_image, albumArt); contentView.setImageViewResource(R.id.notification_playpause, playing ? R.drawable.media_pause : R.drawable.media_start); Intent intent = new Intent("1"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); contentView.setOnClickPendingIntent(R.id.notification_playpause, PendingIntent.getService(context, 0, intent, 0)); intent = new Intent("2"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT)); contentView.setOnClickPendingIntent(R.id.notification_next, PendingIntent.getService(context, 0, intent, 0)); intent = new Intent("4"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Constants.INTENT_EXTRA_NAME_HIDE_NOTIFICATION, true); contentView.setOnClickPendingIntent(R.id.notification_close, PendingIntent.getService(context, 0, intent, 0)); Intent notificationIntent = new Intent(context, DownloadActivity.class); Notification notification = new NotificationCompat.Builder(context).setOngoing(true) .setSmallIcon(R.drawable.stat_notify_playing).setContent(contentView) .setContentIntent(PendingIntent.getActivity(context, 0, notificationIntent, 0)).build(); if (Build.VERSION.SDK_INT >= 16) { notification.bigContentView = createBigContentView(context, song, albumArt, playing); } return notification; }
From source file:Main.java
public static void startAppByPackageName(Context context, String packageName) { PackageInfo pi = null;//from w ww .j a va2 s . c o m try { pi = context.getPackageManager().getPackageInfo(packageName, 0); } catch (NameNotFoundException e) { e.printStackTrace(); } Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null); resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER); resolveIntent.setPackage(pi.packageName); List<ResolveInfo> apps = context.getPackageManager().queryIntentActivities(resolveIntent, 0); ResolveInfo ri = apps.iterator().next(); if (ri != null) { String packageName1 = ri.activityInfo.packageName; String className = ri.activityInfo.name; Intent intent = new Intent(Intent.ACTION_MAIN); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addCategory(Intent.CATEGORY_LAUNCHER); ComponentName cn = new ComponentName(packageName1, className); intent.setComponent(cn); context.startActivity(intent); } }
From source file:com.nhn.android.archetype.base.AABaseApplicationOrg.java
public static void applicationAllKill() { final ActivityManager am = (ActivityManager) _internalInstance.getSystemService(Activity.ACTIVITY_SERVICE); // stop running service inside current process. List<RunningServiceInfo> serviceList = am.getRunningServices(100); for (RunningServiceInfo service : serviceList) { if (service.pid == android.os.Process.myPid()) { Intent stop = new Intent(); stop.setComponent(service.service); _internalInstance.stopService(stop); }// ww w . ja v a2s. c o m } // move current task to background. Intent launchHome = new Intent(Intent.ACTION_MAIN); launchHome.addCategory(Intent.CATEGORY_DEFAULT); launchHome.addCategory(Intent.CATEGORY_HOME); _internalInstance.startActivity(launchHome); // post delay runnable(waiting for home application launching) new Handler().postDelayed(new Runnable() { public void run() { am.killBackgroundProcesses(_internalInstance.getPackageName()); } }, 2000); }
From source file:Main.java
/** * @param packageName//from w ww . j ava2s . c o m * @param context */ public static void openApp(String packageName, Context context) { Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null); resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER); resolveIntent.setPackage(packageName); List<ResolveInfo> apps = context.getPackageManager().queryIntentActivities(resolveIntent, 0); ResolveInfo ri = apps.iterator().next(); if (ri != null) { String packageName_i = ri.activityInfo.packageName; String className_i = ri.activityInfo.name; Intent intent = new Intent(Intent.ACTION_MAIN); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addCategory(Intent.CATEGORY_LAUNCHER); ComponentName cn = new ComponentName(packageName_i, className_i); intent.setComponent(cn); context.startActivity(intent); } }
From source file:org.restcomm.app.utillib.Utils.Global.java
public static void stopService(Context context) { Intent bgServiceIntent = new Intent(); bgServiceIntent .setComponent(new ComponentName(context.getPackageName(), "com.cortxt.app.corelib.MainService")); context.startService(bgServiceIntent); }
From source file:com.mobilesolutionworks.android.httpcache.HttpCacheLoaderImpl.java
public static Intent createExplicitFromImplicitIntent(Context context, Intent implicitIntent) { // Retrieve all services that can match the given intent PackageManager pm = context.getPackageManager(); List<ResolveInfo> resolveInfo = pm.queryIntentServices(implicitIntent, 0); // Make sure only one match was found if (resolveInfo == null || resolveInfo.size() != 1) { return null; }/*from w w w. j ava2s. com*/ // Get component info and create ComponentName ResolveInfo serviceInfo = resolveInfo.get(0); String packageName = serviceInfo.serviceInfo.packageName; String className = serviceInfo.serviceInfo.name; ComponentName component = new ComponentName(packageName, className); // Create a new intent. Use the old one for extras and such reuse Intent explicitIntent = new Intent(implicitIntent); // Set the component to be explicit explicitIntent.setComponent(component); return explicitIntent; }
From source file:nl.sogeti.android.gpstracker.integration.GPSLoggerServiceManager.java
@NonNull private static Intent createServiceIntent() { Intent intent = new Intent(); intent.setComponent(new ComponentName("nl.sogeti.android.gpstracker", "nl.sogeti.android.gpstracker.service.logger.GPSLoggerService")); return intent; }