2015-07-12 2 views
0

Я пытаюсь показать уведомления, отправленные моим приложением, но они не работают. В моем приложении, при условии условия, уведомление должно быть показано. Это метод, который я использую.Уведомления в Android не работают

public void showNotification(){ 

    NotificationCompat.Builder notificacion = new NotificationCompat.Builder(MapsScreen.this); 
    notificacion.setTicker("Bicis cerca") 
      .setContentTitle("Bicis cerca") 
      .setContentText("Bicis a menos de " + ProfileScreen.getDistance()) 
      .setSound(Uri.parse("android.resource://com.app.sb" + R.raw.bike)); 

    PendingIntent myPendingIntent; 
    Intent myIntent = new Intent(); 
    Context myContext = getApplicationContext(); 

    myIntent.setClass(myContext, MapsScreen.class); 
    myPendingIntent = PendingIntent.getActivity(myContext, 0, myIntent, 0); 
    notificacion.setContentIntent(myPendingIntent); 

    Notification n = notificacion.build(); 

    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    nm.notify(1,n); 

    Log.d("Status", ": entrando"); 
} 

Этот метод вызывается после того, как условие срабатывает, и mehtod работает, потому что он пишет на бревне.

Большое спасибо.

ответ

1

У вас отсутствует обязательный аргумент.

setSmallIcon, setContentTitle, setContentMessage являются обязательными.

Добавить setSmallIcon в ваш NotificationBuilder, и он должен работать.

Код: Android Developers

Смежные вопросы