Я новичок ie в android разработке.
Я создаю фоновую службу для получения pushNotification (с нашей собственной службой сокетов, а не FCM). И теперь мое устройство получает сообщение и показывает уведомление успешно. Но когда я нажимаю на уведомление, оно не возвращается в мое приложение.
Когда я нажимаю на уведомление, отображается следующая ошибка: ActivityManager: Невозможно запустить службу Intent {cmp = com.my.app / package.name.AppActivity} U = 0: не найдено
Вот мой код:
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;
}
}
Настройка MainActivity в AndroidManifest. xml
<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>
Пожалуйста, сообщите мне, что я пропускаю или делаю неправильно в этом коде , Большое спасибо.