Skip to content Skip to sidebar Skip to footer

Handle Different Types Of Notifications In Android

I have 3 types of notifications in android.Audio/Video call and msg. How to differentiate based on notification type and open different activity on different notification. THis is

Solution 1:

Assuming that the data (msg) your receiving is from a web service. Now along with the msg parameter, you must be getting some other parameters by which you can distinguish that the following notification is Audio/Video call or message.

So you can create a method that will return the class name which can be used instead of NotificationDetailsActivity.class

privateClass<?> getClassFromType(Stringtype) {
    if(type.equals("Audio")
        returnAudioActivity.class;
    elseif(type.equals("Video")
        returnVideoActivity.class;
    elseif(type.equals("Message")
        returnMessageActivity.class;
}

The final code will be something like this:

Intent intent =new Intent(getApplicationContext(), getClassFromType(type));

Here type will be the variable that distinguishes the notification.

Hope this will solve your problem.

Post a Comment for "Handle Different Types Of Notifications In Android"