Estoy intentando iniciar una notificación de barra de estado desde un receptor de transmisión y luego detenerla desde otro receptor de transmisión, pero estoy teniendo problemas. Me gustaría iniciar la notificación en la barra de estado cuando el usb está conectado y luego cuando el usb está desconectado, me gustaría detenerlo. Tengo los dos receptores configurados y trabajando simplemente luchando con iniciar y detener uno desde un receptor aquí está el código. Tengo actualmenteIniciar y detener una notificación del receptor de difusión
Mi único error con mi código es la línea myNotificationManager = (NotificationManager) getSystemService(context.NOTIFICATION_SERVICE);
, el error solo dice que getSystemService no está definido y quiere hacer que el método suponga que el receptor no tiene soporte para ese método, como lo haría una actividad así que lo que hay que hacer para crear y detener una notificación por parte de los receptores gracias por cualquier ayuda
public class USBConnect extends BroadcastReceiver {
public NotificationManager myNotificationManager;
public static final int NOTIFICATION_ID = 1;
@Override
public void onReceive(Context context, Intent intent) {
myNotificationManager = (NotificationManager) getSystemService(context.NOTIFICATION_SERVICE);
CharSequence NotificationTicket = "USB Connected!";
CharSequence NotificationTitle = "USB Connected!";
CharSequence NotificationContent = "USB is Connected!";
Notification notification = new Notification(R.drawable.usbicon, NotificationTicket, 0);
Intent notificationIntent = new Intent(context, MyClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, NotificationTitle, NotificationContent, contentIntent);
notification.flags |= Notification.FLAG_ONGOING_EVENT;
myNotificationManager.notify(NOTIFICATION_ID, notification);
}
}
y entonces el rec Eiver para cuando se desconecta esto creo que está muy bien y debería funcionar Creo que mi problema es sólo en la clase USBConnect
public class USBDisCon extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(USBConnect.NOTIFICATION_ID);
}
}
Lo he importado en realidad y sigo teniendo que es indefinido y quiere crear el método – user577732
¿Nadie tiene alguna idea? Realmente apreciaría algo de ayuda – user577732