• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

help for java context

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote an Xposed applet, but I can't use the system.loadlibray method due to version issues. I happened to see on the Internet that ReLinker can loadlibray. I have completed the interface display and can use it normally, but XPosed only has ordinary Class. The original system method is system.loadlibray(string), but Relinker uses Relinker.loadlibray(context, string). I have tried many methods but cannot get the Context of MainActivity. Can anyone tell me what method I can use?
 
chuang di
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
code:

 
Saloon Keeper
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not familiar with the libraries you mention, but an Activity is a Context. How is the SmartDialXposed object created? Can you pass a reference to the Activity as a parameter?
 
chuang di
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i try
public class MContext {
   private Map<String, Object> contextMap = new HashMap<>();

   public void set(String key, Object value) {
       contextMap.put(key, value);
   }

   public Object get(String key) {
       return contextMap.get(key);
   }
}
but pass context for null object
 
Saloon Keeper
Posts: 28319
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added Code Tags to make the first example more readable. I recommend that you put them in yourself when posting structured text (code, XML, SQL, fixed text and so forth).

Your second example does not extend any sort of class that would have a Context. It's basically just a dictionary.

Finally, I don't like the "-jni" on that library name.  That smells like Java Native Interface and I've never heard of anyone doing JNI on Android, and I'm doubtful it would work, since I'm fairly sure that a wide variety of different processors use Android and JNI very definitely breaks the "write-once/run-anywhere" concept of Java. Is there a possibility that you can do what you need with something more off-the-shelf? Especially since if it's old code, there are likely improvements available.
 
chuang di
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:Your second example does not extend any sort of class that would have a Context. It's basically just a dictionary.

I know the second example is just a dictionary, but I don't know how to write it to get the Context of MainActivity. I use hashmap to save the Context of MainActivity, but I can't get it. I don't need an interface. I just need to get the context and execute the loadlibray command. Please tell me how to write or how to expand the second example to receive the Context, thank you!

 
Norm Radder
Rancher
Posts: 5035
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is the connection between the MainActivity class and the SmartDialXposed class?
The MainActivity has a reference to the Context.  It could be passed to the SmartDialXposed class via its constructor.
For example: code this in MainActivity:  new SmartDialXposed(this) to pass a reference to the Context.
 
Tim Moores
Saloon Keeper
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:Finally, I don't like the "-jni" on that library name.  That smells like Java Native Interface and I've never heard of anyone doing JNI on Android, and I'm doubtful it would work, since I'm fairly sure that a wide variety of different processors use Android and JNI very definitely breaks the "write-once/run-anywhere" concept of Java.


There's no problem using JNI on Android. Gradle can create native code for all of ARM, ARM-64, X86 and x86-64, and ship that all in the same Android app.
 
I’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic