This code that i have implemnted in my app for pushing imagemessage and also link for opening in your webView

suggest change

This is my FirebaseMessagingService

public class MyFirebaseMessagingService extends FirebaseMessagingService { 
Bitmap bitmap;
@Override 
public void onMessageReceived(RemoteMessage remoteMessage) {
String message = remoteMessage.getData().get("message");
//imageUri will contain URL of the image to be displayed with Notification 
String imageUri = remoteMessage.getData().get("image");
String link=remoteMessage.getData().get("link");

//To get a Bitmap image from the URL received 
bitmap = getBitmapfromUrl(imageUri);
sendNotification(message, bitmap,link);

} 

/** 
* Create and show a simple notification containing the received FCM message. 
*/ 

private void sendNotification(String messageBody, Bitmap image, String link) {
Intent intent = new Intent(this, NewsListActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("LINK",link);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
        PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
        .setLargeIcon(image)/*Notification icon image*/
        .setSmallIcon(R.drawable.hindi)
        .setContentTitle(messageBody)
        .setStyle(new NotificationCompat.BigPictureStyle()
                .bigPicture(image))/*Notification with Image*/
        .setAutoCancel(true) 
        .setSound(defaultSoundUri)
        .setContentIntent(pendingIntent);
NotificationManager notificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
} 
public Bitmap getBitmapfromUrl(String imageUrl) {
try { 
    URL url = new URL(imageUrl);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setDoInput(true);
    connection.connect();
    InputStream input = connection.getInputStream();
    Bitmap bitmap = BitmapFactory.decodeStream(input);
    return bitmap;

} catch (Exception e) {
    // TODO Auto-generated catch block 
    e.printStackTrace();
    return null; 

} 
}}

And this is MainActivity to open link in my WebView or other browser depand on your requirement through intents.

if (getIntent().getExtras() != null) {
    if (getIntent().getStringExtra("LINK")!=null) {
        Intent i=new Intent(this,BrowserActivity.class);
        i.putExtra("link",getIntent().getStringExtra("LINK"));
        i.putExtra("PUSH","yes");
        NewsListActivity.this.startActivity(i);
        finish();
    }}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents