Android MainActivity Changing it

jaimzj9 years ago

Dear Anton,

The current code in Github for Android Client, I have downloaded to try one thing.

That is, Currently when the App is installed and run the .MainActivity is launched

I know its probably not specific to Traccar (The question).

But say for Instance, I want to display another Activity/Menu on launch to the user, and Keep The MainActivity (Preferecne settings tab) elsewhere.

What is the best way to achieve it, without affecting the (service from not running etc.)

jaimzj9 years ago

Anton the edit button on the forum stops showing sometimes.

Anyway, I thought of re-phrasing the question so that other's can also benefit from it.

  1. What is the best way to use Traccar Android Client code, When someone wants to develop an APP and only use traccar as a component/library to update locations of the devices.

  2. Where the primary Android APP is one and Traccar Client codes /library is used only for location update (behind the scenes.)

Anton Tananaev9 years ago

You can easily add more Activities if you want and change launcher activity as well. It's a standard Android project.

  1. I guess the easiest way to extend the app is to fork the project and add your UI to it. That way if there are any changes and bug fixes in the main repository, you can easily merge them into your version.

  2. Not sure if I understand the question correctly. The only thing Traccar Client does it reporting location to the server.

jaimzj9 years ago

Yes, you understood my question right. Thanks for the Input it did help :)

ghotik5 years ago

I've got a similar problem, but I was trying not to merge traccar code into my app and rather run the traccar apk directly from my app.
I made a quick test installing the traccar apk and adding to my project some java code to run a generic activity using "org.traccar.client.MainActivity" argument. The operation didn't fail, but the apk didn't run (on the android device emulator the traccar settings panel didn't show).
This the code, copied from an example:
protected void launchApp(String packageName){
try{
Intent intent = pm.getLaunchIntentForPackage(packageName);
if(intent == null){
// Throw PackageManager NameNotFoundException
throw new PackageManager.NameNotFoundException();
}else{
// Add category to intent
intent.addCategory(Intent.CATEGORY_LAUNCHER);
// Start the app
mContext.startActivity(intent);
}
}catch(PackageManager.NameNotFoundException e){
// Log the exception
//Log.e("Launch", Objects.requireNonNull(e.getMessage()));
Toast t = Toast.makeText(mContext,"traccar start failed",Toast.LENGTH_LONG);
t.show();
}
}
}
Do you think this could be a viable solution?
Why the operation had no success (with no exception and no error message)? Perhaps my app needs some special rights in its manifests?
Please, forgive the imprecision, I was turned to be an Android / java programmer recently and I'm still far from being confident.

ghotik5 years ago

me again, sorry but I can't edit my previous post.
The argument that I'm using with no error message is only "org.traccar.client", other values like "org.traccar.client.MainActivity" cause the exception.
In any case, with or without error, I can't see the traccar activity starting.