Using PhoneGap, navigator.contacts.create () 'create' from undefined?

I'm going to reach the contact functions using the phonegap assembly, I added the API of the required function by calling the contact box after the device is ready in index.html. but it comes as creating undefined. Please tell me where I went missing ?. really appreciate. For further reference, I gave the code for the config.xml and index.html files.

Config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.AbsenceManagement" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
    <name>Add Contact</name>
    <description>       
    </description>
    <author email="support@phonegap.com" href="http://phonegap.com">        
    </author>         

    <feature name="http://api.phonegap.com/1.0/battery"/>   
    <feature name="http://api.phonegap.com/1.0/contacts"/>
    <feature name="http://api.phonegap.com/1.0/file"/>
    <feature name="http://api.phonegap.com/1.0/geolocation"/>
    <feature name="http://api.phonegap.com/1.0/media"/>
    <feature name="http://api.phonegap.com/1.0/network"/>
    <feature name="http://api.phonegap.com/1.0/notification"/>

    <feature name="Contacts">
        <param name="android-package" value="org.apache.cordova.contacts.ContactManager" />
    </feature>
    <feature name="Contacts">
        <param name="ios-package" value="CDVContacts" />
    </feature>

    <access origin="*" browserOnly="false" />
    <access origin=".*"/>

    <preference name="disallowOverscroll" value="true" />
    <preference name="webviewbounce" value="false" />
    <preference name="fullscreen" value="false" />
    <preference name="prerendered-icon" value="true" />
    <preference name="stay-in-webview" value="false" />
    <preference name="ios-statusbarstyle" value="white" />

    <preference name="detect-data-types" value="true" />
    <preference name="exit-on-suspend" value="false" />
    <preference name="show-splash-screen-spinner" value="true" />
    <!--<preference name="auto-hide-splash-screen" value="false" />-->
    <preference name="auto-hide-splash-screen" value="true" />
    <preference name="disable-cursor" value="false" />
    <preference name="orientation" value="portrait" />

    <preference name="phonegap-version" value="3.0.0" /> 
    <gap:splash gap:platform="android"  />
    <gap:splash gap:density="ldpi" gap:platform="android" src="resources/icons/drawable-ldpi/splash_screen.png" />
    <gap:splash gap:density="mdpi" gap:platform="android" src="resources/icons/drawable-mdpi/splash_screen.png" />
    <gap:splash gap:density="hdpi" gap:platform="android" src="resources/icons/drawable-hdpi/splash_screen.png" />
    <gap:splash gap:density="xhdpi" gap:platform="android" src="resources/icons/drawable-xhdpi/splash_screen.png" />

    <icon src="resources/icons/Icon-Small@2x.png" gap:platform="ios" width="57" height="57" />
    <icon src="resources/icons/hdpi/72x72.png" gap:platform="android" gap:density="hdpi" /> <!-- 36 pixels -->
    <icon src="resources/icons/ldpi/36x36.png" gap:platform="android" gap:density="ldpi" /> <!-- 48 pixels -->
    <icon src="resources/icons/mdpi/48x48.png" gap:platform="android" gap:density="mdpi" /> <!-- 72 pixels -->
    <icon src="resources/icons/xhdpi/96x96.png" gap:platform="android" gap:density="xhdpi" /> <!-- 96 pixels -->
    <icon src="resources/icons/xxhdpi/144x144.png" gap:platform="android" gap:density="xxhdpi" />

</widget>

Index.html ------------

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
        <!--<meta name="viewport" content="width=990">-->
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="white">
        <title>Add Contact</title>        
        <script type="text/javascript" src="cordova.js"></script>        
        <script>
            document.addEventListener("deviceready", onDeviceReady, false);
            function start(){
                alert('start');                 
            } 
            function onDeviceReady() {
               console.log('onDeviceReady');
               alert('onDeviceReady');
               try{
                var myContact = navigator.contacts.create({"displayName": "Test User"});
                myContact.note = "This contact has a note.";
                console.log("The contact, " + myContact.displayName + ", note: " + myContact.note); 
                alert('ContactCreated');
               }
               catch(e){
                   alert(e.message);
               }
               pictureSource=navigator.camera.PictureSourceType;
               destinationType=navigator.camera.DestinationType;
               alert('onDeviceReady After');

            }            
        </script>
    </head>
    <body onload="start();init();">
        <div id="outerContainer"  style="position: relative;overflow-x: hidden;" >
            <div id="homePage" class="screen-container" style="position: relative;min-height: 100%;" ></div>
        </div>

    </body>
</html>
+4
source share
1 answer

Check it out Config.xmlI don’t know what your requirement is, but I think you are using the plugin for contacts and camera, so I have included both plugins for you. That should work.

<?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.XYZ.ABC"
    version   = "1.0.0">

  <name>Test</name>

  <description>Demo app</description>

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

  <!--
    Enable individual API permissions by defining each here.
    The 'device' permission is required for the 'deviceready' event.
  -->
  <feature name="http://api.phonegap.com/1.0/device" />
  <feature name="http://api.phonegap.com/1.0/contacts"/>
  <feature name="Camera">
    <param name="android-package" value="org.apache.cordova.camera.CameraLauncher" />
  </feature>  

  <preference name="permissions"                value="none"/>
  <preference name="phonegap-version"           value="3.3.0" />
  <preference name="orientation"                value="portrait" />
  <preference name="target-device"              value="universal" />
  <preference name="fullscreen"                 value="true" />
  <preference name="webviewbounce"              value="false" />
  <preference name="prerendered-icon"           value="true" />
  <preference name="stay-in-webview"            value="false" />
  <preference name="ios-statusbarstyle"         value="black-opaque" />
  <preference name="detect-data-types"          value="true" />
  <preference name="exit-on-suspend"            value="false" />
  <preference name="show-splash-screen-spinner" value="false" />
  <preference name="auto-hide-splash-screen" value="true" />
  <preference name="disable-cursor"             value="false" />
  <preference name="android-minSdkVersion"      value="7" />
  <preference name="android-installLocation"    value="auto" />
  <preference name="DisallowOverscroll" value="true" />

  <icon src="res/icon/android/icon-36-ldpi.png"   gap:platform="android"    gap:density="ldpi" />
  <icon src="res/icon/android/icon-48-mdpi.png"   gap:platform="android"    gap:density="mdpi" />
  <icon src="res/icon/android/icon-72-hdpi.png"   gap:platform="android"    gap:density="hdpi" />
  <icon src="res/icon/android/icon-96-xhdpi.png"  gap:platform="android"    gap:density="xhdpi" />

  <gap:plugin name="org.apache.cordova.device" />
  <gap:plugin name="org.apache.cordova.contacts" version="0.2.3" />
  <gap:plugin name="org.apache.cordova.camera" version="0.2.3" />
  <plugin name="InAppBrowser" value="org.apache.cordova.InAppBrowser" />
  <access origin="*" browserOnly="true"/>

</widget>
0

Source: https://habr.com/ru/post/1526285/


All Articles