@amazon-devices/kepler-identifiers
Kepler識別子APIは、UUID、デバイス名、ユーザーエージェントなどの識別子、および追跡識別子と広告識別子を生成、取得、管理するための機能を提供します。
開始の手順
セットアップ
-
package.jsonファイルの
dependenciesセクションに、以下のライブラリ依存関係を追加します。"@amazon-devices/kepler-identifiers": "~0.1.0" -
manifest.tomlに、デバイスの通称にアクセスするために必要な以下の権限を追加します。
[[needs.privilege]] id = "com.amazon.devconf.privilege.identifiers.device-friendly-name"
使用方法
UUID v4の生成
この例は、UUID v4を生成する方法を示しています。このコードは単純なハンドラー関数であり、基本的なエラー処理でgenerateUuidV4()メソッドをラップしています。このパターンを使用して、メソッドをアプリのイベントハンドラーやユーティリティ関数に統合できます。
import {KeplerIdentifiers as Identifiers} from '@amazon-devices/kepler-identifiers';
const handleGenerateUuidV4 = () => {
try {
let result = Identifiers.generateUuidV4();
return result;
} catch (error) {
console.error(error);
}
};
デバイスの通称の取得
getFriendlyDeviceName()メソッドは、対象となるペルソナのデバイスの通称を返します。
返されるのは、次のいずれかです。
- ユーザーがカスタマイズしたデバイス名(ユーザーがカスタマイズしたデバイス名が存在し、呼び出し元が
com.amazon.devconf.privilege.identifiers.device-friendly-nameの実行時権限を持っている場合) - デバイスモデル名(以下の場合)
- ユーザーがカスタマイズした名前が設定されていない
- 呼び出し元に必要な権限がない
import {KeplerIdentifiers as Identifiers} from '@amazon-devices/kepler-identifiers';
const handleGetFriendlyDeviceName = async () => {
try {
let result = await Identifiers.getFriendlyDeviceName();
return result;
} catch (error) {
console.error(error);
}
};
実行時の権限のリクエスト
実行時の権限を取得する場合は、ユーザーの同意を得てください。セキュリティマネージャーAPIを使用して実行時のcom.amazon.devconf.privilege.identifiers.device-friendly-name権限をリクエストすることで、ユーザーの同意ダイアログを開くことができます。
import {SecurityManager, PrivilegeState} from '@amazon-devices/security-manager-lib';
import { KeplerIdentifiers as Identifiers } from '@amazon-devices/kepler-identifiers';
const DEVICE_NAME_PRIVILEGE = 'com.amazon.devconf.privilege.identifiers.device-friendly-name';
SecurityManager.getPrivilegeState(DEVICE_NAME_PRIVILEGE).then(
function(state: PrivilegeState) {
if (state == PrivilegeState.ALLOW) {
// ユーザーは既に同意しています。
return Identifiers.getFriendlyDeviceName();
} else {
// ユーザーの同意をリクエストします。
// この呼び出しはブロックされ、各アプリはこの呼び出しをスレッドモデルまたはイベントループに統合します。
SecurityManager.requestPrivilege(DEVICE_NAME_PRIVILEGE).then(
function(state: PrivilegeState) {
if (state == PrivilegeState.ALLOW) {
// ユーザーが同意しました。
return Identifiers.getFriendlyDeviceName();
} else {
// ユーザーは同意しませんでした。
}
},
function(error: Object) { KPLOG().error("権限のリクエストに失敗しました:{}", error["message"]); }
)
}
},
function(error: Object) { KPLOG().error("権限の状態を取得できませんでした:{}", error["message"]); }
)
モジュール
- index
- turbo-modules/KeplerIdentifiersTM
- turbo-modules/KeplerIdentifiersTM
- turbo-modules/KeplerIdentifiersTMWrapper
- turbo-modules/KeplerIdentifiersTMWrapper
- types/KeplerIdentifiersDataTypes
- types/KeplerIdentifiersDataTypes
Last updated: 2025年10月2日

