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:
https://cordova.apache.org/docs/en/latest/plugin_ref/spec.html#edit-config
(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:
http://stackoverflow.com/a/30217054/252627

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: