how to load class from one another application in android - java

is there anyway to load a class from differen application ?
for example, I have two application and one of them has SomeExample class file. and I want to load it and use from another application.
I try to use, Class.forName. but this function throws "ClassNotFoundExpetion".

Is there anyway to load a class from differen application ?
No, sorry.
You can use startActivity(), startService(), and so on to launch components of another application, but each application's code remains separate.

While in most cases unadvisable (Android has many APIs to solve the common problems of inter-app communication without sharing code), it's possible by using PathClassLoader.
See also Android- Using DexClassLoader to load apk file.

Related

How can I implement remote server which will run on separate process in android?

I need to create two different applications (two different processes) in Android. One will have activity and the other should just be service which would be started from the activity code.
I need it to be separate because in service I need to create one more instance of SDK that I am using in my activity.
I can't find any example how to implement and connect these two applications, does anyone can help me?
Thanks in advance
I'd suggest not doing it at all. Android is really not set up to be a server, with power limitations and the ability of the OS to kill background processes at any time it just isn't meant to be reliable- which is exactly what a server needs. I would suggest reposting with more details of what you need (because "need to create one more instance of SDK" doesn't make any sense- SDKs don't have instances, and why would you not be able to do more than 1 instance in your Activity) and seeing if you can get alternative architetures.

Application() of a AAR library

I created an AAR library on android and imported it into another project
When I try to execute something from this library, it gives an error saying that Room was not started, I start Room in my Application (),
which leads me to think that the Application () of the AAR library is not being called
How do I get this Application () to start?
There isn't any application class in the android-library that triggered automatically. You should expose an entry point in your library in order to receive the context and init everything you need from there (for example the Room DB).
Another way (maybe a little bit more complicated) is to create a provider and attach it in the application's lifecycle. Here is an example.

programmatically simulate user input from one Android application to another

Is there any way to programmatically simulate user input from one android application to another ? I'd like to create android application that will be send commands to another. For example - user touch screen action.
This is only possible using one of these two approaches:
Root your device
Direct injection to /dev/input/eventX
Using InputManager.injectTouchEvent()
Using WindowManager.injectPointerEvent()
Create an AccessibilityService. Notice that this is not guaranteed to work with all third-party apps.
It is possible with AccessiblityService since Android 4.0. Details in my answer to another question.
It is not possible, this would be too high security risk. Maybe add what you actually would like your app to do?
If this is for testing then this can be achived with test framework, for example you can use uiautomator:
http://developer.android.com/tools/help/uiautomator/index.html

Send email from game on libGDX engine on Android device?

In my debug version of game, I want to take actual information about game progress from many users on my email. As you know, code in libGDX is writing on native Java without Android context. What suggestions do you know for my problem?
See this page on the libgdx wiki: Interfacing with platform specific code.
What you need to do is create an interface with the methods you need. Then create a class implementing that interface in your Android project. (And other projects if needed, if not needed, just create dummy-files that do nothing)
Then instantiate that proper class where you launch your game, and pass in the object to the game and use it there.
Just follow the guide, and then you can use Android stuff in your game (through an interface).
You can try to use ACRA (Application Crash Report for Android). It automaticly sends you crash reports about every error in your application, that is very usefull by itself. And as I see it has method to declare your own varibles which will be send. That may be what you want. Also it's recommended by libgdx.

Making a pluggable Android messaging app

I'm making a messaging app and I want to be able to extend it by using plugins.
The plugin might, for example, replace :) with a smiley image.
I've written some test code which uses intent filters to find the plugins, but I can't find a way to create an instance of the that plugin class.
Is it possible to do this, and if not, what would be the best approach/best alternative to this?
Thanks.
Because applications in android each run in their own VM, I don't think the classloader of your application will have access to the classes defined in the plugin. What you can do, however, is to pass the data between your main application and the plugin via Intents. If the plugin needs data from the main application, create a ContentProvider to make the data available.

Categories

Resources