我在本教程後創建了一個推送通知應用程序:http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html帶有WebView的Android推送通知?
它工作正常,並且當我得到通知時,我可以打開一個網站。但是,我能夠將webview佈局與此推送通知應用程序結合起來嗎?我覺得應該有可能,因爲電子郵件通知以這種方式工作。
這裏是我的代碼,它處理我收到通知:
private void handleData(Context context, Intent intent) {
String app_name = (String)context.getText(R.string.app_name);
String message = intent.getStringExtra("message");
// Use the Notification manager to send notification
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// Create a notification using android stat_notify_chat icon.
Notification notification = new Notification(android.R.drawable.stat_notify_chat, app_name + ": " + message, 0);
// Create a pending intent to call the webviewactivity when the notification is clicked
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;
// Set the notification and register the pending intent to it
notification.setLatestEventInfo(context, app_name, message, pendingIntent); //
// Trigger the notification
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 {
/** Called when the activity is first created. */
@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");
// TODO Auto-generated method stub
}
}
出於某種原因,不過,當我點擊我的通知,它打開了家裏的活動,而不是webview活動。
嗨,我是新的android應用程序,我想知道的是一個webview應用程序在用戶的可用性(電子商務網站)方面良好?我有一個電子商務網站,我將它轉換成webview android應用程序,然後將ii能夠發送pushnotification給我的應用程序用戶? 請幫我這個 –