頁首 — X-Device-Info header-x-device-info
NOTE
此頁面上的內容僅供參考。 使用此API需要Adobe的目前授權。 不允許未經授權的使用。
概觀 overview
X-Device-Info 要求標頭包含與實際串流裝置相關的使用者端資訊(裝置、連線和應用程式)。
語法 syntax
指令 directives
<device_information>
JSON元素的Base64-encoded
值,至少包含下表標示的必要屬性。
範例 examples
// Device information
// {
// "primaryHardwareType" : "MobilePhone",
// "model":"SM-S901U",
// "vendor":"samsung",
// "version":"r0q",
// "manufacturer":"samsung",
// "osName":"Android",
// "osVersion":"14"
// }
// BASE64-encoded
// ewogICJwcmltYXJ5SGFyZHdhcmVUeXBlIiA6ICJNb2JpbGVQaG9uZSIsCiAgIm1vZGVsIjoiU00tUzkwMVUiLAogICJ2ZW5kb3I
// iOiJzYW1zdW5nIiwKICAidmVyc2lvbiI6InIwcSIsCiAgIm1hbnVmYWN0dXJlciI6InNhbXN1bmciLAogICJvc05hbWUiOiJBbmRyb
// 2lkIiwKICAib3NWZXJzaW9uIjoiMTQiCn0=
X-Device-Info: ewogICJwcmltYXJ5SGFyZHdhcmVUeXBlIiA6ICJNb2JpbGVQaG9uZSIsCiAgIm1vZGVsIjoiU00tUzkwMVUiLAogICJ2ZW5kb3IiOiJzYW1zdW5nIiwKICAidmVyc2lvbiI6InIwcSIsCiAgIm1hbnVmYWN0dXJlciI6InNhbXN1bmciLAogICJvc05hbWUiOiJBbmRyb2lkIiwKICAib3NWZXJzaW9uIjoiMTQiCn0=
逐步指南 cookbooks
IMPORTANT
提供的程式碼片段和檔案資源僅供參考。
程式碼片段並非詳盡無遺,且可能需要額外修改才能在專案中運作。
無論您實際實作為何,
X-Device-Info
標頭都必須包含如指示區段中所述格式化的值。瀏覽器 browsers
對於在瀏覽器中執行的使用者端應用程式,可以省略X-Device-Info
標頭,因為瀏覽器會自動在User-Agent
標頭中傳送一組最少的必要資訊。
您仍然可以使用X-Device-Info
標頭來提供裝置、連線和應用程式的額外資訊,以防您的使用者端應用程式整合提供裝置識別機制的程式庫或服務。
行動裝置 mobile-devices
iOS和iPadOS ios-ipados
若要為執行iOS或iPadOS的裝置建置X-Device-Info
標題,您可以參考下列檔案及下列程式碼片段:
+ (NSString *)computeClientInformation {
struct utsname u;
uname(&u);
NSString *hardware = [NSString stringWithCString:u.machine encoding:NSUTF8StringEncoding];
UIDevice *device = [UIDevice currentDevice];
NSString *deviceType;
switch (UI_USER_INTERFACE_IDIOM()) {
case UIUserInterfaceIdiomPhone:
deviceType = @"MobilePhone";
break;
case UIUserInterfaceIdiomPad:
deviceType = @"Tablet";
break;
case UIUserInterfaceIdiomTV:
deviceType = @"TV";
break;
default:
deviceType = @"Unknown";
}
CGRect screenRect = [[UIScreen mainScreen] bounds];
NSNumber *screenWidth = @((float) screenRect.size.width);
NSNumber *screenHeight = @((float) screenRect.size.height);
Reachability *reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];
NetworkStatus status = [reachability currentReachabilityStatus];
NSString *connectionType;
if (status == NotReachable) {
connectionType = @"notConnected";
} else if (status == ReachableViaWiFi) {
connectionType = @"WiFi";
} else if (status == ReachableViaWWAN) {
connectionType = @"cellular";
}
NSMutableDictionary *clientInformation = [@{
@"type": deviceType,
@"model": device.model,
@"vendor": @"Apple",
@"manufacturer": @"Apple",
@"version": [hardware stringByReplacingOccurrencesOfString:device.model withString:@""],
@"osName": device.systemName,
@"osVersion": device.systemVersion,
@"displayWidth": screenWidth,
@"displayHeight": screenHeight,
@"connectionType": connectionType,
@"applicationId": @"REF30"
} mutableCopy];
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:clientInformation options:NSJSONWritingPrettyPrinted error:&error];
NSString *base64Encoded = [jsonData base64EncodedStringWithOptions:0];
return base64Encoded;
}
裝置資訊的建構方式如下:
索引鍵
Source
值(範例)
模型
uname.machine
iPhone
廠商
硬式編碼
Apple
製造商
硬式編碼
Apple
版本
uname.machine
8,1
displaywidth
UIScreen.mainScreen
320
displayheight
UIScreen.mainScreen
568
osName
UIDevice.systemName
iOS
osVersion
UIDevice.systemVersion
10.2
連線資訊的建構方式如下:
索引鍵
Source
值(範例)
connectionType
[連線能力currentReachableStatus]
connectionSecure
應用程式資訊的建構方式如下:
索引鍵
Source
值(範例)
applicationId
硬式編碼
REF30
Android android
若要為執行Android的裝置建置X-Device-Info
標題,您可以參考下列檔案及下列程式碼片段:
- Build類別的Android開發人員檔案。
private JSONObject computeClientInformation() {
String LOGGING_TAG = "DefineClass.class";
JSONObject clientInformation = new JSONObject();
String connectionType;
try {
ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
if (activeNetwork != null && activeNetwork.isConnectedOrConnecting()) {
switch (activeNetwork.getType()) {
case ConnectivityManager.TYPE_WIFI: {
connectionType = "WIFI";
break;
}
case ConnectivityManager.TYPE_BLUETOOTH: {
connectionType = "BLUETOOTH";
break;
}
case ConnectivityManager.TYPE_MOBILE: {
connectionType = "MOBILE";
break;
}
case ConnectivityManager.TYPE_ETHERNET: {
connectionType = "ETHERNET";
break;
}
case ConnectivityManager.TYPE_VPN: {
connectionType = "VPN";
break;
}
case ConnectivityManager.TYPE_DUMMY: {
connectionType = "DUMMY";
break;
}
case ConnectivityManager.TYPE_MOBILE_DUN: {
connectionType = "MOBILE_DUN";
break;
}
case ConnectivityManager.TYPE_WIMAX: {
connectionType = "WIMAX";
break;
}
default:
connectionType = ConnectivityManager.EXTRA_OTHER_NETWORK_INFO;
}
} else {
connectionType = ConnectivityManager.EXTRA_NO_CONNECTIVITY;
}
} catch (Exception e) {
connectionType = "notAccessible";
}
try {
clientInformation.put("model", Build.MODEL);
clientInformation.put("vendor", Build.BRAND);
clientInformation.put("manufacturer", Build.MANUFACTURER);
clientInformation.put("version", Build.DEVICE);
clientInformation.put("osName", "Android");
clientInformation.put("osVersion", Build.VERSION.RELEASE);
clientInformation.put("connectionType", connectionType);
clientInformation.put("applicationId", "REF30");
} catch (JSONException e) {
Log.e(LOGGING_TAG, e.getMessage());
}
return Base64.encodeToString(clientInformation.toString().getBytes(), Base64.NO_WRAP);
}
裝置資訊的建構方式如下:
索引鍵
Source
值(範例)
模型
Build.MODEL
GT-I9505
廠商
Build.BRAND
samsung
製造商
Build.MANUFACTURER
samsung
版本
Build.DEVICE
jflte
displaywidth
DisplayMetrics.widthPixels
600
displayheight
DisplayMetrics.heightPixels
800
osName
硬式編碼
Android
osVersion
Build.VERSION.RELEASE
5.0.1
連線資訊的建構方式如下:
索引鍵
Source
值(範例)
connectionType
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
getSystemService(Context.CONNECTIVITY_SERVICE).getActiveNetworkInfo().getType()
"WIFI","BLUETOOTH","MOBILE","ETHERNET","VPN","DUMMY","MOBILE_DUN","WIMAX","notAccessible"
connectionSecure
應用程式資訊的建構方式如下:
索引鍵
Source
值(範例)
applicationId
硬式編碼
REF30
電視連線裝置 tv-connected-devices
tvOS tvos
若要為執行tvOS的裝置建置X-Device-Info
標題,您可以參考下列檔案及下列程式碼片段:
+ (NSString *)computeClientInformation {
struct utsname u;
uname(&u);
NSString *hardware = [NSString stringWithCString:u.machine encoding:NSUTF8StringEncoding];
UIDevice *device = [UIDevice currentDevice];
NSString *deviceType;
switch (UI_USER_INTERFACE_IDIOM()) {
case UIUserInterfaceIdiomPhone:
deviceType = @"MobilePhone";
break;
case UIUserInterfaceIdiomPad:
deviceType = @"Tablet";
break;
case UIUserInterfaceIdiomTV:
deviceType = @"TV";
break;
default:
deviceType = @"Unknown";
}
CGRect screenRect = [[UIScreen mainScreen] bounds];
NSNumber *screenWidth = @((float) screenRect.size.width);
NSNumber *screenHeight = @((float) screenRect.size.height);
Reachability *reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];
NetworkStatus status = [reachability currentReachabilityStatus];
NSString *connectionType;
if (status == NotReachable) {
connectionType = @"notConnected";
} else if (status == ReachableViaWiFi) {
connectionType = @"WiFi";
} else if (status == ReachableViaWWAN) {
connectionType = @"cellular";
}
NSMutableDictionary *clientInformation = [@{
@"type": deviceType,
@"model": device.model,
@"vendor": @"Apple",
@"manufacturer": @"Apple",
@"version": [hardware stringByReplacingOccurrencesOfString:device.model withString:@""],
@"osName": device.systemName,
@"osVersion": device.systemVersion,
@"displayWidth": screenWidth,
@"displayHeight": screenHeight,
@"connectionType": connectionType,
@"applicationId": @"REF30"
} mutableCopy];
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:clientInformation options:NSJSONWritingPrettyPrinted error:&error];
NSString *base64Encoded = [jsonData base64EncodedStringWithOptions:0];
return base64Encoded;
}
裝置資訊的建構方式如下:
索引鍵
Source
值(範例)
模型
uname.machine
AppleTV
廠商
硬式編碼
Apple
製造商
硬式編碼
Apple
版本
uname.machine
8,1
displaywidth
UIScreen.mainScreen
1920
displayheight
UIScreen.mainScreen
1080
osName
UIDevice.systemName
tvOS
osVersion
UIDevice.systemVersion
10.2
連線資訊的建構方式如下:
索引鍵
Source
值(範例)
connectionType
[連線能力currentReachableStatus]
connectionSecure
應用程式資訊的建構方式如下:
索引鍵
Source
值(範例)
applicationId
硬式編碼
REF30
Fire OS fireos
若要為執行Fire OS的裝置建置X-Device-Info
標頭,您可以參考下列檔案:
- Build類別的Android開發人員檔案。
- 識別Fire TV裝置的Amazon開發人員檔案。
裝置資訊的建構方式如下:
索引鍵
Source
值(範例)
模型
Build.MODEL
AFTM
廠商
Build.BRAND
Amazon
製造商
Build.MANUFACTURER
Amazon
版本
Build.DEVICE
montoya
displaywidth
DisplayMetrics.widthPixels
displayheight
DisplayMetrics.heightPixels
osName
硬式編碼
Android
osVersion
Build.VERSION.RELEASE
5.1.1
連線資訊的建構方式如下:
索引鍵
Source
值(範例)
connectionType
connectionSecure
應用程式資訊的建構方式如下:
索引鍵
Source
值(範例)
applicationId
硬式編碼
REF30
Roku OS rokuos
若要為執行Roku OS的裝置建置X-Device-Info
標題,您可以參考下列檔案:
- ifDeviceInfo的Roku開發人員檔案。
裝置資訊的建構方式如下:
索引鍵
Source
值(範例)
模型
硬式編碼
"Roku"
廠商
ifDeviceInfo.GetModelDetails().VendorName
"Sharp"、"Roku"
製造商
ifDeviceInfo.GetModelDetails().VendorName
"Sharp"、"Roku"
版本
ifDeviceInfo.GetModelDetails().ModelNumber
「5303X」
displaywidth
ifDeviceInfo.GetDisplaySize().w
1920
displayheight
ifDeviceInfo.GetDisplaySize().h
1080
osName
硬式編碼
"Roku"
osVersion
ifDeviceInfo.getVersion()
連線資訊的建構方式如下:
索引鍵
Source
值(範例)
connectionType
ifDeviceInfo.GetConnectionType()
「WifiConnection」、「WiredConnection」
connectionSecure
硬式編碼
如果連線有線,則為true
應用程式資訊的建構方式如下:
索引鍵
Source
值(範例)
applicationId
硬式編碼
REF30
recommendation-more-help
3f5e655c-af63-48cc-9769-2b6803cc5f4b