Is it possible to add provider in AndroidManifest dynamically? - android

Wondering if its possible to add <provider> element in AndroidManifest from code rather having it specified in static AndroidManifest?
I see that such thing is possible for <receiver>, but couldn't find anyway to achieve run-time addition for <provider>.

Wondering if its possible to add element in AndroidManifest from code rather having it specified in static AndroidManifest?
No, sorry. The closest things are:
Enabling and disabling components (e.g., activities) via PackageManager and setComponentEnabledSetting()
Registering a BroadcastReceiver via registerReceiver(), as opposed to it having a manifest entry
Is it possible to add provider in AndroidManifest dynamically?
No, sorry.

Related

Is it possible to set android permission level for a broadcast receiver at runtime?

Is it possible to programatically set the protection level of an IntentFilter/Intent in java similar to how we can define it in the AndroidManifest.xml:
<receiver
android:name="my.test.receiver"
android:protectionLevel="signature" />
We have a core library for our apps which facilitates dynamic broadcasts and receivers at runtime and we would like to make them secure here.
I have found no information on this method online and not sure if it is possible. if we could set an intentFilters permission level = PermissionInfo.PROTECTION_SIGNATURE it would work but going by the docs it seems PermissionInfo is only used for reading. The only alternative method I can find is declaring a special permission, sending it with our broadcasts and adding it to all our manifests: https://stackoverflow.com/a/15316487/1810256
We may fall back on this approach but we would prefer the first method as the signature approach seems more secure.
Any help/suggestions appreciated!
Quoting one of the users(Naveed Ahmad):
"Guys now from Android 6.0 Marshmellow onward, you can ask users at runtime to allow permissions dynamically, I found of it, have a look at this link. I hope it will help you getting idea."
https://inthecheesefactory.com/blog/things-you-need-to-know-about-android-m-permission-developer-edition/en
I found it in here:
get Android permission dynamiclly

android: is it possible to read what activity aliases are set in the manifest?

I know that a bunch of data that is set in the manifest can be read via the Package Manager. Is there a convenient way to do something similar for activity-alias data? If there is no convenient way, is it even possible?

Do I HAVE to declare every activity in a manifest file?

I want to create an Activity but not have to declare it in the manifest file. Is this possible? Everywhere I've seen it seems that every activity must be declared in the manifest, yet I notice that some activities, such as the built-in ChooserActivity, is not declared in my manifest file.
Short answer: yes, every Activity in your application must be declared in the manifest. As described in the Android docs, the purpose of the manifest (among other things) is:
It describes the components of the application — the activities, services, broadcast receivers, and content providers that the
application is composed of. It names the classes that implement each
of the components and publishes their capabilities (for example, which
Intent messages they can handle). These declarations let the Android
system know what the components are and under what conditions they can
be launched.)
http://developer.android.com/guide/topics/manifest/manifest-intro.html#ifs
Therefore any Activity class in your application must be defined in your Manifest. The same goes with Intents, Services etc. even if those components aren't accessible from outside of your application.
As for ChooserActivity and any other Activity which you didn't define in code, they will have their own definitions in another Manifest. If for whatever reason you decide to subclass an existing Activity outside of your application, then you will have to define it in your Manifest too.
I want to create an Activity but not have to declare it in the manifest file. Is this possible?
No, sorry.
I notice that some activities, such as the built-in ChooserActivity, is not declared in my manifest file
That activity is not part of your application. It is part of the core operating system.

Register Android service in source code instead in Android Manifest

Does anyone know that is it possible to register (add) declaration of service in source code instead in AndroidManifest.xml if yes... how?
Thanks for any suggestions or help.
It's not possible. You have to have your Service registered in AndroidManifest.xml.
As stated here:
Like activities (and other components), you must declare all services in your application's manifest file.
So you will allways have to list your Service in the manifest file.
AndroidManifest.xml is part of your source code. This is the place where Android expects to find your services and activities declared, and there's no way around it.
The manifest presents essential information about the application to the Android system, information the system must have before it can run any of the application's code.
So it is mandatory to declare all your components (with their intent filters i.e Category , Action , Data) in your manifest file.

Dynamic AndroidManifest.xml

Is it possible to dynamically define aspects of the AndroidManifest.xml? For example, is it possible to register or edit the definition of activities, services and receivers on the fly, using Java code?
If so, are there any limitations on where this code should be placed? What else can be dynamically defined?
I believe most of the available operations are described by the PackageManager documentation
You can add and remove permissions (addPermission()) and you can enable or disable components (services, receivers etc.) with setComponentEnabledSetting().

Categories

Resources