Android 推送通知未使用 webview 打开我的 Activity

标签 android push-notification android-webview

我按照本教程创建了一个推送通知应用程序:http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html

它有效,当我收到通知时,我可以打开一个网站。但是,我可以将 webview 布局与这个推送通知应用程序结合起来吗?我觉得它必须是可能的,因为电子邮件通知以这种方式工作。

这是我处理收到的通知的代码:

private void handleData(Context context, Intent intent) {
    String app_name = (String) context.getText(R.string.app_name);
    String message = intent.getStringExtra("message");

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(android.R.drawable.stat_notify_chat, app_name + ": " + message, 0);

    PendingIntent pendingIntent = PendingIntent.getActivity(context, -1, new Intent(context, webviewactivity.class), PendingIntent.FLAG_UPDATE_CURRENT); // 
    notification.when = System.currentTimeMillis();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.setLatestEventInfo(context, app_name, message, pendingIntent); //
    notificationManager.notify(0, notification);
}

但是,链接到 main.xml 的 HomeActivity 只是一个按钮,用于注册和注销您的设备以接收通知。我在布局下创建了另一个文件 webviewactivity.xml:

 <?xml version="1.0" encoding="utf-8"?>
 <WebView  xmlns:android="http://schemas.android.com/apk/res/android"
           android:id="@+id/webview"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
 />

我创建了以下 Activity ,webviewactivity

public class BHWebView extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.bhwebview_activity);

        WebView myWebView = (WebView) findViewById(R.id.webview);
        myWebView.loadUrl("http://www.badgerherald.com");
    }
}

出于某种原因,当我点击我的通知时,它会打开主页 Activity ,而不是 WebView Activity 。

最佳答案

改为让通知打开您的 WebView 应用程序:发送一个 PendingIntent,如所述 here .

关于Android 推送通知未使用 webview 打开我的 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10476616/

相关文章:

ios - 适用于iOS模拟器的IBM-Bluemix Push Service构建失败

android - WebView 点击打开手机浏览器

android:在 ListView 行内单击按钮播放音频

android - NFC随意禁用/启用前台调度

android - 我如何在android studio中导入或打开react-native项目?

android - 当我的 Android 应用程序处于前台时,我想隐藏其他应用程序的所有通知。这可能吗?如何?

ios - 应用程序在后台时不显示推送通知

java - 从 Android 网站解析

android - 如何打开新 Activity 的 WebView 链接?

android - 从 Android web View 的 HTML 页面中包含的 js 文件进行的 ajax 调用是否面临 CORS 问题?