2009-11-10 09:45:02 +08:00
|
|
|
package com.phonegap;
|
2009-04-02 07:56:43 +08:00
|
|
|
/* License (MIT)
|
|
|
|
* Copyright (c) 2008 Nitobi
|
|
|
|
* website: http://phonegap.com
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* Software), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
2009-09-12 05:30:24 +08:00
|
|
|
|
2009-04-02 07:56:43 +08:00
|
|
|
import java.util.TimeZone;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Vibrator;
|
2009-12-16 02:38:38 +08:00
|
|
|
import android.provider.Settings;
|
2009-04-02 07:56:43 +08:00
|
|
|
import android.telephony.TelephonyManager;
|
|
|
|
import android.webkit.WebView;
|
|
|
|
import android.media.Ringtone;
|
|
|
|
import android.media.RingtoneManager;
|
|
|
|
|
2010-06-09 07:30:20 +08:00
|
|
|
public class Device{
|
2009-04-02 07:56:43 +08:00
|
|
|
|
|
|
|
private static final String LOG_TAG = "PhoneGap";
|
|
|
|
/*
|
|
|
|
* UUID, version and availability
|
|
|
|
*/
|
|
|
|
public boolean droid = true;
|
2010-06-09 07:30:20 +08:00
|
|
|
public static String version = "0.91";
|
2009-04-02 07:56:43 +08:00
|
|
|
public static String platform = "Android";
|
|
|
|
public static String uuid;
|
|
|
|
private Context mCtx;
|
|
|
|
private WebView mAppView;
|
2010-06-09 07:30:20 +08:00
|
|
|
AudioPlayer audio;
|
2009-04-02 07:56:43 +08:00
|
|
|
|
2010-06-09 07:30:20 +08:00
|
|
|
public Device(WebView appView, Context ctx) {
|
2009-04-02 07:56:43 +08:00
|
|
|
this.mCtx = ctx;
|
|
|
|
this.mAppView = appView;
|
|
|
|
uuid = getUuid();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void beep(long pattern)
|
|
|
|
{
|
2009-09-12 05:30:24 +08:00
|
|
|
Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
|
|
|
Ringtone notification = RingtoneManager.getRingtone(mCtx, ringtone);
|
2010-07-08 06:54:33 +08:00
|
|
|
if (notification != null) { // This will be the case when the phone is set to silent for example
|
|
|
|
for (long i = 0; i < pattern; ++i)
|
|
|
|
{
|
|
|
|
notification.play();
|
|
|
|
}
|
2009-07-18 04:23:51 +08:00
|
|
|
}
|
2009-04-02 07:56:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void vibrate(long pattern){
|
|
|
|
// Start the vibration, 0 defaults to half a second.
|
|
|
|
if (pattern == 0)
|
|
|
|
pattern = 500;
|
|
|
|
Vibrator vibrator = (Vibrator) mCtx.getSystemService(Context.VIBRATOR_SERVICE);
|
|
|
|
vibrator.vibrate(pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPlatform()
|
|
|
|
{
|
|
|
|
return this.platform;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getUuid()
|
2009-11-03 02:06:23 +08:00
|
|
|
{
|
2009-12-16 02:38:38 +08:00
|
|
|
//TelephonyManager operator = (TelephonyManager) mCtx.getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
|
//String uuid = operator.getDeviceId();
|
|
|
|
String uuid = Settings.Secure.getString(mCtx.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
|
2009-04-02 07:56:43 +08:00
|
|
|
return uuid;
|
|
|
|
}
|
2010-04-23 16:49:47 +08:00
|
|
|
|
2010-06-09 07:30:20 +08:00
|
|
|
public String getLine1Number(){
|
2010-04-23 16:49:47 +08:00
|
|
|
TelephonyManager operator = (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
|
return operator.getLine1Number();
|
2010-06-09 07:30:20 +08:00
|
|
|
}
|
|
|
|
|
2010-04-23 16:49:47 +08:00
|
|
|
public String getDeviceId(){
|
|
|
|
TelephonyManager operator = (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
|
return operator.getDeviceId();
|
2010-06-09 07:30:20 +08:00
|
|
|
}
|
|
|
|
|
2010-04-23 16:49:47 +08:00
|
|
|
public String getSimSerialNumber(){
|
|
|
|
TelephonyManager operator = (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
|
return operator.getSimSerialNumber();
|
|
|
|
}
|
2010-06-09 07:30:20 +08:00
|
|
|
|
|
|
|
public String getSubscriberId(){
|
2010-04-23 16:49:47 +08:00
|
|
|
TelephonyManager operator = (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
|
return operator.getSubscriberId();
|
2010-06-09 07:30:20 +08:00
|
|
|
}
|
2009-04-02 07:56:43 +08:00
|
|
|
|
|
|
|
public String getModel()
|
|
|
|
{
|
|
|
|
String model = android.os.Build.MODEL;
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
public String getProductName()
|
|
|
|
{
|
|
|
|
String productname = android.os.Build.PRODUCT;
|
|
|
|
return productname;
|
|
|
|
}
|
|
|
|
public String getOSVersion()
|
|
|
|
{
|
|
|
|
String osversion = android.os.Build.VERSION.RELEASE;
|
|
|
|
return osversion;
|
|
|
|
}
|
|
|
|
public String getSDKVersion()
|
|
|
|
{
|
|
|
|
String sdkversion = android.os.Build.VERSION.SDK;
|
|
|
|
return sdkversion;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getVersion()
|
|
|
|
{
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getTimeZoneID() {
|
|
|
|
TimeZone tz = TimeZone.getDefault();
|
|
|
|
return(tz.getID());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|