android – GCM Notification in Dialog form

Question:

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 is on 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 the Android home , similar to what the "Whoscall" App does when receiving a call. How could this be done?

Answer:

Erick, from what I've researched this seems to be a bad practice as it confuses the user and can hinder the user in the task he is doing. The correct thing in this situation is to use notifications.

Put a notification with the two actions you want, it's the best way.

For more information: http://developer.android.com/intl/en-us/guide/topics/ui/notifiers/notifications.html

Scroll to Top
AllEscort