このチュートリアルに従ってプッシュ通知アプリを作成しました:http ://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html
それは動作し、通知を受け取ると、Webサイトを開くことができます。ただし、Webビューレイアウトをこのプッシュ通知アプリと組み合わせることができますか?メール通知はそのように機能するので、それは可能でなければならないと感じています。
受信した通知を処理するコードは次のとおりです。
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");
}
}
何らかの理由で、通知をクリックすると、Webビューアクティビティではなく、ホームアクティビティが開きます。