Push-уведомление Android с помощью WebView?

Я создал приложение для push-уведомлений, следуя этому руководству:http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html

Оно работает нормально и денди, и когда я получаю уведомление, я могу открыть веб-сайт. Однако могу ли я совместить макет веб-просмотра с этим приложением push-уведомлений? Я чувствую, что это должно быть возможно, потому что уведомления по электронной почте работают таким образом.

Вот мой код, который обрабатывает уведомление, которое я получаю.:

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

Однако HomeActivity, которая связана с main.xml, — это просто кнопка для регистрации и отмены регистрации вашего устройства для получения уведомлений. Я создал еще один файл, webviewactivity.xml в макете :

 
 

, и я создал следующее действие, 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
     }

 }

. Однако по какой-то причине, когда я нажимаю на свое уведомление, оно открывает домашнюю активность, а не активность веб-просмотра.

6
задан Black 11 December 2019 в 08:01
поделиться