How to get phone number from device

15 posts, 0 answers
  1. Carlos
    Carlos avatar
    69 posts
    Member since:
    Jun 2011

    Posted 12 Jun 2013 Link to this post

    How do you get a phone number from the device using Icenium?  We are going to use this as some authentication for our app.  I know it can be kind of tricky sometimes, but is there a way to do this with Icenium?

    Thanks

    Carlos Mosqueda
  2. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 13 Jun 2013 Link to this post

    Hello Carlos,

    You can use the Cordova Contacts API to get the phone number. You can clone a work in progress solution from here. It should work fine and give you a general idea of how the API is used.

    Don't forget to add the necessary Android permissions mentioned in the Cordova docs.

    Regards,
    Steve
    Telerik

    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Missed our first webinar, watch it here.
    Share feedback and vote for features on our Feedback Portal.
  3. Carlos
    Carlos avatar
    69 posts
    Member since:
    Jun 2011

    Posted 13 Jun 2013 Link to this post

    This will give the application the device's phone number correct?

    Do you have a simple code example of the Contacts API getting the current device's phone number?  

  4. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 14 Jun 2013 Link to this post

    Hi Carlos,

    No, you would get any phone number from the device. Cordova does not expose direct access to the device's own phone number, but you can accomplish this through a custom plug-in. Fortunately such custom plug-in already exists (TelephoneNumberPlugin) and you can find detailed explanation how to use it in this blog post. We would introduce support for custom plug-ins in our upcoming version 1.6 expected at the end of the month.

    Regards,
    Steve
    Telerik

    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Missed our first webinar, watch it here.
    Share feedback and vote for features on our Feedback Portal.
  5. Carlos
    Carlos avatar
    69 posts
    Member since:
    Jun 2011

    Posted 14 Jun 2013 Link to this post

    @Steve, 
    From my understanding, I can not add custom plugins into an Icenium project.
    I saw the plugin, but when I go to my plugins in my Icenium project, there is no way to add a custom plugin. Just the ability to add the 4 supported Cordova ( documented here) plugins that Telerik has added to the Icenium.  
    How would I add this or any other custom Cordova plugin into my Icenium project?

    IF I am I reading the documentation correctly that I can on used the base Cordova and the 4 supported Cordova plugins. If I can add custom Cordova plugins like TelephoneNumberPlugin, do you have documentation or step by step instructions on how to add them to Icenium? Because in the plugins menu, when I go to the Add+ button, I only see the 4 supported plugins and not way to add a new one.  

    Thank you in advance

  6. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 14 Jun 2013 Link to this post

    Hi Carlos,

    Yes, custom plug-ins are not supported in the current version, but would be in the upcoming version expected at the end of the month. I've provided this information in my previous reply in the last sentence.

    Regards,
    Steve
    Telerik

    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Missed our first webinar, watch it here.
    Share feedback and vote for features on our Feedback Portal.
  7. Carlos
    Carlos avatar
    69 posts
    Member since:
    Jun 2011

    Posted 14 Jun 2013 Link to this post

    Thank you for the response.  I will be looking for that.
    This is a great product and very thought out, just the lack of custom Cordova plug-in support was starting to be a concern.

    Thanks again.
  8. Carlos
    Carlos avatar
    69 posts
    Member since:
    Jun 2011

    Posted 01 Jul 2013 Link to this post

    @Steve, (or anyone else from )
    First off. Nice job on getting the Cordova custom plugin support released.  

    Secondly,
    I am trying to get the TelephoneNumberPlugin to work.  I tried setting up the plugin.xml since there was not one in the project.  I an not quite sure I have done it all correctly. I am actually not sure I am setting the whole thing up correctly.  

    I am getting an alert back saying it can not find 'Uncaught module cordova/plugin/telephonenumber no found' from file://storage/sdcard0/Icenium/com.telerik_sample_app/cordova.js:48

    I have attached a .txt file to show what I have going on in my files.
    Any pointers or suggestions would be great.  
  9. Carlos
    Carlos avatar
    69 posts
    Member since:
    Jun 2011

    Posted 01 Jul 2013 Link to this post

    @Steve, (or anyone else from )
    First off. Nice job on getting the Cordova custom plugin support released.  

    Secondly,
    I am trying to get the TelephoneNumberPlugin to work.  I tried setting up the plugin.xml since there was not one in the project.  I an not quite sure I have done it all correctly. I am actually not sure I am setting the whole thing up correctly.  

    I am getting an alert back saying it can not find 
    Uncaught module cordova/plugin/telephonenumber not found
     from


    I have attached a .jpg file to show what I have going on in my files.
    Any pointers or suggestions would be great.  
  10. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 02 Jul 2013 Link to this post

    Hi Carlos,

     Your plugin.xml appears to be incorrect and it seems that plugman has failed to add the plugin to the app. Could you please try with this plugin.xml instead:
    <?xml version="1.0" encoding="UTF-8"?>
            xmlns:android="http://schemas.android.com/apk/res/android"
            id="com.simonmacdonald.cordova.plugins.TelephoneNumber
            version="0.2.0">
     
        <name>Telephone Number</name>
     
        <asset src="www/telephonenumber.js" target="telephonenumber.js" />
     
        <platform name="android">
            <config-file target="res/xml/config.xml" parent="plugins">
                <plugin name="TelephoneNumber" value="com.simonmacdonald.cordova.plugins.TelephoneNumber"/>
            </config-file>
     
            <source-file src="src/com/simonmacdonald/cordova/plugins/TelephoneNumber.java" target-dir="src/com/simonmacdonald/cordova/plugins" />
        </platform>
    </plugin>


    Regards,
    Yavor Georgiev
    Telerik

    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Missed our first webinar, watch it here.
    Share feedback and vote for features on our Feedback Portal.
  11. Carlos
    Carlos avatar
    69 posts
    Member since:
    Jun 2011

    Posted 03 Jul 2013 Link to this post

    @Yavor,

    I am still getting an error saying
    Uncaught module cordova/plugin/telephonenumber not found
     from


    This error looks like it is coming from the index.html page in the .require() tag.  Is there an issue with where it is looking for the plugin?

    Here is what I have in my header of the index.html page.
    <script type="text/javascript" charset="utf-8" src="telephonenumber.js"></script>
           <script>
          //alert("hellow");
                
       // global error handling
       var showAlert = function(message, title, callback) {
           alert(message, callback || function () {
           }, title, 'OK');
       };
       var showError = function(message) {
           showAlert(message, 'Error occured');
       };
       window.addEventListener('error', function (e) {
           e.preventDefault();
           var message = e.message + "' from " + e.filename + ":" + e.lineno;
           showAlert(message, 'Error occured');
           return true;
       });
           var telephoneNumber = cordova.require("cordova/plugins/telephonenumber");
           telephoneNumber.get(function(result) {
           console.log("result = " + result);
       }, function(error) {
           console.log("error = " + error.code);
       });
           </script>

    If you see the telephonenumber.js is pointing to the root, which it is actually not. I was following the project example where the source in the script tag the telephonenumber.js has not parent path but is still in the www folder.
    Is this correct?

    Thanks in advance.
  12. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 04 Jul 2013 Link to this post

    Hi Carlos,

    You've changed this line of code:

    var telephoneNumber = cordova.require("cordova/plugin/telephonenumber");
    to
    var telephoneNumber = cordova.require("cordova/plugins/telephonenumber");

    which is wrong. The cordova.require must match the cordova.define in telephonenumber.js, which in this case is "cordova/plugin/telephonenumber". Once I've changed that, the plug-in is working correctly on my end.

    Regards,
    Steve
    Telerik

    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Missed our first webinar, watch it here.
    Share feedback and vote for features on our Feedback Portal.
  13. Carlos
    Carlos avatar
    69 posts
    Member since:
    Jun 2011

    Posted 05 Jul 2013 Link to this post

    @Steve, 
    I changed the path from /plugins/ to /plugin/ but that did not seem to work. Still gave me the same error but with /plugin/ in it.  I have attached a screen shot and a visual of my tree structure in Mist.


    Is this a Cordova version issue?  A plugin version issue? Or something else?

    I am grateful for the help. This is probably something really small, but I appreciate all the help.

    Do you have any other ideas on what this might be?

    I am a big fan of Icenium and will be advocating more of it if I can understand the Plugin structure.

    Thanks.
  14. Carlos
    Carlos avatar
    69 posts
    Member since:
    Jun 2011

    Posted 05 Jul 2013 Link to this post

    Nevermind. I got it.  The variable and the declaration of the variable were cased differently.

    I know this is written for Android, will this same plugin work for iPhone?  Please say yes!
  15. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 08 Jul 2013 Link to this post

    Hello Carlos,

     Unfortunately the iOS SDK does not provide an official way to access a device's own phone number. There is a private API that can access this value, but using it will cause Apple to reject your app when you submit it to the App Store. This means that no iOS version of this plugin can be made.

    Regards,
    Yavor Georgiev
    Telerik

    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Missed our first webinar, watch it here.
    Share feedback and vote for features on our Feedback Portal.
Back to Top