How do I disable an android service for certain architectures?

681 Views Asked by At

Currently I'm using twilio to make calls in android in my application but they don't support arm64 phones yet, my application keeps crashing as it doesn't find the appropriate libtwilio-native.so file.

Is there a way to disable this service only for an architecture? Is there a way to disable the service by default and enable it in runtime?

Additional info:

My manifest.xml file has this:

        <service
        android:name="com.twilio.client.TwilioClientService"
        android:exported="false" />

The bools.xml trick doesn't work for me as arm64 phones and others phones can have the same android version.

1

There are 1 best solutions below

0
On

Is there a way to disable the service by default and enable it in runtime?

Add android:enabled="false" to the <service> in the manifest. Then, at runtime, you can use PackageManager and the awkwardly-named setComponentEnabledSetting() method to enable it, if desired.

The bools.xml trick doesn't work for me as arm64 phones and others phones can have the same android version.

True, though if you are using product flavors in Android Studio for handling your CPU architecture splits, you should be able to use resConfig in the product flavor definitions in Gradle in lieu of the actual bools.xml files to define the boolean resource, and use that in android:enabled. Note that I have not tried this, YMMV, do not taunt Happy Fun Ball, etc.