【发布时间】:2012-05-07 04:24:34
【问题描述】:
我按照本教程创建了一个推送通知应用程序: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"
/>
我创建了以下活动,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 活动。
【问题讨论】:
-
嗨,我是安卓应用的新手,我想知道一个 webview 应用在用户可用性方面是否良好(对于电子商务网站)?我有一个电子商务网站,我会将其转换为 webview android 应用程序,然后我可以向我的应用程序用户发送推送通知吗?请帮我解决这个问题
-
@NikhilAgrawal,webview 太可怕了。有很多错误和缺失的功能。我什至无法打开 PDF 文件。
-
问题的名称有点误导,我以为你的意思是 Android 上的 Chrome 推送通知
标签: android push-notification android-webview