【发布时间】:2014-03-05 20:33:23
【问题描述】:
我已经经历过[在Android中使用AlarmManager和BroadcastReceiver][1]
我在 Android 项目中复制了相同的代码。它运行时没有错误。但未显示任何通知。
有什么建议吗?
我在网上搜索了以下方法
private void showNotification(Context context, String text) {
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(getString(R.string.app_name))
.setContentText(text)
.setAutoCancel(true);
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
我把它称为floows:
private PendingIntent pendingIntent;
Button notifyButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
notifyButton = (Button)findViewById(R.id.button1);
notifyButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
showNotification(MainActivity.this,"Hi Parth Here");
}
});
}
但它显示错误
java.lang.IllegalArgumentException:需要 contentIntent: pkg=com.example.alertmanagerexample id=1 notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x10)
【问题讨论】:
标签: android broadcastreceiver android-notifications