我想要一個(gè)帶有幾個(gè)按鈕的通知,當(dāng)點(diǎn)擊時(shí):會(huì)調(diào)用一個(gè)方法,但不啟動(dòng)任何 UI(活動(dòng));不會(huì)導(dǎo)致通知欄折疊。我已經(jīng)使用如下所示的操作創(chuàng)建了一個(gè)通知(使用 NotificationCompat.Builder)。點(diǎn)擊操作按鈕啟動(dòng) MainActivity UI 并折疊通知欄。關(guān)于如何實(shí)現(xiàn)上述所需行為的任何提示?我的代碼:Intent actionIntent = new Intent(this, MainActivity.class);actionIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);actionIntent.setAction(MY_ACTION_ID);NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setContentTitle("My notification") .setVisibility(VISIBILITY_PUBLIC) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setAutoCancel(false) .addAction(new NotificationCompat.Action( 0, "My action", PendingIntent.getActivity(this, 0, actionIntent, 0)));NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);notificationManager.notify(MY_NOTIFICATION_ID, builder.build());
在不啟動(dòng) UI 的情況下調(diào)用方法
慕工程0101907
2021-08-13 15:22:45