当屏幕顶部的通知被拉下来时,我已经看到了手机的演示执行操作。通常,当您在Android上执行此操作时,通知菜单将打开。它可以与所有应用程序一起使用,因此不仅来自特定支持的应用程序。我尝试实施此操作,但找不到任何方法。
.addAction
只允许我添加按钮,但不能添加按钮。理想情况下,我认为我需要在所有通知中实现类似OnTouchEvent的东西。
以下代码创建通知,如果您对其添加意图(在我的情况下为空(,可以在单击通知时执行操作。
public void buttonClick(View v){
final Intent emptyIntent = new Intent();
PendingIntent pendingIntent = PendingIntent.getActivity(MyActivitity.this, 0, emptyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setAutoCancel(true) //when clicked it disappears
.setContentIntent(pendingIntent); //Required on Gingerbread and below
NotificationManager notificationManager = (NotificationManager) MyActivitity.this.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, mBuilder.build());
}