10 Replies Latest reply on May 18, 2017 1:19 AM by Yehuda Katz

    none of orientation lock methods work with phonegap build

    Yehuda Katz

      Hi,

       

      PhoneGap Build was advertised as service which should save developer's time and simplifies the compilation process. So far I spent more time trying all possible ways to lock orientation for android app using PhoneGap build service than I spent on prepare environment for compilation and running the same app using Cordova in xCode. BTW in custom build, orientation was locked in iOS emulator. Here are what I tried (testing on Galaxy Tab A, Android 5.1.1):

       

      1) traditional way

       

      <preference name="orientation" value="landscape" />

       

      2) overwriting android config

       

      <gap:config-file platform="android" parent="/manifest" >

        <application>

          <activity android:screenOrientation="portrait" android:configChanges="orientation"/>

        </application>

      </gap:config-file>

       

      3) using plugin

       

      config.xml

      <plugin name="orientationLock" spec="https://github.com/cogitor/PhoneGap-OrientationLock.git" />

       

      index.html

      <script type="text/javascript" src="orientationLock.js"></script>

       

      app.js

      document.addEventListener('deviceready', function() {

        window.plugins.orientationLock.lock('landscape');

        alert(JSON.stringify(window.plugins.orientationLock));

      });

       

      the alert was giving 'undefined' error message

       

      I will prepare environment to compile app for android manually using Cordova and could say for sure, is that PhoneGap Build bug or not. This issue is over 3 years old, I have no clue why it was not resolved and native <preference name="orientation" value="landscape" /> is still not working. I am very very very frustrated and start thinking to do whole hybrid app by myself, since calling JavaScript from Java is very simple and the only possible difficulty could be calling Java from JavaScript.

        • 1. Re: none of orientation lock methods work with phonegap build
          Chris W. Griffith Adobe Community Professional

          I just tested a new app with this config.xml. The app launched in landscape on my Nexus 6.

           

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

           


          <!-- config.xml reference: https://build.phonegap.com/docs/config-xml -->

          <widget xmlns = "http://www.w3.org/ns/widgets"

            xmlns:gap = "http://phonegap.com/ns/1.0"

            id = "com.phonegap.helloworld"

            version = "1.0.0">


             <name>Hello World</name>


             <description>

            Hello World sample application that responds to the deviceready event.

             </description>


             <author href="http://phonegap.com" email="support@phonegap.com">

            PhoneGap Team

             </author>


             <!--

            If you do not want any permissions to be added to your app, add the

            following tag to your config.xml; you will still have the INTERNET

            permission on your app, which PhoneGap requires.

            -->

             <preference name="permissions"   value="none"/>


             <!-- Customize your app and platform with the preference element. -->

             <preference name="orientation"   value="landscape" />   <!-- all: default means both landscape and portrait are enabled -->

             <preference name="target-device"   value="universal" />   <!-- all: possible values handset, tablet, or universal -->

             <preference name="fullscreen"   value="true" />   <!-- all: hides the status bar at the top of the screen -->

             <preference name="webviewbounce"   value="true" />   <!-- ios: control whether the screen 'bounces' when scrolled beyond the top -->

             <preference name="prerendered-icon"   value="true" />   <!-- ios: if icon is prerendered, iOS will not apply it's gloss to the app's icon on the user's home screen -->

             <preference name="stay-in-webview"   value="false" />   <!-- ios: external links should open in the default browser, 'true' would use the webview the app lives in -->

             <preference name="ios-statusbarstyle"   value="black-opaque" />   <!-- ios: black-translucent will appear black because the PhoneGap webview doesn't go beneath the status bar -->

             <preference name="detect-data-types"   value="true" />   <!-- ios: controls whether data types (such as phone no. and dates) are automatically turned into links by the system -->

             <preference name="exit-on-suspend"   value="false" />   <!-- ios: if set to true, app will terminate when home button is pressed -->

             <preference name="show-splash-screen-spinner" value="true" />   <!-- ios: if set to false, the spinner won't appear on the splash screen during app loading -->

             <preference name="auto-hide-splash-screen"   value="true" />   <!-- ios: if set to false, the splash screen must be hidden using a JavaScript API -->

             <preference name="disable-cursor"   value="false" />   <!-- blackberry: prevents a mouse-icon/cursor from being displayed on the app -->

             <preference name="android-installLocation"   value="auto" />   <!-- android: app install location. 'auto' will choose. 'internalOnly' is device memory. 'preferExternal' is SDCard. -->

             <!--

            Define a specific version of PhoneGap to build into your app.

            <preference name="phonegap-version" value="3.5.0" />

            -->


             <icon src="res/icon/android/drawable-ldpi-icon.png"   gap:platform="android"   gap:qualifier="ldpi" />

             <icon src="res/icon/android/icon-48-mdpi.png"   gap:platform="android"   gap:qualifier="mdpi" />

             <icon src="res/icon/android/drawable-hdpi-icon"   gap:platform="android"   gap:qualifier="hdpi" />

             <icon src="res/icon/android/drawable-xhdpi.png"  gap:platform="android"   gap:qualifier="xhdpi" />

             <icon src="res/icon/android/drawable-xxhdpi.png"  gap:platform="android"   gap:qualifier="xxhdpi" />

             <icon src="res/icon/android/drawable-xxxhdpi.png"  gap:platform="android"   gap:qualifier="xxxhdpi" />

            

             <!-- Third party plugins -->

             <!-- A list of available plugins are available at https://build.phonegap.com/plugins -->

             <!--

            <plugin name="com.phonegap.plugins.barcodescanner" />

            -->


             <!-- Define app icon for each platform. -->

             <icon src="icon.png" />

            


             <access origin="*"/>

             <!-- Added the following intents to support the removal of whitelist code from base cordova to a plugin -->

             <!-- Whitelist configuration. Refer to https://cordova.apache.org/docs/en/edge/guide_appdev_whitelist_index.md.html -->

             <plugin name="cordova-plugin-whitelist" version="1" />

             <allow-intent href="http://*/*" />

             <allow-intent href="https://*/*" />

             <allow-intent href="tel:*" />

             <allow-intent href="sms:*" />

             <allow-intent href="mailto:*" />

             <allow-intent href="geo:*" />

             <platform name="android">

             <allow-intent href="market:*" />

             </platform>


          </widget>```

          • 2. Re: none of orientation lock methods work with phonegap build
            Yehuda Katz Level 1

            I tried 'hello world' app without any changes, just added:

             

            <preference name="orientation" value="landscape" />

             

            at the end and the same issue, now I am preparing environment for custom compilation in Android Studio.

            • 3. Re: none of orientation lock methods work with phonegap build
              Chris W. Griffith Adobe Community Professional

              What device are you testing on?

               

              Chris

              • 4. Re: none of orientation lock methods work with phonegap build
                Yehuda Katz Level 1

                Testing on Galaxy Tab A with Android 5.1.1. I have installed Cordova and created project with it but when I uploaded it to PhoneGap Build, I got the same result. App keeps rotating... I have feeling that I am missing something or this Samsung is buggy. I will add platform and try to compile app in Android Studio (which I already have, I hope I will not need to update JDK or do too much tuning to be able to compile app)

                 

                <?xml version='1.0' encoding='utf-8'?>

                <widget id="com.example.app" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">

                    <name>App Name</name>

                    <description>

                        A sample Apache Cordova application that responds to the deviceready event.

                    </description>

                    <author email="dev@cordova.apache.org" href="http://cordova.io">

                        Apache Cordova Team

                    </author>

                    <content src="index.html" />

                    <plugin name="cordova-plugin-whitelist" spec="1" />

                    <access origin="*" />

                    <allow-intent href="http://*/*" />

                    <allow-intent href="https://*/*" />

                    <allow-intent href="tel:*" />

                    <allow-intent href="sms:*" />

                    <allow-intent href="mailto:*" />

                    <allow-intent href="geo:*" />

                    <platform name="android">

                        <allow-intent href="market:*" />

                    </platform>

                    <platform name="ios">

                        <allow-intent href="itms:*" />

                        <allow-intent href="itms-apps:*" />

                    </platform>

                  <preference name="orientation" value="landscape" />

                </widget>

                • 5. Re: none of orientation lock methods work with phonegap build
                  Chris W. Griffith Adobe Community Professional

                  Nothing appears to be off.

                  Here is the sample app I built. Hopefully, you can download it and install it and test it.

                  https://build.phonegap.com/apps/2622390/download/android/?qr_key=ma2_9dj8yEABXUV8qvgw

                  1 person found this helpful
                  • 6. Re: none of orientation lock methods work with phonegap build
                    Yehuda Katz Level 1

                    I will try your app Chris and update you shortly.

                     

                    I complied the same project with android studio and deployed it on the device - orientation lock works just fine. So seems like it's PhoneGap Build service's bug. Is that possible to report and fix that...

                     

                    I still prefer to use PhoneGap Build because of compilation simplicity and hydration feature.

                    • 7. Re: none of orientation lock methods work with phonegap build
                      Yehuda Katz Level 1

                      Chris, your app also works fine. Did you compile it with PhoneGap Build? Can you send me source so I will upload it from my end and try again. The only guess which I have right now is that hydration causes the problem. As hydration is wrapper for my app and it may override settings set by app itself. Let me compile app with hydration disabled.

                      • 8. Re: none of orientation lock methods work with phonegap build
                        Yehuda Katz Level 1

                        So Chris, the problem was in hydration. It was causing the problem... I build app without this feature, reinstalled app and everything works fine now. This case could be marked as resolved.

                        • 9. Re: none of orientation lock methods work with phonegap build
                          Chris W. Griffith Adobe Community Professional

                          Yup. Your config.xml file is ignored if hydration is used, as would the custom plugin that you referenced as well.

                          1 person found this helpful
                          • 10. Re: none of orientation lock methods work with phonegap build
                            Yehuda Katz Level 1

                            Thanks a lot Chris, now everything is clear. Developer should use hydration only after default compilation showed no error with config.xml file. Also I will keep in mind that projects with custom plugins cannot use hydration. I think showing this warning would save other developer's time (or it's there and I missed it).