Android Notification Push avec WebView?
J'ai créé un push notifications d'application suivant ce tutoriel: http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html
Il fonctionne très bien et dandy, et quand je reçois la notification, je peux ouvrir un site web. Cependant, je suis en mesure de combiner la webview mise en page avec ce push notifications d'application? J'ai l'impression que cela est possible parce que l'e-mail les notifications de travaux.
Voici mon code qui gère la notification-je recevoir:
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);
}
Cependant, la HomeActivity qui est liée à la main.xml est juste un bouton pour enregistrer et annuler l'inscription de votre appareil pour recevoir les notifications. J'ai créé un autre fichier, webviewactivity.xml sous mise en page:
<?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"
/>
et j'ai créé l'activité suivante, 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
}
}
Pour quelque raison que lorsque je clique sur ma notification qu'il ouvre la maison de l'activité, pas la webview activité.
OriginalL'auteur Kevin | 2012-05-07
Vous devez vous connecter pour publier un commentaire.
Procéder à la notification ouvrir votre WebView app plutôt: envoyer un PendingIntent, comme décrit ici.
Non, vous pouvez mettre la WebView dans une Activité dans la même application.
Alright. Je suis donc fondé ma WebView hors de ce tutoriel: developer.android.com/guide/webapps/webview.html. Mais je suis un peu confus quant à la façon d'intégrer la WebView activité. Pourrais-je faire une nouvelle activité pour la WebView dans le pushnotifications? Droit maintenant, le main.xml pour le pushnotifications est un modèle qui vient de registres et affiche le numéro d'enregistrement de l'appareil. Quand j'ai essayé de copier le WebView, j'ai eu une erreur (oublié l'erreur exacte, mais je peux le regarder et de le poster). Merci
La notification a un point de vue, mais lance le WebView activité, qui est séparé.
Passons sur toutes les œuvres aujourd'hui. Merci!
OriginalL'auteur Yusuf X