我正在尝试在状态栏上发送通知,一旦点击按钮就会发送此通知。 我使用下面的代码,我也提到了一些例子,但在运行时,按钮点击事件的状态栏上没有显示任何内容。
请让我知道我缺少的东西
code-1:发送上游消息:
mBtn_send = (Button) findViewById(R.id.btn_send_notification);
mBtn_send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "TOAST", Toast.LENGTH_LONG).show();
try {
send();
} catch (PendingIntent.CanceledException e) {
e.printStackTrace();
}
}
});
}
public void send() throws PendingIntent.CanceledException {
Intent intAct = new Intent(this, ActPending.class);
PendingIntent pending = PendingIntent.getActivity(this, 1, intAct, PendingIntent.FLAG_UPDATE_CURRENT);
//pending.send();
String title = getString(R.string.app_name);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setStyle(new NotificationCompat.BigTextStyle().bigText("BIG TEXT")).setContentText("CONTENTS").setContentTitle(title);
builder.setContentIntent(pending).setAutoCancel(true);
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(1, builder.build());
}