List of usage examples for android.content Intent getComponent
public @Nullable ComponentName getComponent()
From source file:io.nuclei.cyto.share.PackageTargetManager.java
/** * Send the startActivityForResult intent to an activity * * @param requestCode The request code to listen to in the onActivityResult */// w w w . j a v a 2s. c om public void onShare(Activity activity, Intent intent, int requestCode) { if (mWeights == null) mWeights = activity.getSharedPreferences(DEFAULT_SHARE_WEIGHTS, Context.MODE_PRIVATE); int weight = mWeights.getInt(intent.getComponent().getClassName(), 0) + 1; mWeights.edit().putInt(intent.getComponent().getClassName(), weight).apply(); activity.startActivityForResult(intent, requestCode); }
From source file:io.nuclei.cyto.share.PackageTargetManager.java
/** * Send the startActivityForResult intent to an activity * * @param requestCode The request code to listen to in the onActivityResult *//*from ww w .j a va2 s. c o m*/ public void onShare(Fragment fragment, Intent intent, int requestCode) { if (mWeights == null) mWeights = fragment.getActivity().getSharedPreferences(DEFAULT_SHARE_WEIGHTS, Context.MODE_PRIVATE); int weight = mWeights.getInt(intent.getComponent().getClassName(), 0) + 1; mWeights.edit().putInt(intent.getComponent().getClassName(), weight).apply(); fragment.startActivityForResult(intent, requestCode); }
From source file:com.parse.ParsePushBroadcastReceiver.java
/** * Used by {@link #onPushOpen} to determine which activity to launch or insert into the back * stack. The default implementation retrieves the launch activity class for the package. * * @param context//from w w w. j a v a2 s. c o m * The {@code Context} in which the receiver is running. * @param intent * An {@code Intent} containing the channel and data of the current push notification. * @return * The default {@code Activity} class of the package or {@code null} if no launch intent is * defined in {@code AndroidManifest.xml}. */ protected Class<? extends Activity> getActivity(Context context, Intent intent) { String packageName = context.getPackageName(); Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName); if (launchIntent == null) { return null; } String className = launchIntent.getComponent().getClassName(); Class<? extends Activity> cls = null; try { cls = (Class<? extends Activity>) Class.forName(className); } catch (ClassNotFoundException e) { // do nothing } return cls; }
From source file:com.allthatseries.RNAudioPlayer.MediaNotificationManager.java
private Notification createNotification() { if (mMetadata == null || mPlaybackState == null) { return null; }/*from w ww . ja v a2 s. c o m*/ NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService); int playPauseButtonPosition = 0; // If skip to previous action is enabled if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) { notificationBuilder.addAction(R.drawable.ic_skip_previous_white_24dp, "previous", mPreviousIntent); // If there is a "skip to previous" button, the play/pause button will // be the second one. We need to keep track of it, because the MediaStyle notification // requires to specify the index of the buttons (actions) that should be visible // when in compact view. playPauseButtonPosition = 1; } addPlayPauseAction(notificationBuilder); // If skip to next action is enabled if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) { notificationBuilder.addAction(R.drawable.ic_skip_next_white_24dp, "next", mNextIntent); } MediaDescriptionCompat description = mMetadata.getDescription(); String fetchArtUrl = null; Bitmap art = null; if (description.getIconUri() != null) { // This sample assumes the iconUri will be a valid URL formatted String, but // it can actually be any valid Android Uri formatted String. // async fetch the album art icon String artUrl = description.getIconUri().toString(); art = AlbumArtCache.getInstance().getBigImage(artUrl); if (art == null) { fetchArtUrl = artUrl; // use a placeholder art while the remote art is being downloaded art = BitmapFactory.decodeResource(mService.getResources(), R.drawable.ic_default_art); } } // Basically we use notification icon but it doesn't exist we use launcher icon Context context = mService.getApplicationContext(); int resId = context.getResources().getIdentifier("ic_notification", "drawable", context.getPackageName()); if (resId == 0) { resId = context.getResources().getIdentifier("ic_launcher", "mipmap", context.getPackageName()); } notificationBuilder .setStyle(new NotificationCompat.MediaStyle() .setShowActionsInCompactView(new int[] { playPauseButtonPosition }) // show only play/pause in compact view .setMediaSession(mSessionToken)) .setColor(0xffdf533b).setSmallIcon(resId).setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setUsesChronometer(true).setContentTitle(description.getTitle()) .setContentText(description.getSubtitle()).setLargeIcon(art); setNotificationPlaybackState(notificationBuilder); // We should get MainActivity.class to set pendingIntent // If there exists better way, it should place this logic String packageName = mService.getApplicationContext().getPackageName(); Intent launchIntent = mService.getApplicationContext().getPackageManager() .getLaunchIntentForPackage(packageName); String className = launchIntent.getComponent().getClassName(); try { Class activityClass = Class.forName(className); notificationBuilder.setContentIntent(createContentIntent(activityClass)); } catch (Exception e) { // do nothing } if (fetchArtUrl != null) { fetchBitmapFromURLAsync(fetchArtUrl, notificationBuilder); } return notificationBuilder.build(); }
From source file:net.lp.actionbarpoirot.helpers.DualTaskStackBuilder.java
/** * Add the activity parent chain as specified by manifest <meta-data> * elements to the task stack builder.//w w w . j av a 2 s . c om * * @param sourceActivityName * Must specify an Activity component. All parents of this * activity will be added * @return This DualTaskStackBuilder for method chaining */ public DualTaskStackBuilder addParentStack(ComponentName sourceActivityName) { final int insertAt = mIntents.size(); try { Intent parent = DualNavUtils.getParentActivityIntent(mSourceContext, sourceActivityName); while (parent != null) { mIntents.add(insertAt, parent); parent = DualNavUtils.getParentActivityIntent(mSourceContext, parent.getComponent()); } } catch (NameNotFoundException e) { Log.e(TAG, "Bad ComponentName while traversing activity parent metadata"); // ***ActionBarPoirot // added******************************************************************************************************************* if (PoirotWindow.DEBUG) e.printStackTrace(); // If this runs in the extension app, then some parent search is // going to throw an error eventually. By then the right intent has // been added. final String mainPackageName = ((ActivityHelperUser) mSourceContext).getHomePackageName(); if (!mainPackageName.equalsIgnoreCase(sourceActivityName.getPackageName()) && sourceActivityName.getPackageName().startsWith(mainPackageName)) { // do nothing } else { throw new IllegalArgumentException(e); } } return this; }
From source file:org.altbeacon.beacon.service.Callback.java
/** * Tries making the callback, first via messenger, then via intent * * @param context/*ww w . j a v a2s .c o m*/ * @param dataName * @param data * @return false if it callback cannot be made */ public boolean call(Context context, String dataName, Bundle data) { boolean useLocalBroadcast = BeaconManager.getInstanceForApplication(context).getScheduledScanJobsEnabled(); boolean success = false; if (useLocalBroadcast) { String action = null; if (dataName == "rangingData") { action = BeaconLocalBroadcastProcessor.RANGE_NOTIFICATION; } else { action = BeaconLocalBroadcastProcessor.MONITOR_NOTIFICATION; } Intent intent = new Intent(action); intent.putExtra(dataName, data); LogManager.d(TAG, "attempting callback via local broadcast intent: %s", action); success = LocalBroadcastManager.getInstance(context).sendBroadcast(intent); } else { Intent intent = new Intent(); intent.setComponent( new ComponentName(context.getPackageName(), "org.altbeacon.beacon.BeaconIntentProcessor")); intent.putExtra(dataName, data); LogManager.d(TAG, "attempting callback via global broadcast intent: %s", intent.getComponent()); try { context.startService(intent); success = true; } catch (Exception e) { LogManager.e(TAG, "Failed attempting to start service: " + intent.getComponent().flattenToString(), e); } } return success; }
From source file:net.lp.actionbarpoirot.helpers.DualTaskStackBuilder.java
/** * Add the activity parent chain as specified by manifest <meta-data> * elements to the task stack builder.// ww w. j a v a 2 s.c om * * @param sourceActivity * All parents of this activity will be added * @return This DualTaskStackBuilder for method chaining */ public DualTaskStackBuilder addParentStack(Activity sourceActivity) { final Intent parent = DualNavUtils.getParentActivityIntent(sourceActivity); if (parent != null) { // We have the actual parent intent, build the rest from static // metadata // then add the direct parent intent to the end. ComponentName target = parent.getComponent(); if (target == null) { target = parent.resolveActivity(mSourceContext.getPackageManager()); } addParentStack(target); addNextIntent(parent); } return this; }
From source file:com.partypoker.poker.engagement.reach.EngagementDefaultNotifier.java
@Override public Boolean handleNotification(EngagementReachInteractiveContent content) throws RuntimeException { /* System notification case */ if (content.isSystemNotification()) { /* Big picture handling */ Bitmap bigPicture = null;//from w w w.j a v a2 s. c o m String bigPictureURL = content.getNotificationBigPicture(); if (bigPictureURL != null && Build.VERSION.SDK_INT >= 16) { /* Schedule picture download if needed, or load picture if download completed. */ Long downloadId = content.getDownloadId(); if (downloadId == null) { EngagementNotificationUtilsV11.downloadBigPicture(mContext, content); return null; } else bigPicture = EngagementNotificationUtilsV11.getBigPicture(mContext, downloadId); } /* Generate notification identifier */ int notificationId = getNotificationId(content); /* Build notification using support lib to manage compatibility with old Android versions */ NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext); /* Icon for ticker and content icon */ builder.setSmallIcon(mNotificationIcon); /* * Large icon, handled only since API Level 11 (needs down scaling if too large because it's * cropped otherwise by the system). */ Bitmap notificationImage = content.getNotificationImage(); if (notificationImage != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) builder.setLargeIcon(scaleBitmapForLargeIcon(mContext, notificationImage)); /* Texts */ String notificationTitle = content.getNotificationTitle(); String notificationMessage = content.getNotificationMessage(); String notificationBigText = content.getNotificationBigText(); builder.setContentTitle(notificationTitle); builder.setContentText(notificationMessage); /* * Replay: display original date and don't replay all the tickers (be as quiet as possible * when replaying). */ Long notificationFirstDisplayedDate = content.getNotificationFirstDisplayedDate(); if (notificationFirstDisplayedDate != null) builder.setWhen(notificationFirstDisplayedDate); else builder.setTicker(notificationTitle); /* Big picture */ if (bigPicture != null) builder.setStyle(new BigPictureStyle().bigPicture(bigPicture).setBigContentTitle(notificationTitle) .setSummaryText(notificationMessage)); /* Big text */ else if (notificationBigText != null) builder.setStyle(new BigTextStyle().bigText(notificationBigText)); /* Vibration/sound if not a replay */ if (notificationFirstDisplayedDate == null) { int defaults = 0; if (content.isNotificationSound()) defaults |= Notification.DEFAULT_SOUND; if (content.isNotificationVibrate()) defaults |= Notification.DEFAULT_VIBRATE; builder.setDefaults(defaults); } /* Launch the receiver on action */ Intent actionIntent = new Intent(INTENT_ACTION_ACTION_NOTIFICATION); com.microsoft.azure.engagement.reach.EngagementReachAgent.setContentIdExtra(actionIntent, content); actionIntent.putExtra(INTENT_EXTRA_NOTIFICATION_ID, notificationId); Intent intent = content.getIntent(); if (intent != null) actionIntent.putExtra(INTENT_EXTRA_COMPONENT, intent.getComponent()); actionIntent.setPackage(mContext.getPackageName()); PendingIntent contentIntent = PendingIntent.getBroadcast(mContext, (int) content.getLocalId(), actionIntent, FLAG_CANCEL_CURRENT); builder.setContentIntent(contentIntent); /* Also launch receiver if the notification is exited (clear button) */ Intent exitIntent = new Intent(INTENT_ACTION_EXIT_NOTIFICATION); exitIntent.putExtra(INTENT_EXTRA_NOTIFICATION_ID, notificationId); EngagementReachAgent.setContentIdExtra(exitIntent, content); exitIntent.setPackage(mContext.getPackageName()); PendingIntent deleteIntent = PendingIntent.getBroadcast(mContext, (int) content.getLocalId(), exitIntent, FLAG_CANCEL_CURRENT); builder.setDeleteIntent(deleteIntent); /* Can be dismissed ? */ Notification notification = builder.build(); if (!content.isNotificationCloseable()) notification.flags |= Notification.FLAG_NO_CLEAR; /* Allow overriding */ if (onNotificationPrepared(notification, content)) /* * Submit notification, replacing the previous one if any (this should happen only if the * application process is restarted). */ mNotificationManager.notify(notificationId, notification); } /* Activity embedded notification case */ else { /* Get activity */ Activity activity = EngagementActivityManager.getInstance().getCurrentActivity().get(); /* Cannot notify in app if no activity provided */ if (activity == null) return false; /* Get notification area */ String category = content.getCategory(); int areaId = getInAppAreaId(category); View notificationAreaView = activity.findViewById(areaId); /* No notification area, check if we can install overlay */ if (notificationAreaView == null) { /* Check overlay is not disabled in this activity */ Bundle activityConfig = EngagementUtils.getActivityMetaData(activity); if (!activityConfig.getBoolean(METADATA_NOTIFICATION_OVERLAY, true)) return false; /* Inflate overlay layout and get reference to notification area */ View overlay = LayoutInflater.from(mContext).inflate(getOverlayLayoutId(category), null); activity.addContentView(overlay, new LayoutParams(MATCH_PARENT, MATCH_PARENT)); notificationAreaView = activity.findViewById(areaId); } /* Otherwise check if there is an overlay containing the area to restore visibility */ else { View overlay = activity.findViewById(getOverlayViewId(category)); if (overlay != null) overlay.setVisibility(View.VISIBLE); } /* Make the notification area visible */ notificationAreaView.setVisibility(View.VISIBLE); /* Prepare area */ prepareInAppArea(content, notificationAreaView); } /* Success */ return true; }
From source file:com.ubikod.capptain.android.sdk.reach.CapptainDefaultNotifier.java
@Override public Boolean handleNotification(CapptainReachInteractiveContent content) throws RuntimeException { /* System notification case */ if (content.isSystemNotification()) { /* Big picture handling */ Bitmap bigPicture = null;/*from w ww . ja v a 2 s . c o m*/ String bigPictureURL = content.getNotificationBigPicture(); if (bigPictureURL != null && Build.VERSION.SDK_INT >= 16) { /* Schedule picture download if needed, or load picture if download completed. */ Long downloadId = content.getDownloadId(); if (downloadId == null) { NotificationUtilsV11.downloadBigPicture(mContext, content); return null; } else bigPicture = NotificationUtilsV11.getBigPicture(mContext, downloadId); } /* Generate notification identifier */ int notificationId = getNotificationId(content); /* Build notification using support lib to manage compatibility with old Android versions */ NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext); /* Icon for ticker and content icon */ builder.setSmallIcon(mNotificationIcon); /* * Large icon, handled only since API Level 11 (needs down scaling if too large because it's * cropped otherwise by the system). */ Bitmap notificationImage = content.getNotificationImage(); if (notificationImage != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) builder.setLargeIcon(scaleBitmapForLargeIcon(mContext, notificationImage)); /* Texts */ String notificationTitle = content.getNotificationTitle(); String notificationMessage = content.getNotificationMessage(); String notificationBigText = content.getNotificationBigText(); builder.setContentTitle(notificationTitle); builder.setContentText(notificationMessage); /* * Replay: display original date and don't replay all the tickers (be as quiet as possible * when replaying). */ Long notificationFirstDisplayedDate = content.getNotificationFirstDisplayedDate(); if (notificationFirstDisplayedDate != null) builder.setWhen(notificationFirstDisplayedDate); else builder.setTicker(notificationTitle); /* Big picture */ if (bigPicture != null) builder.setStyle(new BigPictureStyle().bigPicture(bigPicture).setBigContentTitle(notificationTitle) .setSummaryText(notificationMessage)); /* Big text */ else if (notificationBigText != null) builder.setStyle(new BigTextStyle().bigText(notificationBigText)); /* Vibration/sound if not a replay */ if (notificationFirstDisplayedDate == null) { int defaults = 0; if (content.isNotificationSound()) defaults |= Notification.DEFAULT_SOUND; if (content.isNotificationVibrate()) defaults |= Notification.DEFAULT_VIBRATE; builder.setDefaults(defaults); } /* Launch the receiver on action */ Intent actionIntent = new Intent(INTENT_ACTION_ACTION_NOTIFICATION); CapptainReachAgent.setContentIdExtra(actionIntent, content); actionIntent.putExtra(INTENT_EXTRA_NOTIFICATION_ID, notificationId); Intent intent = content.getIntent(); if (intent != null) actionIntent.putExtra(INTENT_EXTRA_COMPONENT, intent.getComponent()); actionIntent.setPackage(mContext.getPackageName()); PendingIntent contentIntent = PendingIntent.getBroadcast(mContext, (int) content.getLocalId(), actionIntent, FLAG_CANCEL_CURRENT); builder.setContentIntent(contentIntent); /* Also launch receiver if the notification is exited (clear button) */ Intent exitIntent = new Intent(INTENT_ACTION_EXIT_NOTIFICATION); exitIntent.putExtra(INTENT_EXTRA_NOTIFICATION_ID, notificationId); CapptainReachAgent.setContentIdExtra(exitIntent, content); exitIntent.setPackage(mContext.getPackageName()); PendingIntent deleteIntent = PendingIntent.getBroadcast(mContext, (int) content.getLocalId(), exitIntent, FLAG_CANCEL_CURRENT); builder.setDeleteIntent(deleteIntent); /* Can be dismissed ? */ Notification notification = builder.build(); if (!content.isNotificationCloseable()) notification.flags |= Notification.FLAG_NO_CLEAR; /* Allow overriding */ if (onNotificationPrepared(notification, content)) /* * Submit notification, replacing the previous one if any (this should happen only if the * application process is restarted). */ mNotificationManager.notify(notificationId, notification); } /* Activity embedded notification case */ else { /* Get activity */ Activity activity = CapptainActivityManager.getInstance().getCurrentActivity().get(); /* Cannot notify in app if no activity provided */ if (activity == null) return false; /* Get notification area */ String category = content.getCategory(); int areaId = getInAppAreaId(category); View notificationAreaView = activity.findViewById(areaId); /* No notification area, check if we can install overlay */ if (notificationAreaView == null) { /* Check overlay is not disabled in this activity */ Bundle activityConfig = CapptainUtils.getActivityMetaData(activity); if (!activityConfig.getBoolean(METADATA_NOTIFICATION_OVERLAY, true)) return false; /* Inflate overlay layout and get reference to notification area */ View overlay = LayoutInflater.from(mContext).inflate(getOverlayLayoutId(category), null); activity.addContentView(overlay, new LayoutParams(MATCH_PARENT, MATCH_PARENT)); notificationAreaView = activity.findViewById(areaId); } /* Otherwise check if there is an overlay containing the area to restore visibility */ else { View overlay = activity.findViewById(getOverlayViewId(category)); if (overlay != null) overlay.setVisibility(View.VISIBLE); } /* Make the notification area visible */ notificationAreaView.setVisibility(View.VISIBLE); /* Prepare area */ prepareInAppArea(content, notificationAreaView); } /* Success */ return true; }
From source file:com.android.leanlauncher.IconCache.java
public synchronized Bitmap getIcon(Intent intent, UserHandleCompat user, ItemInfo info) { ComponentName component = intent.getComponent(); // null info means not installed, but if we have a component from the intent then // we should still look in the cache for restored app icons. if (component == null) { return getDefaultUserIcon(user); }//from w w w . j a v a 2s .c o m LauncherActivityInfoCompat launcherActInfo = mLauncherApps.resolveActivity(intent, user); CacheEntry entry = cacheLocked(info, component, launcherActInfo, user, null, true); return entry.icon; }