2014-09-24 5 views
0

Обратите внимание, что этот вопрос (Phonegap PushNotification to open a specific app page) можно открыть в приложении cordova при нажатии на push-уведомление. Из ответа я не могу видеть указанный код в своем плагине. Вот мой код из GCMIntentService.java файлаКордока pushnotification Открыть специальную страницу в android

@Override 
    protected void onMessage(Context context, Intent intent) { 
     Log.d(TAG, "onMessage - context: " + context); 

     // Extract the payload from the message 
     Bundle extras = intent.getExtras(); 
     if (extras != null) 
     { 
      // if we are in the foreground, just surface the payload, else post it to the statusbar 
      if (PushPlugin.isInForeground()) { 
       extras.putBoolean("foreground", true); 
       PushPlugin.sendExtras(extras); 
      } 
      else { 
       extras.putBoolean("foreground", false); 

       // Send a notification if there is a message 
       if (extras.getString("message") != null && extras.getString("message").length() != 0) { 
        createNotification(context, extras); 
       } 
      } 
     } 
    } 

    public void createNotification(Context context, Bundle extras) 
    { 
     NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     String appName = getAppName(this); 
     Intent notificationIntent = new Intent(this, PushHandlerActivity.class); 
     notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     notificationIntent.putExtra("pushBundle", extras); 
     PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

     int defaults = Notification.DEFAULT_ALL; 

     if (extras.getString("defaults") != null) { 
      try { 
       defaults = Integer.parseInt(extras.getString("defaults")); 
      } catch (NumberFormatException e) {} 
     } 

     NotificationCompat.Builder mBuilder = 
      new NotificationCompat.Builder(context) 
       .setDefaults(defaults) 
       .setSmallIcon(context.getApplicationInfo().icon) 
       .setWhen(System.currentTimeMillis()) 
       .setContentTitle(extras.getString("title")) 
       .setTicker(extras.getString("title")) 
       .setContentIntent(contentIntent) 
       .setAutoCancel(true); 

     String message = extras.getString("message"); 
     if (message != null) { 
      mBuilder.setContentText(message); 
     } else { 
      mBuilder.setContentText("<missing message content>"); 
     } 

     String msgcnt = extras.getString("msgcnt"); 
     if (msgcnt != null) { 
      mBuilder.setNumber(Integer.parseInt(msgcnt)); 
     } 

     int notId = 0; 

     try { 
      notId = Integer.parseInt(extras.getString("notId")); 
     } 
     catch(NumberFormatException e) { 
      Log.e(TAG, "Number format exception - Error parsing Notification ID: " + e.getMessage()); 
     } 
     catch(Exception e) { 
      Log.e(TAG, "Number format exception - Error parsing Notification ID" + e.getMessage()); 
     } 

     mNotificationManager.notify((String) appName, notId, mBuilder.build()); 
    } 

    private static String getAppName(Context context) 
    { 
     CharSequence appName = 
       context 
        .getPackageManager() 
        .getApplicationLabel(context.getApplicationInfo()); 

     return (String)appName; 
    } 

    @Override 
    public void onError(Context context, String errorId) { 
     Log.e(TAG, "onError - errorId: " + errorId); 
    } 

.Please помочь

ответ

0

в exsample you're связывании, they're получать дополнительную называемый message от намерения, который вызывает активность в методе onCreate , Затем они calling super.loadUrl().

Переопределите onCreate вашего действия в PhoneGap и откройте URL-адрес, который вы можете передать, в намерении, которое вы устанавливаете в дополнительном уведомлении.

+0

Можете ли вы показать пример кода? –

+0

вы уже связаны с http://stackoverflow.com/questions/16689092/phonegap-pushnotification-to-open-a-specific-app-page – eduyayo

Смежные вопросы