Reputation: 3
i'm trying to show notifications sent by my app, but they don't work. In my app, given a condition, the notification must be shown. This is the method I'm using.
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");
}
This method is called after the condition is triggered, and the mehtod works because it writes on the log.
Thanks so much.
Upvotes: 0
Views: 97
Reputation: 7751
You are missing a compulsory argument.
setSmallIcon
, setContentTitle
, setContentMessage
are compulsory.
Add setSmallIcon
to your NotificationBuilder
and it should work.
Reference: Android Developers
Upvotes: 1