如何将FCM密钥和值传递给主要活动中的Web视图?

时间:2016-08-30 08:32:20

标签: android webview firebase firebase-cloud-messaging

我有一个Android应用程序,在WebView中加载了一个网址,我实施了Firebase通知云消息传递。

通过FCM自定义数据(键和值)我想发送带有WebView的网址。

我的问: 如何访问Activity WebView创建的private void sendNotification(String messageBody) { Intent intent = new Intent(this, Principal.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle("Formación Alcalá") .setAutoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent) .setStyle(new NotificationCompat.BigTextStyle() .bigText(messageBody)) .setContentText(messageBody); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notificationBuilder.build()); } 中的密钥和值?

这是我的notificatión文件类:

public class Principal extends AppCompatActivity {

private WebView myWebView;
private FirebaseAnalytics mFirebaseAnalytics;

private int getScale(){
    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int width = display.getWidth();
    Double val = new Double(width)/new Double(width);
    val = val * 100d;
    return val.intValue();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
    setContentView(R.layout.activity_principal);
    if(CheckNetwork.isInternetAvailable(Principal.this)) {
        myWebView = (WebView) findViewById(R.id.webview);
        WebSettings webSettings = myWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        myWebView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                //hide loading image
                findViewById(R.id.imageLoading1).setVisibility(View.GONE);
                //show webview
                findViewById(R.id.webview).setVisibility(View.VISIBLE);
                //view.reload();
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                if (url.startsWith("tel:") || url.startsWith("mailto:") || url.startsWith("sms:")) {
                    // magic
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    startActivity(intent);
                    return true;
                }
                if (Uri.parse(url).getHost().endsWith("formacionalcala.es") || Uri.parse(url).getHost().endsWith("paypal.com")) {
                    // This is my web site, so do not override; let my WebView load the page
                    return false;
                }

                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(intent);
                return true;
            }
        });
        myWebView.getSettings().setLoadWithOverviewMode(true);
        myWebView.getSettings().setUseWideViewPort(true);
        myWebView.loadUrl("http://www.formacionalcala.es/app/");
    }else{
        // No hay internet asi que muestro un popup para salir de la app.
        NoInternetDialog dialogo = new NoInternetDialog();
        dialogo.show(getFragmentManager(), "tag");
    }
}

@Override
public void onBackPressed() {
    if(myWebView.canGoBack()) {
        myWebView.goBack();
    } else {
        super.onBackPressed();
    }
}

这是我的主要活动:

<div class='images'></div>
<div class='toload'></div>
<div class='sky'></div>
<select class="select01">
    <option value="winners_02/2015.php">2015 - DOPS 6</option>
    <option value="winners_02/2014.php">2014 - DOPS 5</option>
    <option value="winners_02/2013.php">2013 - DOPS 4</option>
</select>

<div class='images'></div>
<div class='sea'></div>
<div class='toload'></div>  // target

}

我想捕获FCM从主要活动发送的变量。

非常感谢,抱歉我的英语不好。

0 个答案:

没有答案