GCM Notification in Dialog form

Asked

Viewed 180 times

3

I’m making an application that receives alert messages using Google Cloud Messaging, as soon as it receives a message in the background the App triggers a notification that stays in the Android notification bar with this code below:

private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_ic_notification)
            .setContentTitle("GCM Message")
            .setContentText(message)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

I would like to display this notification as a Dialog in home Android, something similar like the "Whoscall" App does when receiving a call. How could this be done?

  • Does Whatsapp also not do what you’re asking? The mobile is off, launched a GCM for the same, and when the user turns on the mobile even without unlocking the Dialog will be appearing.

  • this, in the case on my device with Android 5.0 Whatsapp performs the same process that this code posted above does, displays an icon in the notification bar where by sliding down bar is possible to see all notifications from mobile, and when clicking on the notification of my application it opens Mainactivity, but would like to send another form of notification, example if you are moving the Facebook App and receive a notification, would like to display a small Popup in the center of the screen with 2 buttons, but seeing Facebook behind App to cancel the Dialog of this notification.

1 answer

1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.