Es posible poner en marcha un servicio de notificación.
Tienes que usar PendingIntent.getService en lugar de pendingIntent.getActivity.
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);
¡Definitivamente debería ser la respuesta aceptada! "PendingIntent.getService en vez de pendingIntent.getActivity" es la forma correcta de hacerlo. – Christian
@keide cómo pausar el servicio usando pendingIntent en la notificación. necesitamos llamar al método de parada de la clase de servicio. –
Cuando comienzo el servicio como se describió anteriormente recibo una excepción de tiempo de ejecución: Subproceso [<1> principal] (Suspendido (excepción RuntimeException)) - - ActivityThread.handleCreateService (ActivityThread $ CreateServiceData) línea: 2561 - ActivityThread .access $ 1600 (ActivityThread, ActivityThread $ CreateServiceData) línea: 141 –
samo