2017-04-07 10 views
1

2つ以上の行がある場合、WhatsApp通知からメッセージを取得する方法を探しています。Java Reflection Androidの内部クラスによるWhatsAppからのメッセージの取得

AndroidのReflectionから内部クラスのプライベート変数から値を取得しようとしています。私はInboxStyle通知を構築するために使用されるcharsequenceの 'mTexts' ArrayListを取得しようとしています。私はwhatsappからのメッセージを探しています。最後のwhats updateから、notificationListener()が複数行の通知を受け取った通知のEXTRAはありません(私は最初の行しか取得できません)。

行を得るための方法はそれだけの価値があります。

これは私のコードです。

@Override 
    public void onNotificationPosted(StatusBarNotification sbn) { 
     super.onNotificationPosted(sbn); 

    Class[] declaredClasses = sbn.getNotification().getClass().getClasses(); 

     for (Class c : declaredClasses){ 

      if(c.getName().contains("Notification$InboxStyle")){ 
       Class inboxStyleClass = c.getClass(); 

       Field[] fields = inboxStyleClass.getDeclaredFields(); 

       for(Field field : fields){ 

        if(field.getName().contains("mText")){ 

         Field fmText = null; 
         try { 
          fmText = inboxStyleClass.getDeclaredField("mTexts"); 
         } catch (NoSuchFieldException e) { 
          e.printStackTrace(); 
         } 

         ArrayList<CharSequence> mTextsArrayList = null; 

         fmText.setAccessible(true); 

         try{ 
          mTextsArrayList = (ArrayList<CharSequence>) fmText.get(**WICH OBJECT MAY USE HERE**); 
         }catch(IllegalAccessException e){ 
          e.printStackTrace(); 
         } 

         for(CharSequence value : mTextsArrayList){ 
          Log.i("XXX","Results are: "+value.toString()); 
         } 
        } 
       } 

      } 

     } 

} 

私が正しくMTEX​​Tフィールドに達するが、私はそれから値を取得しcan't。

私はそれがうまく動作するかどうかを確認するために、新たなNotification.InboxStyle()オブジェクト

Notification.InboxStyle iStyleObjectToGetTheValue = new Notification.InboxStyle(); 

を使用することを試みたが、それは

inboxStyle = (ArrayList<CharSequence>) fmText.get(iStyleObjectToGetTheValue); 

を行いますが、私は、通知から値を必要とします。どのように私はそれを達成することができますか?

私も)あなたがStatusBarNotification.getNotification(によって取得することができRemoteViewsを膨らませるメッセージ行を取得しようとしました。THE_REMOTE_VIEWDeviceMonitorを使用しているため、デバイスのscreenshootを取るとのIDを見ることができますビュー...しかしそれで運がなかった。

行を得るための方法はそれだけの価値があります。

すべてのヘルプが歓迎されます! ありがとうございます! RemoteView.applyのためのドキュメントによると

+0

あなたは通知からcontentView/bigContentViewを取得し、テキストを見つけるためにそれらを点検することはできません:通知)を構築する場合にのみ使用する必要がありますか? –

+0

リモートビューを検査するにはどうすればよいですか?-Iは、ビューのノードを取得することにより、検索が、didn't何も信頼性を...たぶん私は間違っていた.... bigContentViewを膨らましようとすると、nullポインタを取得 – Dan

答えて

0

():

ビューは、(コンテキストのコンテキスト、のViewGroupの親)を適用する - このオブジェクトによって表されるビュー階層を膨張させると、すべてのアクションを適用します。

親を作成し、コンテキストをRemoteView.apply()に指定できます。テキストを検索する結果の表示を点検:(マニュアルに従って、より慎重にこれを読むことあなたは、このパラメータを読んでいることをするために、Googleはおそらく意味しなかったことを私に告げるよう

@Nullable 
public View getBigContentView (StatusBarNotification statusBarNotification) { 
    RemoteViews bigContentView = statusBarNotification.getNotification().bigContentView; 
    return bigContentView != null ? bigContentView.apply(ctx, null) : null; 
} 

これは、ヌガーの携帯電話では動作しない場合があります

* As of N, this field may be null. The expanded notification view is determined by the 
* inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be 
* supplied with {@link Notification.Builder#setCustomBigContentView(RemoteViews)}. 
+0

- 私()を見つけることを試みました。これは私のコードです... RemoteViews rv = sbn.getNotification()。bigContentView; LayoutInflaterインフレータ=(LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); ViewGroup localView =(ViewGroup)インフレータ.inflate(rv.getLayoutId()、null); rv.reapply(ctx.getApplicationContext()、localView);用 は、(i = 0、int型、私は((のViewGroup)localView).getChildCount()<; ++ I){ 表示nextChild =((のViewGroup)localView).getChildAt(I)。 Log.i( "XXX"、 "ID:" + nextChild.getId()); } – Dan

+0

これで幸運なことは...何もできません...関心のない2つのIDだけです。ビューがこのIDに属することをどのように知ることができますか? – Dan

関連する問題