Author: h.mohri
毛利です。
C++Builderを使用してANDROID_IDとidentifierForVendor(IDFV)を取得を試してみました。
ID | Description |
---|---|
ANDROID_ID | ANDROID_IDは、Android端末の初期化時にランダムに生成された文字列です。 |
identifierForVendor(IDFV) | identifierForVendor(IDFV)は、iOS UDIDの代替としてiOS 6.0から使用できるIDです。 異なるベンダ(開発者)を持つアプリケーションでは、異なるIDが返されます。複数のアプリケーション間で同じ値を得ることができます。異なる端末で異なる値が返されることは保証されません。 |
uGetUuid.hpp
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<span class="cp" style="color:#999999;font-weight:bold;font-style:italic;">#if defined(_PLAT_IOS)</span> <span class="cp" style="color:#999999;font-weight:bold;font-style:italic;">#include</span> <span class="cpf"><Macapi.Helpers.hpp></span> <span class="cp" style="color:#999999;font-weight:bold;font-style:italic;">#include</span> <span class="cpf"><iOSapi.UIKit.hpp></span> <span class="cp" style="color:#999999;font-weight:bold;font-style:italic;">#elif defined(__ANDROID__)</span> <span class="cp" style="color:#999999;font-weight:bold;font-style:italic;">#include</span> <span class="cpf"><Androidapi.Helpers.hpp></span> <span class="cp" style="color:#999999;font-weight:bold;font-style:italic;">#include</span> <span class="cpf"><Androidapi.JNI.Provider.hpp></span> <span class="cp" style="color:#999999;font-weight:bold;font-style:italic;">#else</span> <span class="cp" style="color:#999999;font-weight:bold;font-style:italic;">#include</span> <span class="cpf"><IdIPWatch.hpp></span> <span class="cp" style="color:#999999;font-weight:bold;font-style:italic;">#endif</span> <span class="k" style="font-weight:bold;">struct</span> <span class="n">TGetUUID</span> <span class="p">{</span> <span class="k" style="font-weight:bold;">static</span> <span class="k" style="font-weight:bold;">const</span> <span class="n">UnicodeString</span> <span class="n">get_uuid</span><span class="p">();</span> <span class="p">};</span> |
uGetUuid.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<span class="k" style="font-weight:bold;">const</span> <span class="n">UnicodeString</span> <span class="n">TGetUUID</span><span class="o" style="font-weight:bold;">::</span><span class="n">get_uuid</span><span class="p">()</span> <span class="p">{</span> <span class="cp" style="color:#999999;font-weight:bold;font-style:italic;">#if defined(_PLAT_IOS)</span> <span class="n">_di_UIDevice</span> <span class="n">device_</span> <span class="o" style="font-weight:bold;">=</span> <span class="n">TUIDevice</span><span class="o" style="font-weight:bold;">::</span><span class="n">Wrap</span><span class="p">(</span><span class="n">TUIDevice</span><span class="o" style="font-weight:bold;">::</span><span class="n">OCClass</span><span class="o" style="font-weight:bold;">-></span><span class="n">currentDevice</span><span class="p">());</span> <span class="k" style="font-weight:bold;">return</span> <span class="nf" style="color:#990000;font-weight:bold;">NSStrToStr</span><span class="p">(</span><span class="n">device_</span><span class="o" style="font-weight:bold;">-></span><span class="n">identifierForVendor</span><span class="p">()</span><span class="o" style="font-weight:bold;">-></span><span class="n">UUIDString</span><span class="p">());</span> <span class="cp" style="color:#999999;font-weight:bold;font-style:italic;">#elif defined(__ANDROID__)</span> <span class="k" style="font-weight:bold;">using</span> <span class="k" style="font-weight:bold;">namespace</span> <span class="n">Androidapi</span><span class="o" style="font-weight:bold;">::</span><span class="n">Jni</span><span class="o" style="font-weight:bold;">::</span><span class="n">Provider</span><span class="p">;</span> <span class="k" style="font-weight:bold;">using</span> <span class="k" style="font-weight:bold;">namespace</span> <span class="n">Androidapi</span><span class="o" style="font-weight:bold;">::</span><span class="n">Helpers</span><span class="p">;</span> <span class="k" style="font-weight:bold;">return</span> <span class="nf" style="color:#990000;font-weight:bold;">JStringToString</span><span class="p">(</span> <span class="n">TJSettings_Secure</span><span class="o" style="font-weight:bold;">::</span><span class="n">JavaClass</span><span class="o" style="font-weight:bold;">-></span><span class="n">getString</span><span class="p">(</span> <span class="n">SharedActivity</span><span class="p">()</span><span class="o" style="font-weight:bold;">-></span><span class="n">getContentResolver</span><span class="p">(),</span> <span class="n">TJSettings_Secure</span><span class="o" style="font-weight:bold;">::</span><span class="n">JavaClass</span><span class="o" style="font-weight:bold;">-></span><span class="n">ANDROID_ID</span> <span class="p">));</span> <span class="cp" style="color:#999999;font-weight:bold;font-style:italic;">#else</span> <span class="cp" style="color:#999999;font-weight:bold;font-style:italic;">#endif</span> <span class="p">}</span> |
使い方
In the button click event, return ID to Edit1->Text.
Unit1.cpp
1 2 3 4 5 |
<span class="kt" style="color:#445588;font-weight:bold;">void</span> <span class="kr" style="font-weight:bold;">__fastcall</span> <span class="n">TForm1</span><span class="o" style="font-weight:bold;">::</span><span class="n">Button1Click</span><span class="p">(</span><span class="n">TObject</span> <span class="o" style="font-weight:bold;">*</span><span class="n">Sender</span><span class="p">)</span> <span class="p">{</span> <span class="n">Edit1</span><span class="o" style="font-weight:bold;">-></span><span class="n">Text</span> <span class="o" style="font-weight:bold;">=</span> <span class="n">TGetUUID</span><span class="o" style="font-weight:bold;">::</span><span class="n">get_uuid</span><span class="p">();</span> <span class="p">}</span> <span class="c1" style="color:#999988;font-style:italic;">//---------------------------------------------------------------------------</span> |
Delphiコードは、下記URL.
https://community.embarcadero.com/answers/device-information
Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition