河南省住房和城乡建设厅查询网站首页/数字经济发展情况报告
我试图把PendingIntent通知放在我的android项目,但我有这个错误,它说错误的第一个参数发现android view.View.OnClickListener需要android内容,上下文。安卓工作室错误放在通知函数使用if else
我打算显示代码错误,“其他通知”下的“this”有错误。
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification noti = new Notification.Builder(this)
此错误
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int targetId = view.getId();
if (targetId == R.id.button) {
Toast.makeText(getApplicationContext(), "You have " + numMessages++ + " message", Toast.LENGTH_SHORT).show();
} else {
if (numMessages > 0) {
Intent intent = new Intent();
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification noti = new Notification.Builder(this)
.setTicker("You Have " + numMessages++ + " message")
.setContentTitle("OneDiver")
.setContentText("Content")
.setSmallIcon(R.drawable.ic_od_icon_24dp)
.setContentIntent(pIntent).getNotification();
noti.flags = Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, noti);
}
}
2015-11-02
jaylord
+0
像'YourActivityName.this'这样写'YourActivityName.this'代替'this' –
+0
你有关于如何在应用程序中放置通知的喜好,比如在facebook上弹出一个图标。我已经搜索了这个引用,但没有结果回答我的问题,关于如何将通知放在应用程序上。谢谢! –