android.app.Notification.Action Java Examples

The following examples show how to use android.app.Notification.Action. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MutableNotificationTest.java    From sdk with Apache License 2.0 6 votes vote down vote up
@Test @SuppressWarnings("UnusedLabel") public void testBasicMutationsWithParceling() {
		final MutableNotification mutable = mutable(n());

		testMutation(mutable, MutableNotification::setGroup, MutableNotification::getGroup, "G1", "G2", "", null);
		testMutation(mutable, MutableNotification::setSortKey, MutableNotification::getSortKey, "S1", "S2", "", null);

		testMutation(mutable, MutableNotification::setSmallIcon, MutableNotification::getSmallIcon, RES_ICON, DATA_ICON, null);
		testMutation(mutable, MutableNotification::setLargeIcon, MutableNotification::getLargeIcon, RES_ICON, DATA_ICON, null);
		if (SDK_INT >= O) testMutation(mutable, MutableNotification::setTimeoutAfter, Notification::getTimeoutAfter, 10L, -999L, 0L);

ACTION:	testMutation(mutable, MutableNotification::addAction, m -> m.actions[0], new Action.Builder(RES_ICON, "Hello", null).build());
		testMutation(mutable, MutableNotification::addAction, m -> m.actions[1], new Action.Builder(RES_ICON, "Bye", null).build());

PERSON: testMutation(mutable, MutableNotification::addPerson, m -> m.extras.getStringArray(Notification.EXTRA_PEOPLE)[0], "Tom");
		testMutation(mutable, MutableNotification::addPerson, m -> m.extras.getStringArray(Notification.EXTRA_PEOPLE)[1], "Jerry");

PUBLIC: testMutation(mutable, (m, p) -> m.publicVersion = p, m -> ensureParcelingEquality(m.publicVersion), n(), b().setGroup("x").build());
	}
 
Example #2
Source File: FindPhoneActivity.java    From android-FindMyPhone with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Create a notification with an action to toggle an alarm on the phone.
    Intent toggleAlarmOperation = new Intent(this, FindPhoneService.class);
    toggleAlarmOperation.setAction(FindPhoneService.ACTION_TOGGLE_ALARM);
    PendingIntent toggleAlarmIntent = PendingIntent.getService(this, 0, toggleAlarmOperation,
            PendingIntent.FLAG_CANCEL_CURRENT);
    Action alarmAction = new Action(R.drawable.alarm_action_icon, "", toggleAlarmIntent);
    // This intent turns off the alarm if the user dismisses the card from the wearable.
    Intent cancelAlarmOperation = new Intent(this, FindPhoneService.class);
    cancelAlarmOperation.setAction(FindPhoneService.ACTION_CANCEL_ALARM);
    PendingIntent cancelAlarmIntent = PendingIntent.getService(this, 0, cancelAlarmOperation,
            PendingIntent.FLAG_CANCEL_CURRENT);
    // Use a spannable string for the notification title to resize it.
    SpannableString title = new SpannableString(getString(R.string.app_name));
    title.setSpan(new RelativeSizeSpan(0.85f), 0, title.length(), Spannable.SPAN_POINT_MARK);
    notification = new Notification.Builder(this)
            .setContentTitle(title)
            .setContentText(getString(R.string.turn_alarm_on))
            .setSmallIcon(R.drawable.ic_launcher)
            .setVibrate(new long[] {0, 50})  // Vibrate to bring card to top of stream.
            .setDeleteIntent(cancelAlarmIntent)
            .extend(new Notification.WearableExtender()
                    .addAction(alarmAction)
                    .setContentAction(0)
                    .setHintHideIcon(true))
            .setLocalOnly(true)
            .setPriority(Notification.PRIORITY_MAX);
    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
            .notify(FIND_PHONE_NOTIFICATION_ID, notification.build());

    finish();
}
 
Example #3
Source File: FindPhoneActivity.java    From AndroidWearable-Samples with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Create a notification with an action to toggle an alarm on the phone.
    Intent toggleAlarmOperation = new Intent(this, FindPhoneService.class);
    toggleAlarmOperation.setAction(FindPhoneService.ACTION_TOGGLE_ALARM);
    PendingIntent toggleAlarmIntent = PendingIntent.getService(this, 0, toggleAlarmOperation,
            PendingIntent.FLAG_CANCEL_CURRENT);
    Action alarmAction = new Action(R.drawable.alarm_action_icon, "", toggleAlarmIntent);
    // This intent turns off the alarm if the user dismisses the card from the wearable.
    Intent cancelAlarmOperation = new Intent(this, FindPhoneService.class);
    cancelAlarmOperation.setAction(FindPhoneService.ACTION_CANCEL_ALARM);
    PendingIntent cancelAlarmIntent = PendingIntent.getService(this, 0, cancelAlarmOperation,
            PendingIntent.FLAG_CANCEL_CURRENT);
    // Use a spannable string for the notification title to resize it.
    SpannableString title = new SpannableString(getString(R.string.app_name));
    title.setSpan(new RelativeSizeSpan(0.85f), 0, title.length(), Spannable.SPAN_POINT_MARK);
    notification = new Notification.Builder(this)
            .setContentTitle(title)
            .setContentText(getString(R.string.turn_alarm_on))
            .setSmallIcon(R.drawable.ic_launcher)
            .setVibrate(new long[] {0, 50})  // Vibrate to bring card to top of stream.
            .setDeleteIntent(cancelAlarmIntent)
            .extend(new Notification.WearableExtender()
                    .addAction(alarmAction)
                    .setContentAction(0)
                    .setHintHideIcon(true))
            .setLocalOnly(true)
            .setPriority(Notification.PRIORITY_MAX);
    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
            .notify(FIND_PHONE_NOTIFICATION_ID, notification.build());

    finish();
}
 
Example #4
Source File: NotificationActionSubject.java    From android-test with Apache License 2.0 4 votes vote down vote up
public static NotificationActionSubject assertThat(Action action) {
  return Truth.assertAbout(notificationActions()).that(action);
}
 
Example #5
Source File: NotificationActionSubject.java    From android-test with Apache License 2.0 4 votes vote down vote up
public static Subject.Factory<NotificationActionSubject, Action> notificationActions() {
  return NotificationActionSubject::new;
}
 
Example #6
Source File: NotificationActionSubject.java    From android-test with Apache License 2.0 4 votes vote down vote up
NotificationActionSubject(FailureMetadata failureMetadata, Action subject) {
  super(failureMetadata, subject);
  this.actual = subject;
}