Showing posts with label Phonegap. Show all posts
Showing posts with label Phonegap. Show all posts

Tuesday, 14 February 2017

ionic2 based using Angular2 TypeScript

This tutorial is demonstrating "How to create ionic2 based app using Angular2 TypeScript"?

Here is the demo example with complete guide documentation process to install and run this demo project.

Happy Coding!

Wednesday, 13 June 2012

Play sound in iPhone | Phonegap

Ahh! After lot of search i found some clue for playing sound in iPhone through phonegap.
Path for  sound file --> import your sound file inside www folder.
Let say :
Path : www->src->alarm.wav
i)initiateAudio()-> This function describes to initiate the audio tag on source and set source attribute.
ii)playAudio()-> Use this function to play sound file.


if you want to check the fileformat 

if (audio.canPlayType('audio/mpeg')) 
source.type= 'audio/mpeg'; 
source.src='your_file_name.mp3'; 
else 
source.type= 'audio/wav'; 
source.src='your_file_name.wav'; 
}

EXAMPLE:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Play Sound in both OS</title>
<script type="text/javascript" src="js/cordova-1.8.0.js"></script>
<script type="text/javascript">
$(document).ready(function()  {
 initiateAudio();
});
var audio;
function initiateAudio() {
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
//CODE_FOR_IPHONE_||_IPAD
    var source= document.createElement('source'); 
    audio= document.createElement('audio'); 
    source.type='audio/wav';
    source.src='src/alarm.wav'; 

    audio.setAttribute('src', source.src); 
   
}else{
      //CODE_FOR_ANDROID
      audio = new Media("/android_asset/www/src/alarm.wav");
}
}
function playAudio(){
audio.play();
}
</script>
</head>
<body>
//YOUR_CONTENT_HERE
</body>
</html>

Tuesday, 1 November 2011

Network Reachability Code in Phonegap




// Wait for PhoneGap to load

// 
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
//
function onDeviceReady() {

}

function checkReachability() {
var _check=true;

var networkState = navigator.network.connection.type;
var states = {};
states[Connection.UNKNOWN]  = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI]     = 'WiFi connection';
states[Connection.CELL_2G]  = 'Cell 2G connection';
states[Connection.CELL_3G]  = 'Cell 3G connection';
states[Connection.CELL_4G]  = 'Cell 4G connection';
states[Connection.NONE]     = 'No network connection';
 
    //alert('Connection type: '+ networkState + states[networkState]);
  if(networkState==="unknown"){
  _check=false;
  showAlert();
  return _check;
  }
  else {
  return true;
  }
  
}

function showAlert() {
navigator.notification.alert("Please connect your device to Internet.",onDeviceReady,"No Network Connectivity","OK");
}


Putting this code  in one js file i.e named as network_reachability.js


onload function calls on HTML page.
 <body onload="onload()">
Use checkReachability function where you check internet connectivity.


Enjoy :)

ERROR whitelist rejection in phonegap compilation | Custom URL Scheme


Change in Phonegap.plist

Go to External Host and add row (i.e left click on row)
In Value column : Put your domain name.

Example :
Whenever you fetch any URL in iPhone  through phonegap.We do like this.

1) ERROR whitelist rejection: url('http://localhost:8888/myproject/index.html')
    Type: localhost in value column
2) ERROR whitelist rejection: url('http://google.com/dashboard/mobilews.php?')
    Type: google in value column

It works for me.

Cheers :)