2015-07-12 65 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