类android.app.Notification.Action源码实例Demo

下面列出了怎么用android.app.Notification.Action的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: sdk   文件: MutableNotificationTest.java
@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());
	}
 
源代码2 项目: android-FindMyPhone   文件: FindPhoneActivity.java
@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();
}
 
@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();
}
 
源代码4 项目: android-test   文件: NotificationActionSubject.java
public static NotificationActionSubject assertThat(Action action) {
  return Truth.assertAbout(notificationActions()).that(action);
}
 
源代码5 项目: android-test   文件: NotificationActionSubject.java
public static Subject.Factory<NotificationActionSubject, Action> notificationActions() {
  return NotificationActionSubject::new;
}
 
源代码6 项目: android-test   文件: NotificationActionSubject.java
NotificationActionSubject(FailureMetadata failureMetadata, Action subject) {
  super(failureMetadata, subject);
  this.actual = subject;
}
 
 类所在包
 同包方法