android - Show dialog in hooked method by xposed running in thread -


i try show alertdialog within hooked method xposed. problem method running in threads, , thread running in thread, etc...

for example : activity -> thread -> thread -> ... -> function

is there way show alertdialog ? have context, since hooked function not in main thread, useless.

edit (some code) :

public class xposed implements ixposedhookloadpackage { private context ctx; private queue<string> queue = new linkedlist<>();  public void handleloadpackage(final loadpackageparam lpparam) throws throwable {     if (!lpparam.packagename.equals("xxx.xxx.xxx")) {         return;     }      // here context static class extending application     findandhookmethod("xxx.xxx.xxx", lpparam.classloader, "attachbasecontext", context.class, new xc_methodhook() {         @override         protected void afterhookedmethod(methodhookparam param) throws throwable {             xposedbridge.log("context modified");             ctx = (context) param.args[0];         }     });      findandhookmethod("com.xxx.xxx.xxx", lpparam.classloader, "e", "com.xxx.xxx.xxx", string.class, new xc_methodhook() {         @override         protected void afterhookedmethod(final methodhookparam param) throws throwable {             if (!(param.args[1]).equals("xxxxxxxxxxxxxx")) {                 return ;             }              xposedbridge.log("new element detected detected");             object param = param.args[0];             object info = callmethod(param, "q");              // here, want show alertdialog             dialoginterface.onclicklistener dialogclicklistener = new dialoginterface.onclicklistener() {                 @override                 public void onclick(dialoginterface dialog, int which) {                     if (which == dialoginterface.button_positive) {                      }                 }             };              // classic error can't modify ui             // in thread has not called looper.prepare()             alertdialog.builder builder = new alertdialog.builder(ctx);             builder.setmessage("are sure ?")                     .setpositivebutton("yes", dialogclicklistener)                     .setnegativebutton("no", dialogclicklistener)                     .show();         }     }); } 

thanks

you can keep reference of current activity (android.app.instrumentation.newactivity). goes this:

class<?> instrumentation = xposedhelpers.findclass(                 "android.app.instrumentation", lpparam.classloader);  method method = instrumentation.getmethod("newactivity",                  classloader.class, string.class, intent.class);  xposedbridge.hookmethod(method, ihook); 

in case ihook hook of yours stores current activity statically can invoke runonuithread wherever are:

public class activityhook extends xc_methodhook{      /* assure latest read of write */     private static volatile activity _currentactivity = null;      public static activity getcurrentactivity() {         return _currentactivity;     }      @override     protected object afterhookedmethod(methodhookparam param)             throws throwable {         _currentactivity = (activity) param.getresult();     } } 

then able anywhere:

activityhook.getcurrentactivity().runonuithread(...); 

good luck!


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -