Software Archive
Read-only legacy content
17061 Discussions

where can I declare supports-screens or target-device attribute in xdk?

Bigfanx__
Beginner
635 Views

Hi, I want to limit my app only to mobile phones . I don't want tablet users to download it due to the screen size issue, but I don't know where I can put the attribute <supports-screens android:requiresSmallestWidthDp="320" /> or <preference name="target-device" value="handset">  in xdk. Is it in intelxdk.config.android.xml file or intelxdk.config.additions.xml file or somewhere else? Thanks a lot in advance.

0 Kudos
8 Replies
PaulF_IntelCorp
Employee
635 Views

I don't have a specific answer for your question, but there are two possible solutions:

  1. an existing Cordova config.xml entry that does this for your
  2. creating a "dummy" plugin that does this for your

The XDK created standard Cordova apps. You can add, via the intelxdk.config.additions.xml file, standard Cordova config.xml directives. If you can identify a Cordova-specific config.xml directive that does what you want, that is the simplest solution. You can try the "target-device" preference you mention, but I believe that only works with PhoneGap, not with Cordova.

Otherwise, you can use the plugin.xml file that is part of every Cordova plugin to add these items. Several customers have done similar work, I don't have one to point to, but that is the second approach.

I would search Stack Overflow for such solutions, something like "stack overflow cordova config.xml target handset" or something similar.

0 Kudos
Bigfanx__
Beginner
635 Views

Hi Paul, thanks a lot for the reply. Should I create a dummy plugin.xml to add the directive or just modify an existing plugin.xml to add the directive in my plugins folder? If it is the latter approach, which one should I modify? I have cordova.device, cordova.dialogs, and cordova.splashscreen plugins in my plugin folder. I reckon it is the cordova.device plugin.xml. The android part of the cordova.device plugin.xml is shown below:

<!-- android -->
    <platform name="android">
        <config-file target="res/xml/config.xml" parent="/*">
            <feature name="Device" >
                <param name="android-package" value="org.apache.cordova.device.Device"/>
            </feature>
        </config-file>
        <source-file src="src/android/Device.java" target-dir="src/org/apache/cordova/device" /> 
   </platform>

If it is the cordova.device plugin.xml, should I put the directive <preference name="target-device" value="handset"> inside the <feature></feature> tag? I searched the stack overflow site but couldn't find an example. Thanks a lot again for your help.

0 Kudos
PaulF_IntelCorp
Employee
635 Views

You should create a new dummy plugin, modifying an existing plugin could get overwritten by updates to that plugin.

That <preference name="target-device" value="handset"> option is specific to building iOS apps on PhoneGap Build, it is not a standard Cordova build option and does not apply to Android devices. Instead you're going to need to create a dummy plugin that has an Android "config-file" piece to it that adds the <supports-screens android:requiresSmallestWidthDp="320" /> preference to the AndroidManifest.xml file.

See this doc page, especially the "config-file Element" section: https://cordova.apache.org/docs/en/4.0.0/plugin_ref_spec.md.html#Plugin%20Specification

You should be able to use this plugin.xml as a starting point:

<?xml version="1.0" encoding="UTF-8"?>

<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" 
  xmlns:android="http://schemas.android.com/apk/res/android"
  id="cordova-plugin-android-supports-only-handsets"
  version="0.0.1">

    <name>Android Supports Only Handsets</name>
    <description>Dummy plugin to configure Android supports-screens directive.</description>
    <license>BSD-3 license, http://www.tldrlegal.com/l/bsd3</license>;

    <!-- android -->
    <platform name="android">
        <config-file target="AndroidManifest.xml" parent="/*">
            <supports-screens android:requiresSmallestWidthDp="320" />
        </config-file>
    </platform>
</plugin>

I have not tested this, essentially, your plugin consists of this one file. I'm not sure that attribute is going to do what you want, see this page for the complete set: http://developer.android.com/guide/topics/manifest/supports-screens-element.html -- you might need to use the android:largestWidthLimitDp option, instead.

0 Kudos
Bigfanx__
Beginner
635 Views

Hi Paul, I think I might be better off if I use media queries to manually adjust my app layout to fit different tablets resolution. However, it is still worth a try of the dummy plugin.xml file you suggested for the future use. Thanks a lot for your great help.

0 Kudos
PaulF_IntelCorp
Employee
635 Views

Good idea, especially since it is hard to equate resolution and density to physical size, on Android.

0 Kudos
Paul_R_
Beginner
635 Views

Is there still no proper way to define Android <supports-screens>?  I'm not seeing anywhere to set this in the build options, and no explicit instructions or direction for adding this to the intelxdk.config.additions.xml file.

0 Kudos
PaulF_IntelCorp
Employee
635 Views

Paul R. wrote:

Is there still no proper way to define Android <supports-screens>?  I'm not seeing anywhere to set this in the build options, and no explicit instructions or direction for adding this to the intelxdk.config.additions.xml file.

Beyond a few special add/remove line operations, the additions.xml file only understands standard Cordova CLI directives. If Cordova does not provide such an option then the additions.xml file is of no value. Note that Cordova directives that will work in the additions.xml file are specific to the version of CLI that you build to (most do not change). For example, if a Cordova config.xml directive was added for CLI 6.2, and you add it to the additions.xml file, it will only work with the 6.2 build system (it will be ignored by the other build systems).

You need to use a simple plugin, like those presented in the previous posts, to do what you want with our build system.

0 Kudos
Paul_R_
Beginner
635 Views

That makes sense; thank you for the plugin.xml information. 

0 Kudos
Reply