From c96e36935133e5b2aa482ba31ccf9f23acf27ba7 Mon Sep 17 00:00:00 2001 From: addios Date: Fri, 27 Feb 2009 14:22:59 +0700 Subject: [PATCH] Added phone information for android --- assets/gap.js | 21 +++- assets/index.html | 58 ++++++++-- src/com/nitobi/phonegap/DirectoryManager.java | 109 ++++++++++++++++++ src/com/nitobi/phonegap/PhoneGap.java | 27 +++++ 4 files changed, 202 insertions(+), 13 deletions(-) create mode 100644 src/com/nitobi/phonegap/DirectoryManager.java diff --git a/assets/gap.js b/assets/gap.js index c7390440..778209a9 100644 --- a/assets/gap.js +++ b/assets/gap.js @@ -330,7 +330,7 @@ var Device = { Device.storage.result = window.DroidGap.createDirectory(file); return Device.storage.result; } - } + }, audio: { @@ -352,7 +352,24 @@ var Device = { getDuration: function(file) { return window.DroidGap.getDurationAudio(file); } - } + }, + information: { + getLine1Number: function(){ + return window.DroidGap.getLine1Number(); + }, + getVoiceMailNumber: function(){ + return window.DroidGap.getVoiceMailNumber(); + }, + getNetworkOperatorName: function(){ + return window.DroidGap.getNetworkOperatorName(); + }, + getSimCountryIso: function(){ + return window.DroidGap.getSimCountryIso(); + }, + getTimeZoneID: function(){ + return window.DroidGap.getTimeZoneID(); + } + } } diff --git a/assets/index.html b/assets/index.html index 6aa8b010..1e35cb50 100644 --- a/assets/index.html +++ b/assets/index.html @@ -149,7 +149,14 @@ audio = function(func) } } - +phInformation = function(){ + alert ('Device.information.getLine1Number()'); + $('phnumber').value = Device.information.getLine1Number(); + $('vmnumber').value = Device.information.getVoiceMailNumber(); + $('nwoperator').value = Device.information.getNetworkOperatorName(); + $('simiso').value = Device.information.getSimCountryIso(); + $('tzid').value = Device.information.getTimeZoneID(); +} addLoadEvent(initGap); @@ -175,6 +182,7 @@ addLoadEvent(initGap);
  • Notification...
  • HTTP...
  • External Storage
  • +
  • Phone Info...
  • About
  • @@ -334,16 +342,17 @@ addLoadEvent(initGap);

    Storage Management

    -
    - - -
    -
    - Check File - -
    +
    + + +
    + +
    + Check File + +
    Create Directory @@ -392,6 +401,33 @@ addLoadEvent(initGap);
    +
    + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    + +
    +
    +
    diff --git a/src/com/nitobi/phonegap/DirectoryManager.java b/src/com/nitobi/phonegap/DirectoryManager.java new file mode 100644 index 00000000..d3e0e96d --- /dev/null +++ b/src/com/nitobi/phonegap/DirectoryManager.java @@ -0,0 +1,109 @@ +package com.nitobi.phonegap; + +import java.io.File; + +import android.os.Environment; + +public class DirectoryManager { + + protected boolean isDirtoryOrFileExists (String name){ + boolean status; + if ((testSaveLocationExists())&&(!name.equals(""))){ + File path = Environment.getExternalStorageDirectory(); + File newPath = constructFilePaths(path.toString(), name); + status = newPath.exists(); + + }else{ + status = false; + } + return status; + } + + protected boolean createDirectory(String directoryName){ + boolean status; + if ((testSaveLocationExists())&&(!directoryName.equals(""))){ + File path = Environment.getExternalStorageDirectory(); + File newPath = constructFilePaths(path.toString(), directoryName); + status = newPath.mkdir(); + status = true; + }else + status = false; + return status; + } + + protected boolean testSaveLocationExists(){ + String sDCardStatus = Environment.getExternalStorageState(); + boolean status; + if (sDCardStatus.equals(Environment.MEDIA_MOUNTED)){ + status = true; + }else + status = false; + return status; + } + + protected boolean deleteDir (String fileName){ + boolean status; + SecurityManager checker = new SecurityManager(); + + if ((testSaveLocationExists())&&(!fileName.equals(""))){ + + File path = Environment.getExternalStorageDirectory(); + File newPath = constructFilePaths(path.toString(), fileName); + checker.checkDelete(newPath.toString()); + if(newPath.isDirectory()){ + System.out.println("Dir = "+ fileName); + String[] listfile = newPath.list(); + + try{ + for (int i=0; i < listfile.length; i++){ + System.out.println(listfile[i].toString()+" length = "+listfile.length); + File deletedFile = new File (newPath.toString()+"/"+listfile[i].toString()); + deletedFile.delete(); + } + + newPath.delete(); + status = true; + }catch (Exception e){ + e.printStackTrace(); + status = false; + } + + }else + status = false; + }else + status = false; + return status; + + } + protected boolean deleteFile (String fileName){ + boolean status; + SecurityManager checker = new SecurityManager(); + + if ((testSaveLocationExists())&&(!fileName.equals(""))){ + + File path = Environment.getExternalStorageDirectory(); + File newPath = constructFilePaths(path.toString(), fileName); + checker.checkDelete(newPath.toString()); + if (newPath.isFile()){ + try { + System.out.println("deleting the file"); + newPath.delete(); + status = true; + }catch (SecurityException se){ + se.printStackTrace(); + status = false; + } + }else + status = false; + }else + status = false; + return status; + + } + private File constructFilePaths (String file1, String file2){ + File newPath; + newPath = new File(file1+"/"+file2); + return newPath; + } + +} \ No newline at end of file diff --git a/src/com/nitobi/phonegap/PhoneGap.java b/src/com/nitobi/phonegap/PhoneGap.java index 9a313758..d5e72fba 100644 --- a/src/com/nitobi/phonegap/PhoneGap.java +++ b/src/com/nitobi/phonegap/PhoneGap.java @@ -22,6 +22,7 @@ package com.nitobi.phonegap; * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import java.io.IOException; +import java.util.TimeZone; import android.content.Context; import android.content.IntentFilter; @@ -319,5 +320,31 @@ public class PhoneGap{ System.out.println(audio.getDuration(file)); return(audio.getDuration(file)); } + + public String getLine1Number() { + TelephonyManager tm = + (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE); + return(tm.getLine1Number()); + } + public String getVoiceMailNumber() { + TelephonyManager tm = + (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE); + return(tm.getVoiceMailNumber()); + } + public String getNetworkOperatorName(){ + TelephonyManager tm = + (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE); + return(tm.getNetworkOperatorName()); + } + public String getSimCountryIso(){ + TelephonyManager tm = + (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE); + return(tm.getSimCountryIso()); + } + public String getTimeZoneID() { + TimeZone tz = TimeZone.getDefault(); + return(tz.getID()); + } + }