0

I want notify a notification on a widget. but it doesn't show it

I call this function but in emulator android 4.3 just play sound when call this function. and it doesn't show any notification

void DisplayZiyaratPage()
        {

            NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(this)
                .setContentTitle("Title")
                .setContentText("text")
                .setSound(Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.alarm_sound))
                .setDefaults(Notification.DEFAULT_VIBRATE);
            Intent intent = new Intent(this, ZiyaratActivity.class);

            PendingIntent pendingIntent =PendingIntent.getActivity(this, 0, intent, 0);
            notificationBuilder.setContentIntent(pendingIntent);
            NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(0, notificationBuilder.build());
        }
BenMorel
  • 34,448
  • 50
  • 182
  • 322

1 Answers1

0

try this

NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.notification_icon)
        .setContentTitle("My notification")
        .setContentText("Hello World!");
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, ResultActivity.class);

// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(ResultActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(
            0,
            PendingIntent.FLAG_UPDATE_CURRENT
        );
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(mId, mBuilder.build());

the NotificationCompat.Builder class has been added to the Support Package so we can use this to support API level v4 and up:

http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html

If your app supports versions of Android as old as API level 4, you can instead use NotificationCompat.Builder, available in the Android Support library.

sunil
  • 660
  • 8
  • 20