Category Archives: RemoteViews

Extract a Instance of specific class RemoteViews which don’t know to how to make.

Extract a Instance of specific class RemoteViews which I don’t know to how to make.


Return instance that i’m looking for.

If type == 0, then return a instance first found.
If type == 1, then return a instance second found.


The problem is, because of tree search, maybe return different value depending on the situation.



ex) find a instance of TextView in RemoteViews.

count is a static variable.


      static public TextView extractTextView(Context context, RemoteViews views, int type) {
           
        Context remotePackageContext ;
        remotePackageContext  = context.getApplicationContext();
        try{
              remotePackageContext = context.createPackageContext(TARGET_PACKAGE, 0);
        }catch(Exception e){;}
       
        LinearLayout ll = new LinearLayout(remotePackageContext );
        View view = views.apply(remotePackageContext, ll);
        count = 0;
       
        LogControl.i(TAG, “msg = ” + searchForTextView(view,2).getText().toString());
        count = 0;
       
        return searchForTextView(view,type);
    }
     
     
    static public TextView searchForTextView(View view, int duration) {
        if (view instanceof TextView) {
              TextView textView = (TextView)view;
              String text = textView.getText().toString();
              count ++;
              LogControl.i(TAG, “tview string = ” + text);
             
              if(textView.getTag() == null && count > duration){
                  
                   return (TextView)view;
              }
        }

        if (view instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) view;
            for (int i = 0; i < viewGroup.getChildCount(); i++) {
                TextView result = searchForTextView(viewGroup.getChildAt(i), duration);
                if (result != null) {
                     if(count > duration)
                           return result;
                }
            }
        }
        return null;
    }