如何在按钮点击通知时调用类

时间:2013-10-11 12:12:40

标签: android-layout android-intent android-notifications android-pendingintent android-notification-bar

实际上我是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;

你能告诉我如何在这个场景中编程

1 个答案:

答案 0 :(得分:0)

我遇到同样的问题检查很多链接但是没有结果也许你可以想出这里的东西是链接:

Link 1

Link 2

Link 3

Link 4

Link 5

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