0
使用Firebase我试图通过'值'URL链接在'钥匙'中发送通知。我每次都收到通知,但问题是我的价值中发送的URL链接不会在我的webview中打开。使用Firebase发送带有在我的WebView中打开的链接的通知
在这里,我附上我的WebView活动
public class WebViewActivity extends AppCompatActivity {
private WebView notiWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
notiWebView = (WebView) findViewById(R.id.NotiWebView);
if(getIntent().getExtras() != null){
for(String key: getIntent().getExtras().keySet()){
if(key.equals(("url"))){
notiWebView.loadUrl(key);
}
}
}
}
这里是我的FirebaseInstanceIdService
public class MyFirebaseInstanceIdService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh(){
String token = FirebaseInstanceId.getInstance().getToken();
Log.d("TOKEN",token);
}
,这里是FirebaseInstanceMessagingService
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Intent intent = new Intent(this,WebViewActivity.class);
intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setContentTitle("My Notification:");
notificationBuilder.setContentText(remoteMessage.getNotification().getBody());
notificationBuilder.setAutoCancel(true);
notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
任何帮助将不胜感激。提前致谢!
这可能会帮助你-http://stackoverflow.com/a/42211049/6291914 –
感谢这个@AL –