動作中のデバイスがKindleかアプリで判別するサンプルを以下に記述。
-----
/*
* Display device info.
*
* @note More detail information of SystemInfo that see below url.
* http://docs-jp.unity3d.com/Documentation/ScriptReference/SystemInfo.html
*/
using UnityEngine;
using System.Collections;
public class Sample_KindleCheck : MonoBehaviour {
string debug_message; //!< Display strings
GUIStyle labelStyle; //!< GUI text
public static AndroidJavaClass unityPlayer;
public static string MODEL {get; set;}
public static string MANUFACTURER {get; set;}
void Start(){
Screen.orientation = ScreenOrientation.Portrait; //Set screen to portrait.
//Screen.orientation = ScreenOrientation.Landscape; //Set screen to landscape.
Screen.sleepTimeout = SleepTimeout.NeverSleep; //No sleep device when running this app.
labelStyle = new GUIStyle();
labelStyle.fontSize = Screen.height / 60;
labelStyle.normal.textColor = Color.white;
debug_message = "deviceModel: "+ SystemInfo.deviceModel + "\n";
if(Application.platform == RuntimePlatform.Android){ // is this Android device?
AndroidJavaClass buildClass = new AndroidJavaClass("android.os.Build");
MANUFACTURER = buildClass.GetStatic<string>("MANUFACTURER");
MODEL = buildClass.GetStatic<string>("MODEL");
debug_message += string.Format("MANUFACTURER: {0}\nMODEL: {1}\n", MANUFACTURER, MODEL);
//Kindle check
if(MANUFACTURER=="Amazon") debug_message += "This is KINDLE";
else debug_message += "This is not KINDLE";
}
}
void OnGUI(){
float x = Screen.width / 30;
float w = Screen.width * 8 / 10;
float h = Screen.height / 19;
string text = string.Format("{0}", debug_message);
GUI.Label(new Rect(x, 64, w, h), text, labelStyle);
}
}
-----Kindle機の場合、
- android.os.Build.MANUFACTURER に "Amazon"が格納されている
- android.os.Build.MODELに モデル名が格納されている
※モデル名は SystemInfo.deviceModel からでも取得できる。
各Kindle機種とモデル名の対応は以下に。
モデル名 機種 (第一世代)Android 2.3.3(Gingerbread / API level10) "kindle Fire" Kindle Fire (第二世代)Android4.0.3( Ice Cream Sandwich / API level15) "KFOT" Kindle Fire "KFTT" Kindle Fire HD "KFJWA" Kindle Fire HD8.9 (wan) "KFJWI" Kindle Fire HD8.9 (wi-fi) (第三世代)Fire OS 3.0。Android4.2.2(JellyBean / API level17) "KFSOWI" Kindle Fire HD "KFTHWA" Kindle Fire HDX (wan) "KFTHWI" Kindle Fire HDX (wi-fi) "KFAPWA" Kindle Fire HDX 8.9 (wan) "KFAPWI" Kindle Fire HDX 8.9 (wifi)
追記2014/6/27:
今後、MANUFACTURER=="Amazon" だけではFire Phoneも該当する可能性がありえそうです(実機が無いので未確認)。
明らかにKindleと判定するにはさらにモデル名も照合すれば良いのですけど。
アプリによって判定を随時考慮する必要があるかもしれません。
0 件のコメント:
コメントを投稿