Android Push Notification无法使用WebView打开我的活动 [英] Android Push Notification not opening my activity with webview
问题描述
我按照本教程创建了一个推送通知应用程序: http://www.vogella .com/articles/AndroidCloudToDeviceMessaging/article.html
I created a push notifications app following this tutorial: http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html
它有效,当我收到通知时,我可以打开一个网站.但是,我可以将Webview布局与此推送通知应用程序结合使用吗?我觉得这一定有可能,因为电子邮件通知以这种方式工作.
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);
}
但是,链接到main.xml的HomeActivity只是一个用于注册和注销设备以接收通知的按钮.我在布局下创建了另一个文件webviewactivity.xml:
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"
/>
我创建了以下活动webviewactivity
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");
}
}
尽管出于某些原因,当我单击通知时,它会打开主页活动,而不是webview活动.
For some reason though when I click my notification it opens the home activity, not the webview activity.
推荐答案
改为通过通知打开您的WebView应用:发送PendingIntent,如
Make the notification open your WebView app instead: send a PendingIntent, as described here.
这篇关于Android Push Notification无法使用WebView打开我的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!