Android push notifications with webview?

I created the push push application after this tutorial: http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html

It works fine and dandy, and when I get a notification, I can open a website. However, can I combine the webview layout with this push notification application? I feel this should be possible because email notifications work this way.

Here is my code that processes the received notification:

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

However, the HomeActivity associated with main.xml is just a button to register and unregister a device to receive notifications. I created another file, webviewactivity.xml under the 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 {

/** 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
}

  }

- , , , -.

+5
1

WebView: PendingIntent, .

+3

All Articles