通知仍然没有启动:

时间:2012-07-21 16:24:13

标签: android notifications

我调试了我的代码,以至于在次要内容上有一个“未使用”警告。我的问题是为什么代码没有运行?这是:

public class NoteMe extends Activity {
/** Called when the activity is first created. */
NotificationManager nm;
Context context = this;
ImageView iv;
TextView title, text;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.note_activity);
    title = (TextView) findViewById(R.id.title);
    text = (TextView) findViewById(R.id.text);
    iv = (ImageView) findViewById(R.id.icon);
    nm = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    long when = System.currentTimeMillis();
    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.note_activity);
    contentView.setImageViewResource(R.id.image, R.drawable.ic_launcher);
    contentView.setTextViewText(R.id.title, "Example Title");
    contentView.setTextViewText(R.id.text, "HELLO NOTIFICATION!");
    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    Notification notification = new Notification();
    notification.contentIntent = contentIntent;
    notification.contentView = contentView;
    notification.flags = Notification.FLAG_ONGOING_EVENT;
    int NOTIFICATION_ID = 10;
    nm.notify(NOTIFICATION_ID, notification);
}
}

目前logCat无法使用手机:(

0 个答案:

没有答案