这是我的CreateNotification类。代码已从android页面中获取。 http://developer.android.com/guide/topics/ui/notifiers/notifications.html
代码:
package your.notification.manager;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcel;
import android.view.View;
public class CreateNotification extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
Intent notificationIntent = new Intent(this, NotificationReceiver.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification);
}
}
错误:
05-05 12:51:38.687: E/AndroidRuntime(8629): Caused by: java.lang.IllegalArgumentException: contentView required: pkg=com.crumbs.main id=0 notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x10)
答案 0 :(得分:2)
您的准则工作正常......
只需清理您的项目并再次运行。