Restrict android tablets?

How can I restrict my app so that it cannot be used on android tablets?

Can I just edit the android manifest directly?

This will possibly be overwritten with future Builds of your app or if you remove and re-add the Android platform. You should probably try to find a better solution that doesnā€™t break when the platform folder is recreated.

If you are on the newest Cordova CLI then this will probably help:

(See here for a bit of background: [CB-10894] Add supports-screens support from the config.xml file - ASF JIRA and CB-10894 Add supports-screens config from the config.xml file by akofman Ā· Pull Request #280 Ā· apache/cordova-android Ā· GitHub)

If not, this plugin will probably help:
cordova-custom-config - npm
Or as a hook:
android - Can I control the <supports-screen> setting of an AndroidManifest.xml file from my Cordova config.xml? - Stack Overflow

If you make it work, please post the solution here in full for others to find.

1 Like

@Sujan12 Thanks for the reply, I actually tried that method by adding the edit-config tag and options to my config.xml, but it wouldnā€™t work. I could not build my app and it was giving a very nondescript error. I am on the latest cordova version.

Okay, then letā€™s see that error message and what you actually put in that file. Seems to be the right routeā€¦

Placed this in config.xml - tried inside and outside of the android platform tag.

Error: /Users/xxx/xxx/xxx/xxx/platforms/android/gradlew: Command failed with exit code 1 Error output:
/Users/xxx/xxx/xxx/xxx/platforms/android/res/xml/config.xml:68: AAPT: Error parsing XML: unbound prefix

/Users/xxx/xxx/xxx/xxx/platforms/android/build/intermediates/res/merged/debug/xml/config.xml:68: error: Error parsing XML: unbound prefix

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ā€˜:processDebugResourcesā€™.
    com.android.ide.common.process.ProcessException: Failed to execute aapt

the supports-screens is wrapped in edit config, but it wonā€™t show that in the post for some reason.

Iā€™ve actually noticed that it does build the manifest to the settings iā€™ve set, but the build crashes.

SOLVED: Needed to add xmlns:android=ā€œhttp://schemas.android.com/apk/res/androidā€ to the widget tag in config.xml.

This allows the use of android:xxx properties.

3 Likes

Namespacesā€¦ always a pain :stuck_out_tongue:

Itā€™s all a pain when itā€™s your first time doing things. Such a simple fix, but only found a solution by chance.

Thanks for taking the time to help.

Googling for this error message turned up a few pointers that it is about namespaces, so we would have figured it out by time.

Could you post the complete config.xml (or unrelevant parts edited out) for someone to find later on?

The solution was to update my config.xml to include the following:

Add this line inside the widget tag:

xmlns:android=ā€œhttp://schemas.android.com/apk/res/androidā€

Then add this inside the android platform tag:

<edit-config file="AndroidManifest.xml" target="/manifest" mode="merge">
  <supports-screens android:resizeable="true" android:smallScreens="false" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="false"/>
</edit-config>
2 Likes

Correction in stevenhastieā€™s post, just for the reference.

Since the <supports-screens... element is inside the <manifest... element, the target for the support screens should be target="/manifest/supports-screens"

so the whole snippet:

<edit-config file="AndroidManifest.xml" target="/manifest/supports-screens" mode="merge">
  <supports-screens android:resizeable="true" android:smallScreens="false" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="false"/>
</edit-config>
1 Like

Interesting. I didnā€™t need to do that for it to work on mine.

Well I use the latest ionic available. With your configuration it was
inserting the screen configs in manifest as properties of the manifest
itself.

Hey mate, I tried your way and it returned exactly the same results.
The supports-screen tag is just below the manifest tag in the manifest file.

Can you explain what difference you were seeing between my method and yours?

hello Stevenhastie

When I tried the target="/manifest then the support screens option would go as properties of the manifest tag.

<manifest android:resizeable="true" android:smallScreens="false" ...>

If target="/manifest/support-screens" then the support-screens element goes as child element of the manifext element, as explained above.

At least this is what I rememberā€¦ itā€™s been some days since my try :slight_smile: