/** * Creates and shows notification to the user. * * @param context app <code>Context</code> for the intent. * @param title short content. * @param text few more details. * @param alert shows on the top bar for one second. * @param uuid must be unique. * @param tabTag should not be <code>null</code>. */ private void createNotification( Context context, String title, String text, String alert, String uuid, String owner, String phone, String tabTag) { int alarmId = uuid.hashCode(); Intent intent = new Intent(context, EditDebtActivity.class); // intent.setFlags(/*Intent.FLAG_ACTIVITY_REORDER_TO_FRONT*/ // /*Intent.FLAG_ACTIVITY_SINGLE_TOP | */Intent.FLAG_ACTIVITY_CLEAR_TOP);// REMOVE: 21/09/2015 intent.putExtra(Debt.KEY_UUID, uuid); intent.putExtra(Debt.KEY_TAB_TAG, tabTag); PendingIntent notificationIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Notification.Builder builder = new Notification.Builder(context) .setContentTitle(title) .setTicker(alert) .setContentText(text) .setSmallIcon(R.drawable.ic_launcher) .setContentIntent(notificationIntent) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setAutoCancel(true); if (phone != null) { // Create dialing action String dialTitle = "Call " + owner; int dialIcon = R.drawable.ic_call_white_36dp; Intent dialIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone)); PendingIntent notificationCallIntent = PendingIntent.getActivity(context, 0, dialIntent, PendingIntent.FLAG_UPDATE_CURRENT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { builder.addAction( new Notification.Action.Builder( Icon.createWithResource(context, dialIcon), dialTitle, notificationCallIntent) .build()); } else { //noinspection deprecation builder.addAction(dialIcon, dialTitle, notificationCallIntent); } } Notification notification = builder.build(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(alarmId, notification); }
private boolean showNextPermissionGroupGrantRequest() { final int groupCount = mRequestGrantPermissionGroups.size(); int currentIndex = 0; for (GroupState groupState : mRequestGrantPermissionGroups.values()) { if (groupState.mState == GroupState.STATE_UNKNOWN) { CharSequence appLabel = mAppPermissions.getAppLabel(); SpannableString message = new SpannableString( getString( R.string.permission_warning_template, appLabel, groupState.mGroup.getDescription())); // Set the permission message as the title so it can be announced. setTitle(message); // Color the app name. int appLabelStart = message.toString().indexOf(appLabel.toString(), 0); int appLabelLength = appLabel.length(); int color = getColor(R.color.grant_permissions_app_color); message.setSpan( new ForegroundColorSpan(color), appLabelStart, appLabelStart + appLabelLength, 0); // Set the new grant view // TODO: Use a real message for the action. We need group action APIs Resources resources; try { resources = getPackageManager().getResourcesForApplication(groupState.mGroup.getIconPkg()); } catch (NameNotFoundException e) { // Fallback to system. resources = Resources.getSystem(); } int icon = groupState.mGroup.getIconResId(); mViewHandler.updateUi( groupState.mGroup.getName(), groupCount, currentIndex, Icon.createWithResource(resources, icon), message, groupState.mGroup.isUserSet()); return true; } currentIndex++; } return false; }
@Override public List<ChooserTarget> onGetChooserTargets( ComponentName targetActivityName, IntentFilter matchedFilter) { ProfileManager pm = ProfileManager.getInstance(getApplicationContext()); ArrayList<Profile> profiles = (ArrayList<Profile>) pm.getProfiles().clone(); final List<ChooserTarget> targets = new ArrayList<>(); for (int i = 0; i < profiles.size(); i++) { // Name final String title = profiles.get(i).getName(); // Individual icon final Icon icon = Icon.createWithResource(this, R.drawable.gyazo_ninja); // TODO: Scoring final float score = pm.getChooserScore(profiles.get(i)); // Extras final Bundle extra = new Bundle(); extra.putString("uuid", profiles.get(i).getUUID()); final ChooserTarget target = new ChooserTarget(title, icon, score, targetActivityName, extra); targets.add(target); } Collections.sort(targets, new targetComparator()); return targets; }