「Xamarin.AndroidでUUIDを生成取得する」を編集中
ナビゲーションに移動
検索に移動
この編集を取り消せます。 下記の差分を確認して、本当に取り消していいか検証してください。よろしければ変更を保存して取り消しを完了してください。
最新版 | 編集中の文章 | ||
3行目: | 3行目: | ||
[[リセマラ]]対応[[ゲーム]]などを作るときはこれ。 | [[リセマラ]]対応[[ゲーム]]などを作るときはこれ。 | ||
− | <source | + | <source> |
− | public class Installation | + | public class Installation |
− | { | + | { |
− | + | public static string _uuid; | |
− | + | public const string INSTALLATION = "INSTALLATION"; | |
− | + | public static string GetUUID(Context context) | |
− | |||
− | |||
{ | { | ||
− | + | if (_uuid == null) | |
− | if ( | ||
{ | { | ||
− | _uuid = | + | var installationFilePath = Path.Combine(context.FilesDir.AbsolutePath, INSTALLATION); |
− | + | if (!File.Exists(installationFilePath)) | |
+ | { | ||
+ | _uuid = Java.Util.UUID.RandomUUID().ToString(); | ||
+ | File.WriteAllText(installationFilePath, _uuid); | ||
+ | } | ||
+ | _uuid = File.ReadAllText(installationFilePath); | ||
} | } | ||
− | _uuid | + | return _uuid; |
} | } | ||
− | |||
} | } | ||
− | |||
</source> | </source> | ||