0

实际上我是 android 新手,正在构建自定义通知。在我的通知布局中,我有一个按钮。在其点击事件中,我需要更改某些系统设置。但是当我调用除 MainActivity 类之外的任何类时,它不响应这里是我的代码

 int icon = R.drawable.notifyicon;
    long when = System.currentTimeMillis();
    Notification notification = new Notification(icon, "Custom Notification", when);

    NotificationManager mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification);
    contentView.setImageViewResource(R.id.image, R.drawable.ic_launcher);
    contentView.setTextViewText(R.id.title, "Custom notification");
    //contentView.setTextViewText(R.id.text, "This is a custom layout");
    Intent notificationIntent1 = new Intent(this,notify.class);//Here if I write MainActivity.class it works
    PendingIntent contentIntent1 = PendingIntent.getActivity(this, 0, notificationIntent1, 0);
    contentView.setOnClickPendingIntent(R.id.button2, contentIntent1);
    /*
    Intent notificationIntent = new Intent(this, NotificationReceiverActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);*/


    notification.contentView = contentView;

    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

  notification.contentIntent = contentIntent;

你能告诉我如何在这种情况下编程吗

4

1 回答 1

0

我陷入了同样的问题,检查了许多链接,但没有结果,也许您可​​以在这里找到一些链接:

链接 1

链接 2

链接 3

链接 4

链接 5

我也是android新手,也许我们可以互相帮助。

于 2014-02-21T05:33:56.040 回答