Bildirimden bir hizmet başlatmak mümkündür.
pendingIntent.getActivity yerine PendingIntent.getService kullanmanız gerekir. BroadCastReceiver ile tipp için
Intent notificationIntent = new Intent(mContext, HandleNotificationClickService.class);
PendingIntent pendingIntent = PendingIntent.getService(mContext, 0, notificationIntent, 0);
Notification notification = new Notification(icon, tickerText,System.currentTimeMillis());
notification.setLatestEventInfo(mContext,contentTitle , contentText, pendingIntent);
notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONGOING_EVENT;
NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(CALLER_ID_NOTIFICATION_ID, notification);
Bu kesinlikle kabul edilen cevap olmalı! "PendingIntent.getActivity yerine PendingIntent.getService" bunu yapmanın doğru yolu! – Christian
@keide Bildirimde pendingIntent kullanarak hizmeti duraklatma. Hizmet sınıfının durma yöntemini aramalıyız. –
Bir çalışma zamanı özel olsun yukarıda açıklandığı gibi hizmet başlattığınızda: Konu [<1> ana] (Asma (istisna RuntimeException)) - - ActivityThread.handleCreateService (ActivityThread $ CreateServiceData) çizgi: 2561 - ActivityThread .Geçiş 1600 $ (ActivityThread, ActivityThread $ CreateServiceData) hattı: 141 –
samo