Can I package Activity/ies in an aar library - android

I have a working android app. The client wants to expose part of it as an "SDK" (actually library) to other developers. The idea is that other developers should be able to start a workflow from this so called "SDK" which spans through a few activities.
So my question is: Can I package an Activity (or more Activities) in an aar, which the end developer can use?
If yes: Does she have to do anything else, besides listing the Activity/Activities within their own Manifest, or are they merged automatically?
If no: How can I expose an Activity to other developers (without Intents, because there is no guarantee my App is installed on the end device)

yes you can do.
If i recall correctly, you may need to tools:replace="android:allowBackup,android:icon,android:label" amongst others in the manifest of the apk-activity, or you will get some warnings from the manifest merger.
And I believe you need to declare an parentActivity, that (or one of its members) will be able to launch the activity from the aar via Intent.
Manifest of the apk:
<activity
android:name="com.somepackage.LibraryActivity"
android:parentActivityName="com.someotherpackage.UsingActivity"/>

Related

Compiling system-api calls for 3th party apps with root process

in android system api there are several methods which are not compileable for a 3th party app (means: not a system app/system signature signed app).
special example: goToSleep() in PowerManager. (which turns off screen)
goToSleep is also marked as removed if you look at docs at developer.android.com history. but in fact it is defined in sdk source code when you look in e.g. powermanager.java.
if you try to use it, you get standard compiler error, unknown reference.
but in e.g. well known 3th party launcher Lawnchair they use it in a root service (provided by john wu's libsu) to turn of screen after double tap screen. so the root service has of course the permissions at runtime to use that method.
at runtime.. but what settings in android studio project enable to get that compiled??
the source of lawnchair is at github. that special source file is:
https://github.com/LawnchairLauncher/lawnchair/blob/12.1-dev/lawnchair/src/app/lawnchair/root/RootHelperBackend.java
thanks in advance for some tips

Multiple applications with different names for the same code base

Reading this article, thought having the same problem - One code base, two applications on Android
I have created an application testApp that has items like topics, splash screens, logos, charts, rules, statuses and/or events.
Now, I want different applications (testApp_USA, testApp_Canada, testApp_Australia)from the same code base and put them on Google Play Store so that if user downloads the application, say, testApp_USA, then only the specific items to that region should be shown like splash Screen of USA, USA logos, etc..
So I want to configure multiple applications according to countries and then set the items as defaults according to which application the user has downloaded.
Presently, I have a single application which is for all regions and I am imposing multiple conditions to distinguish or change the items according to the regions.
For example:
(In many Java files, I used)
if(rule.contains("USA"))
{
//Show splash screen of USA
}
(Similarly, In many Java files, I used)
if(rule.contains("Australia"))
{
//Show splash screen of Australia
}
This is just a one item out of many repeated throughout code. Considering all, it will be lot more.
There should be a better way to create multiple applications in android with different names and settings.
I know, iOS allows me to easily change the application name and profile to allow multiple apps to be created. But I don't know or this is not easy to do on the Android code.
My question:
Is it possible to create different applications with the same source code in android with different settings of items and publish them to Google Play Store ? If YES, How to set such configuration ?
UPDATE:
Read this Post - multiple-android-application-package-apk-files-from-single-source-code
Then I came up with the same idea -
1) Taking some string variable that holds values about which application type you want to create.
public static final String app_Name = "testApp_CANADA" ;
2) Have multiple AndroidManifest.xml files for multiple apps you need to create .apk for.
3) Create corresponding launcher activities for each manifest.
But then how to have multiple AndroidManifest.xml files in a single app ?
UPDATE:
My first AndroidManifest.xml is in main project folder (application root folder) as usual that we have. Consider this for testApp_USA.
My second AndroidManifest.xml is in separate package under main project. Consider this for testApp_CANADA.
Both AndroidManifest.xml have different launcher activities with corresponding splash screens, icons defined. The package names are given different in both so that they will create different .apk files as per requirement.
Now, how to switch code between testApp_USA/testApp_CANADA provided my main app has setting:
public static final String app_Name = "testApp_CANADA" ;
OR
More clearly,
How to call a particular AndroidManifest.xml according to the value of app_Name ?
With the current setup that I have, only first AndroidManifest.xml is called always.
I had similar problem with putting project to different markets - Google Play, Samsung, Amazon. All code base is the same, difference only in billing code.
The best solution I found is creating separate project for each market and pushing common code into library project.
In more detail, you need to leave common code in main project, make it library project and enable manifest merger for library and child projects.
Add following lines to project.properties of main project:
android.library=true
manifestmerger.enabled=true
and this to project.properties of every child project:
android.library.reference.1=../testApp //absolute or relative path to your main project
manifestmerger.enabled=true
Also you need to attach main project as library in ADT plugin (in Eclipse - project properties -> Android) to all child projects.
Main project manifest should not contain any launcher activity, it will be ignored, same thing with appWidget xml's and config activities, if you have some.
In child projects you can configure whatever you want and use main code by extending or just using needed classes as normal Java library. Also, you can use main project activities, services, broadcast receivers, etc just as they are in your child project without any duplication of manifest of child projects.
After all configured, you can just build needed project for needed country as usual single project and you would have different apk's for different countries, as you want.
Here is more detail description of manifest merging http://www.platoevolved.com/blog/programming/android/merging-android-manifest-files/
Note, this feature was added in ADT version 20 preview 3.
Hope this helps.
I had this same question. Maybe you have found the answer at this point, but some searching finally led me to this website, which explains Gradle.
It seems to explain all the basics really well. For the answer to your specific question, look for the section Product Flavors under Build Variants.
As the website explains, part of the purpose behind this design was to make it more dynamic and more easily allow multiple APKs to be created with essentially the same code, which sounds exactly like what you're doing.
I probably didn't explain it the best, but that website does a pretty good job.
The way to have multiple apps from a common code base is to have the common code as a library project, and have each app use the library project (see http://developer.android.com/tools/projects/index.html).
Each project can override strings.xml, and the common come can check the package id.
In your case it seems that this is against the Google Play policy (cookie cutter apps), so it may be better to create one app and let the user choose a country.
For this you have to use App Localization concept. For this you have to create different resources, durables. Let say You want to run your application in japan, you have to create drawable folder like "res/drawable-ja". This is same as you create different layouts to support tablet and small devices.
here is reference link:
http://developer.android.com/guide/topics/resources/localization.html
http://developer.android.com/distribute/googleplay/publish/localizing.html
I am not sure what you want exactly. But at my point of level, you can able to get the geo location, there you can find-out where you app currently running out, or in more easier get the location from locale, once you find the locale or geo-location, you can navigate the source according to that.

android app adding content during runtime

Hello I am trying to build an app which will hold "other app's"
For example MY app will hold different apps of different ClIENTS.
Now i want to make it so that 1 client has the option to only download his part, BUT he still has to use MY main app. (in other words i don't want to reference to another APK, cause then he can start his app without using mine(i think))
And the download option should be at runtime, cause else he has to download everything in one go.
I have thought about using jar files as library files, but what i found so far is that you have to add them in Eclipse (else they are not found)
I also thought about building the app with the jar files in it, and then leave them out when i compile the app. Then my client can download those files afterwards. But i am guessing that will cause reference errors?
So the questions are;
Is it possible?
How to go about?
The main idea is that i don't want to make one HUGE app where as my client will only use his part of it.
Thanks in advance
It can be achieved in android, and some big platform apps could let the 3rd party developers to develop plugins for them. The main idea is try to create your own DexClassLoader to replace the default one, the custom DexClassLoader could load classes from apkfile.
Try to look through this article for details.
Same with this question.
It seems this is a difficult topic. I can only give you some point.
Since you don't want to make a huge app, then you have to build CLIENTs as separate APKs. But if you don't define CLIENT's activity as MAIN and DEFAULT in manifest, after install CLIENT app, user could not find CLIENT app from system menu (launcher). You can define a private intent name for CLIENT app's activity, this way, only your main app could start CLIENT app's activity.

How to determine if Android app version is pro or lite from an Activity in a Library Project?

I'm currently changing my free version to a lite+pro combo by using a library to hold all of the important code, including my activities. Essentially what I plan to do is have a one-line in the code check if the app running is the pro or lite version, and modify the app's appearance and functionality accordingly. I'm just not sure what that line should be.
So say my activity being launched from the manifest is com.example.myapp.lib.MainActivity, and my two packages are com.example.myapp and com.example.myapp.pro. What is a function I can call to check what the currently running package is?
It occurs to me I could possibly do this through a preference.xml file in each app. Would that be better?
You just need to call Activity.getPackageName from your activity

Associating 2 Apps together

I have a project “Abc12” which contains App “TypeYourName”.
Also I have another project “Xyz12” which contains a Service like “MySoftKeyboard”, which is NOT a library type project.
I’d like to associate project “Xyz12” to project “Abc12”, so when user downloads App “TypeYourName”, App “MySoftKeyboard” is also downloaded with it.
Any idea how can be done, if possible ?
I don't think you can do this as separate .apk files. (At least I'm pretty sure you can't do this either in the Android Market or the Amazon Appstore. I also don't know how you could side-load two apk files from the same link.) Create a single project that has your app and also has the service.
It might make sense to put all the code for the service into a library project. Then you could have the service available as a stand-alone project and also bundled with other applications.
You can't. The best you can do is within Abc12, query the package manager for Xyz12, and if it is not present, prompt the user to download it. Make Xyz12 a service or define the proper intent so that ABC12 can access it.

Categories

Resources