Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android中的捕获通知_Android_Notifications_Google Calendar Api - Fatal编程技术网

android中的捕获通知

android中的捕获通知,android,notifications,google-calendar-api,Android,Notifications,Google Calendar Api,当用户单击通知ui中的通知时,是否有方法将其重定向到另一个活动 比如说 我在Google Calendar中创建了一个事件,当出现通知时,当用户单击它时,它将打开我的活动,而不是直接进入Google Calendar。尝试以下方法: private void generateNotification(Context context, String message, long when, String query) { int icon = R.drawable.icon; long when

当用户单击通知ui中的通知时,是否有方法将其重定向到另一个活动

比如说

我在Google Calendar中创建了一个事件,当出现通知时,当用户单击它时,它将打开我的活动,而不是直接进入Google Calendar。

尝试以下方法:

private void generateNotification(Context context, String message,
long when, String query) {
int icon = R.drawable.icon;
 long when = System.currentTimeMillis();
String appname = context.getResources().getString(R.string.app_name);
NotificationManager notificationManager = (NotificationManager) context
    .getSystemService(Context.NOTIFICATION_SERVICE);
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
Notification notification;

Intent intent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
    intent, 0);

if (currentapiVersion < android.os.Build.VERSION_CODES.HONEYCOMB) {
    notification = new Notification(icon, message, when);
    notification.setLatestEventInfo(context, appname, message,
            contentIntent);
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify((int) when, notification);

} else {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(
            context);
    notification = builder.setContentIntent(contentIntent)
            .setSmallIcon(icon).setTicker(appname).setWhen(when)
            .setAutoCancel(true).setContentTitle(appname)
            .setContentText(message).build();

    notificationManager.notify((int) when, notification);

}
private void generateNotification(上下文、字符串消息、,
长时,字符串查询){
int icon=R.drawable.icon;
长时间=System.currentTimeMillis();
String appname=context.getResources().getString(R.String.app_name);
NotificationManager NotificationManager=(NotificationManager)上下文
.getSystemService(上下文通知服务);
int currentapiVersion=android.os.Build.VERSION.SDK\u int;
通知;
意向意向=新意向(上下文,MainActivity.class);
PendingEvent contentIntent=PendingEvent.getActivity(上下文,0,
意图,0);
if(currentapiVersion
希望这有帮助。

看看,我想这就是你需要的。