proj.android-studio\app\src\org\cocos2dx\cpp\AppActivity.java
增加
import android.os.Build; // 主機版名稱 String board = Build.BOARD;
public class AppActivity extends Cocos2dxActivity {
private static String deviceInfo; //回傳手機型號跟系統版本
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
deviceInfo = this.getDeviceInfo();
}
public static String findDeviceInfo() {
return deviceInfo;
}
/**
* Get Android node and Android version
* */
public String getDeviceInfo()
{
TelephonyManager manager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
String model = Build.MODEL; //手機型號
String phoneNum = manager.getLine1Number();//本機電話號碼
String sdkVersion = Build.VERSION.SDK;//SDK版本號
String osVersion = Build.VERSION.RELEASE;//Firmware/OS 版本號
return "Phone:" +model + " OS:" + osVersion;
}
}
///參考文章
http://www.cocos2dev.com/?p=208
今天要獲取用戶反饋意見,我默認將用戶的手機號碼上傳了,結果發現並不是所有的手機能拿到本機號碼。找了下發現原是用戶的SIM卡沒有寫入本機號碼導致的。
Android獲取本機號碼:
TelephonyManager phoneMgr = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
String phoneNum = phoneMgr.getLine1Number();
AndroidManifest.xml中添加權限:
<uses-permission android:name=」android.permission.READ_PHONE_STATE」 />
剛才也說了,手機號碼不是所有的都能獲取。只是有一部分可以拿到。這個是由於移動運營商沒有把手機號碼的數據寫入到sim卡中。
手機型號 Build.MODEL
String MODEL The end-user-visible name for the end product.
sdk版本 Build.VERSION.SDK
String SDK This constant is deprecated. Use SDK_INT to easily get this as an integer.
frimware版本號(系統版本號) Build.VERSION.RELEASE
String RELEASE The user-visible version string.
獲取手機的其他信息:
private void getPhoneStatus(){
TelephonyManager phoneMgr=(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
String model = Build.MODEL; //手機型號
String phoneNum = phoneMgr.getLine1Number();//本機電話號碼
String sdkVersion = Build.VERSION.SDK;//SDK版本號
String osVersion = Build.VERSION.RELEASE;//Firmware/OS 版本號
}
Build中包括 硬件廠商,硬件編號,序列號等很多信息。調用方法也很簡單,和上面類似的。
下面是Google提供的參考表:
String | BOARD | The name of the underlying board, like 「goldfish」. |
String | BOOTLOADER | The system bootloader version number. |
String | BRAND | The brand (e.g., carrier) the software is customized for, if any. |
String | CPU_ABI | The name of the instruction set (CPU type + ABI convention) of native code. |
String | CPU_ABI2 | The name of the second instruction set (CPU type + ABI convention) of native code. |
String | DEVICE | The name of the industrial design. |
String | DISPLAY | A build ID string meant for displaying to the user |
String | FINGERPRINT | A string that uniquely identifies this build. |
String | HARDWARE | The name of the hardware (from the kernel command line or /proc). |
String | HOST | |
String | ID | Either a changelist number, or a label like 「M4-rc20」. |
String | MANUFACTURER | The manufacturer of the product/hardware. |
String | MODEL | The end-user-visible name for the end product. |
String | PRODUCT | The name of the overall product. |
String | RADIO | The radio firmware version number. |
String | SERIAL | A hardware serial number, if available. |
String | TAGS | Comma-separated tags describing the build, like 「unsigned,debug」. |
long | TIME | |
String | TYPE | The type of build, like 「user」 or 「eng」. |
String | UNKNOWN | Value used for when a build property is unknown. |
String | USER |
沒有留言:
張貼留言