Not being able to get device info using core plugin

13 posts, 0 answers
  1. Leonardo
    Leonardo avatar
    16 posts
    Member since:
    Feb 2014

    Posted 18 Jun 2014 Link to this post

    Hey,

    I am trying to get the device info using device.platform but it's not getting anything. I mean, I added this line: alert("device.platform"); and the alert isn't popped up. Probably, I am missing something...

    I added the plugin, using this command:   appbuilder fetch-plugin https://github.com/apache/cordova-plugin-device/ --path ./app
    and that was all. The project was created using the cli, so I can see the cordova.js files.

    Do I have to reference them? Which should be the steps to add a plugin and use it inside of a js file?

    Thank you!


  2. Iva Koevska
    Admin
    Iva Koevska avatar
    286 posts

    Posted 20 Jun 2014 Link to this post

    Hello Leonardo,

    Thank you for trying out our command-line interface offering. Unfortunately, the workflow you have picked up might be what is causing the problem. It also appears that you are running an outdated version of the CLI since you have used the fetch-plugin command which is now deprecated and transformed into the plugin fetch command.

    The best course of action would be to first update your installation by running $ npm install -g appbuilder.

    Next, you should consider the following. The Device plugin is considered a core plugin and should be enabled/disabled via the $ appbuilder prop command. When you fetched it from the official repository, you have probably created a conflict between the plugins in your project. On the one hand, you have the Device plugin enabled as a core plugin in your project properties and on the other - you have just added it as a custom plugin.

    What you can do is either disable the core plugin OR remove the "custom" one.
    To disable the device core plugin, run $ appbuilder prop remove CorePlugins org.apache.cordova.device.
    To remove the device custom plugin, just empty the Plugins folder in your project.

    And now to your code - we cannot identify what the problem might be without your complete project or a sample code snippet that shows where and how you're calling the alert. Please, either attach your code or prepare a jsFiddle with your code so that we can examine it and check how it works.

    Regarding your last question about adding a plugin - it depends almost entirely on the type of plugin.
    For the core/integrated plugins (that is all core Apache Cordova APIs, the BarcodeScanner, the SQLite, the PushPlugin, the Telerik Mobile Testing, the Telerik Analytics, and the Telerik AppFeedback plugins, run $ appbuilder prop add|remove CorePlugins <plugin ID>. To get the available plugin IDs, run $ appbuilder prop add --help and examine the CorePlugins section. You do not need to reference these in your index.html.

    For custom plugins, you need to run $ appbuilder plugin fetch. After the CLI fetches the plugin, it places it in the Plugins folder in your project. You would need to examine your plugin.xml to find out if you need to reference the plugin in your project. For more information, see this article.

    Let us know if you need further assistance.

    Regards,
    Iva Koevska
    Telerik
     

    Share what you think about AppBuilder and Telerik Platform with us in our feedback portal, so we can become even better!

     
  3. Leonardo
    Leonardo avatar
    16 posts
    Member since:
    Feb 2014

    Posted 20 Jun 2014 in reply to Iva Koevska Link to this post

    Awesome reply! I added that plugin for testing purposes only. What I am into is trying to add a custom cordova plugin that I have developed to the appbuilder project. This plugin can be added to a cordova project using the cli (cordova plugin add ... ) and it is in the plugman compatible way (the xml file and the folder structure meet that standard). So, this could be added to the appbuilder project but there is something that it's not fine yet. These are the steps I followed in the project: 

    1- Added the plugin using appbuilder plugin fetch ./Custom_Plugins/VolumeControl --path ./app
    And I get:
    The plugin has been successfully fetched to /Users/leonardomartinez/Desktop/Otoharmonics_Corp/BlackBird_Repository/bb_patient/app/plugins/com.cordova.plugins.volumecontrol

    2- Added the reference into the index.html file as:

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

    This was located after the spot that was placed the reference for cordova.js and before the JS file that uses the customs functions.

    Do I need to do something else? Is there a difference between working custom plugins for Cordova projects and appbuilder projects? 

    Thank you!

    PS: Cordova is working because I could attach the device ready event and it is triggered.


  4. Iva Koevska
    Admin
    Iva Koevska avatar
    286 posts

    Posted 24 Jun 2014 Link to this post

    Hello Leonardo,

    Working with custom plugins in AppBuilder is not that different from working with them in Cordova projects.

    The steps to work with a plugin in an AppBuilder project break down to the following:
    1. Add a Plugman-compatible plugin to the Plugins folder in the project.
    Note that the structure should look something like this. You cannot have a folder that does not contain a plugin.xml under Plugins and you cannot have src, www, and plugin.xml nested right under Plugins.
    Plugins
    plugin-folder-1
    src
    www
    plugin.xml
    plugin-folder-2
    src
    www
    plugin.xml
    2. Reference the plugin if needed.
    You need to reference it in index.html if the plugin is declared as an asset in plugin.xml. If it's declared as a js-module, do not reference it in your index.html.
    3. Call the plugin in your JavaScript code.
    4. Test the app as a deployed application package on the device.
    Note that you cannot test custom plugins in the device simulator or the companion app. Custom plugins work only if you deploy your app as an APK/IPA/XAP.

    Hope this helps.

    Regards,
    Iva Koevska
    Telerik
     

    Share what you think about AppBuilder and Telerik Platform with us in our feedback portal, so we can become even better!

     
  5. Leonardo
    Leonardo avatar
    16 posts
    Member since:
    Feb 2014

    Posted 24 Jun 2014 in reply to Iva Koevska Link to this post

    Thanks!
    I also needed to make another step which was to add this line into the android config file: <plugin name="VolumeControl" value="com.cordova.plugins.volumecontrol"/>

    I thought that this was done automatically. Now, this working if I use a device which runs the latest android version.

    I added this to the manifest which helped me to deploy the app on a 4.1.2 OS device on the web client but it's not working now:
    <uses-sdk
    android:minSdkVersion="16"
    android:targetSdkVersion="16" />

    Is that ok? Am I missing something else to get that to work on an older device?

    I added this to the iOS config file: <plugin name="VolumeControl" value="com.cordova.plugins.volumecontrol"/>

    But my app isn't working on an iOS device yet...

    What do you think about this?
  6. Leonardo
    Leonardo avatar
    16 posts
    Member since:
    Feb 2014

    Posted 24 Jun 2014 in reply to Leonardo Link to this post

    Now, the android version is working on both sides: the emulator and my phone (4.1.2 Android version). I had to put that uses-sdk declaration in another place within the Android Manifest.

    Nevertheless, it doesn't work on an iOS device yet... 
  7. Iva Koevska
    Admin
    Iva Koevska avatar
    286 posts

    Posted 25 Jun 2014 Link to this post

    Hello Leonardo,

    As much we would love to assist you, we can't identify the possible issues with your custom plugin without the actual code. If your plugin.xml file was written correctly, you should not need to manually fix your AndroidManifest.xml, Info.plist, and config.xml files. All transformations that should be applied during the build process, should be declared in the plugin.xml.

    Since it seems you are developing the custom plugin yourself, you might find the following resources handy:
    To be able to assist you, we will need to take a look at the custom plugin. If you are reluctant to share it in public, you can open a support request or send a general feedback item and attach the code there.

    Thank you!

    Regards,
    Iva Koevska
    Telerik
     

    Share what you think about AppBuilder and Telerik Platform with us in our feedback portal, so we can become even better!

     
  8. Leonardo
    Leonardo avatar
    16 posts
    Member since:
    Feb 2014

    Posted 25 Jun 2014 in reply to Leonardo Link to this post

    Hello Iva,

    Finally, it's also working on iOS now. I guess I found the error but I need you to confirm. This situation is happening on both platforms: iOS and Android.

    After adding any plugin, modifying the Manifest/config file for Android as I told you before (I don't need to do that for iOS), adding the reference to the JS file and using a method of the plugin, I must build the app using: "appbuilder deploy android" or "appbuilder deploy ios --certificate '...' --provision '...' for each platform.
    If I use the appbuilder build android --companion or appbuilder build ios --companion, I only get the updates of the HTML, JS but not the ones made for the plugins...
    Can that be true? That's what was happening to me.
  9. Leonardo
    Leonardo avatar
    16 posts
    Member since:
    Feb 2014

    Posted 25 Jun 2014 in reply to Leonardo Link to this post

    Thanks for helping me. My first problems are solved now. This is my last version of the plugin.xml file (the part for Android):

    <platform name="android">
            <config-file target="res/xml/config.xml" parent="widget">
                <feature name="VolumeControl" >
                    <param name="android-package" value="com.cordova.plugins.volumecontrol.VolumeControl"/>
                </feature>
            </config-file>
            
            <config-file target="AndroidManifest.xml" parent="/manifest/application">
    <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="16" />
            </config-file>
             
            <source-file src="src/android/com/cordova/plugins/volumecontrol/VolumeControl.java" target-dir="src/com/cordova/plugins/volumecontrol" />
         </platform>

    I had a typo error there. Now, I don't have to touch the Manifest nor the Android config file... That's great.

    Nevertheless, I still have the other problem. It's like I can only add/use custom plugins if I am not using the appbuilder app (I need to deploy my own app using my Apple certificates or deploying using "appbuilder deploy android"... That's weird, I guess.
    I can update the appbuilder using the QR code on iOS but I am having troubles with the QR code provided for Android OS: I am using the reader you suggested here http://www.telerik.com/forums/scanning-qr-code-on-android-companion-app but still with no luck.
  10. Iva Koevska
    Admin
    Iva Koevska avatar
    286 posts

    Posted 26 Jun 2014 Link to this post

    Hello Leonardo,

    You are correct. As I mentioned earlier, you cannot test custom plugins in the companion app and in the device simulator. You need to deploy them as application packages.

    You might want to check the following documentation articles for more information:

    Regards,
    Iva Koevska
    Telerik
     

    Share what you think about AppBuilder and Telerik Platform with us in our feedback portal, so we can become even better!

     
  11. Leonardo
    Leonardo avatar
    16 posts
    Member since:
    Feb 2014

    Posted 26 Jun 2014 in reply to Iva Koevska Link to this post

    Thank you so much!
  12. vignesh
    vignesh avatar
    1 posts
    Member since:
    Mar 2016

    Posted 17 Mar in reply to Iva Koevska Link to this post

    Hi I am new to mobile application. I am just trying to create a sample application to get device information and Geolocation when the application is opened. I am using Apache Cordova CLI and Ionic framework. I have added the following two plugins to get the information. But I am receiving the empty values.

    plugins:1. ionic plugin add org.apache.cordova.device.

                 2.ionic  plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git 

                3.ionic plugin add org.apache.cordova.core.geolocation

    here I have attached the snapshot what I am getting as output in the emulator.

                    

     

  13. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 21 Mar Link to this post

    @ Vignesh

    From the screenshot you have attached it appears that either the UI properties are not correctly bound or they are not receiving the correct values from the code. Please note that this is just an assumption based on the screenshot. I'd suggest that you debug your project and examine if the plugin is returning the correct values, then examine the bindings between the code and the UI.


    Also, I am afraid that it is not clear which product or service in Telerik Platform you are using to develop your application. Based on the tools and frameworks you quoted it may be more beneficial for your development tasks to consult the respective community forums.

    Let me know should you have further questions.

    Regards,
    Anton Dobrev
    Telerik
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
Back to Top