以下是我的代码。我已经把行动(是或否)使用的addAction到notification.But的问题是,如果它按我无法检测或not.Plz帮助..谢谢如何检测是否按通知Android
@SuppressWarnings("deprecation")
@Override
protected void onIncomingCallReceived(final Context ctx, final String number, final Date start) {
// Create Intent for notification
Intent intent = new Intent(ctx, CallReceiver.class);
PendingIntent pi = PendingIntent.getActivity(ctx, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
//Yes intent
Intent yesReceive = new Intent();
yesReceive.setAction(YES_ACTION);
PendingIntent pendingIntentYes = PendingIntent.getBroadcast(ctx, 0, yesReceive, PendingIntent.FLAG_UPDATE_CURRENT);
//No intent
Intent noReceive = new Intent();
noReceive.setAction(NO_ACTION);
PendingIntent pendingIntentNo = PendingIntent.getBroadcast(ctx, 0, noReceive, PendingIntent.FLAG_UPDATE_CURRENT);
// Defining notification
NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(
ctx).setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Sample text 1 ?")
.setContentText("Sample text 2").setContentIntent(pi)
.addAction(R.drawable.ic_done_white_36dp, "Yes", pendingIntentYes)
.addAction(R.drawable.ic_close_white_36dp, "No", pendingIntentNo);
// Allows notification to be cancelled when user clicks it
nBuilder.setAutoCancel(true);
// Issuing notification
int notificationId = 0;
NotificationManager notifyMgr = (NotificationManager) ctx.getSystemService(NOTIFICATION_SERVICE);
String action = intent.getAction();
if (CallReceiver.YES_ACTION.equals(action)) {
Toast.makeText(ctx, "YES CALLED", Toast.LENGTH_SHORT).show();
} else if (CallReceiver.NO_ACTION.equals(action)) {
Toast.makeText(ctx, "STOP CALLED", Toast.LENGTH_SHORT).show();
}
notifyMgr.notify(notificationId, nBuilder.build());
}
这个代码是在我的CallReciever.class延伸Phonecallreciever 其中,phonecallreciever延长broadcastreciver。
事情是在点击Yes按钮,我想保存在db..ie从来电中获得的细节(最后语境环磷酰胺,最终串号,最后的日期开始)...如果你说我不能在Obregive功能中使用详细信息 – Androidss
@Androidss我不这么认为。在'onRecieve(Context context,Intent intent)'中,您拥有所有您需要的内容:1. context,您可以使用它打开数据库或访问系统服务; 2. intent,它通过'Intent'拥有所有共享数据。尝试使用它们来存储所有你需要的数据。 –