Android 在后台点击通知不打开我的应用?
我是android开发的新手 我为receive pushNotification创建了一个后台服务(使用我们自己的套接字服务,而不是FCM)。 现在,我的设备成功接收消息并显示通知。但当我点击通知时,它不会返回到我的应用程序 单击通知时,显示以下错误: ActivityManager:无法启动服务意图{cmp=com.my.app/package.name.AppActivity}U=0:未找到 这是我的密码:Android 在后台点击通知不打开我的应用?,android,android-activity,push-notification,Android,Android Activity,Push Notification,我是android开发的新手 我为receive pushNotification创建了一个后台服务(使用我们自己的套接字服务,而不是FCM)。 现在,我的设备成功接收消息并显示通知。但当我点击通知时,它不会返回到我的应用程序 单击通知时,显示以下错误: ActivityManager:无法启动服务意图{cmp=com.my.app/package.name.AppActivity}U=0:未找到 这是我的密码: public static void setNotification(S
public static void setNotification(Service service, String message) {
NotificationManager manager = (NotificationManager) service.getSystemService(NOTIFICATION_SERVICE);
String appName = service.getString(R.string.app_name);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder builder = new NotificationCompat.Builder(service)
.setContentTitle(appName)
.setContentText(message)
.setContentIntent(getDefaultIntent(service))
.setWhen(System.currentTimeMillis())
.setOngoing(false)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_VIBRATE)
.setSmallIcon(R.drawable.icon)
.setLargeIcon(BitmapFactory.decodeResource(service.getResources(), R.drawable.icon))
.setSound(alarmSound);
Notification notification = builder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
manager.notify(1, notification);
}
private static PendingIntent getDefaultIntent(Service service) {
Intent intent = new Intent(service, AppActivity.class);
PendingIntent pendingIntent = PendingIntent.getService(service, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
return pendingIntent;
}
}
AndroidManifest.xml中的MainActivity设置
<activity android:name="package.name.AppActivity" android:configChanges="orientation|screenSize" android:label="@string/app_name" android:launchMode="singleTask" android:screenOrientation="landscape" android:theme= "@android:style/Theme.NoTitleBar.Fullscreen" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
请指导我在这段代码中遗漏了什么或做错了什么。非常感谢。我遇到了问题,您只取消了当前的通知,这就是为什么Intent没有启动活动更改您的挂起意图 从 到
我在padding intent和manager.notify中传递了相同的id(0,notification) 并使用pendingent.getActivity而不是pendingent.getService
它起作用了 它应该与padding intent pass manager的id相同。notify(0,notification);我传递id 0,经理。通知(0,通知),并且仍然没有在manager.notify中打开myAppI pass id 0(0,notification),并且仍然没有打开MyApp,然后尝试在NotificationObject而不是NotificationBuilder中设置意图,就像我的代码一样,这可能会起作用。您已在通知生成器中设置了意图。只是尝试一下,但是setLateStevenInfo方法是deprecated@Pie我收到了你的问题,我已经更新了答案。希望这能解决这个问题。最后,我使用PendingEvent.getActivity代替PendingEvent.getService,它很有效
PendingIntent.FLAG_CANCEL_CURRENT);
PendingIntent.FLAG_UPDATE_CURRENT
| PendingIntent.FLAG_ONE_SHOT);