简体   繁体   中英

Android Push Notification not opening my activity with webview

I created a push notifications app following this tutorial: http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html

It works and when I get the notification, I can open a website. However, am I able to combine the webview layout with this push notifications app? I feel like it has to be possible because the email notifications work in that way.

Here is my code which handles the notification I receive:

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);
}

However, the HomeActivity which is linked to the main.xml is just a button to register and unregister your device for receiving the notifications. I created another file, webviewactivity.xml under layout:

 <?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"
 />

and I created the following 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");
    }
}

For some reason though when I click my notification it opens the home activity, not the webview activity.

请通知打开你的WebView应用程序,而不是:发送的PendingIntent,描述在这里

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM