【发布时间】:2014-05-13 17:09:01
【问题描述】:
在我的主类中,我有 notificationBuilder,它在按钮单击时启动。
NotificationManager NotifyMgr =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
PendingIntent turnOffIntent = PendingIntent.getBroadcast(this, 0,
new Intent(NotifiReceiver.turnOffFlash), 0);
PendingIntent contentIntent = PendingIntent.getActivity(this,
0, new Intent(this, MainActivity.class), 0);
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_lightbulb_on)
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.app_name))
.setContentIntent(contentIntent)
.setDefaults(Notification.DEFAULT_ALL) // requires VIBRATE permission
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(getString(R.string.app_name) + "dfddddddggffgf"))
.addAction(R.drawable.ic_lightbulb,
getString(R.string.app_name), turnOffIntent);
NotifyMgr.notify(notificationId, builder.build());
这里是 NotifiReceiver.class
package com.AleXMan.torch.standart;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class NotifiReceiver extends BroadcastReceiver {
MainActivity mna = new MainActivity();
public static final String turnOffFlash = "com.AleXMan.torch.standart.turnOffFlash";
@Override
public void onReceive(Context context, Intent intent) {
Log.i("test", "recieved");
if (intent.getAction().equals(turnOffFlash)) {
mna.toggleFrstFlash();
Log.i("test", "confirmed");
}
throw new UnsupportedOperationException("Not yet implemented");
}
}
但是当我点击通知中的这个“按钮”时:.addAction(R.drawable.ic_lightbulb,
getString(R.string.app_name), turnOffIntent);
什么都没有发生。
你能告诉我我到底做错了什么吗?
非常感谢您,对您未来的帮助!
【问题讨论】:
-
请发布您的清单,为您的
NotifiReceiver显示<receiver>元素。 -
这是我错过的东西!!你能在回答器中写下我需要添加到清单吗?
标签: android methods notifications android-activity broadcastreceiver