Device Information

0

Dear Friends

 

Is there any component or source code for getting system informations from device ?

- UUID, DeviceType/Version, OS Version, WIFI, PhoneNumber, DiskInfo, etc details and id datas from device

Responses (4)
  • Accepted Answer

    Monday, October 19 2015, 06:37 AM - #Permalink
    0

    Thanks Jayden for pointing that out.

    I guess this code will then work to get device id:

     

    Android:

    uses
    
      Androidapi.Helpers, Androidapi.JNI.Provider,
    
    function GetDeviceId: string;
    
    begin
    
      Result := JStringToString(TJSettings_SECURE.JavaClass.getString(SharedActivity.getContentResolver, TJSettings_SECURE.JavaClass.ANDROID_ID));
    
    end;



    iOS:

    uses
    
      Macapi.Helpers, iOSapi.UIKit,
    
    
    
    function GetDeviceId: string;
    
    var
    
      Device : UIDevice;
    
    begin
    
      Device := TUIDevice.Wrap(TUIDevice.OCClass.currentDevice);
    
      Result := NSStrToStr(Device.identifierForVendor.UUIDString);
    
    end;



     

    The reply is currently minimized Show
  • Accepted Answer

    Monday, October 19 2015, 04:42 AM - #Permalink
    0

    Robert,

    This has been widely available on Android since its release. See:

    https://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID

    This can be accessed from the TJSettings_Secure JavaClass property ANDROID_ID - believe the bridging interfaces are in Android.JNI.App or .OS

     

    Jayden

    The reply is currently minimized Show
  • Accepted Answer

    Sunday, October 18 2015, 01:39 PM - #Permalink
    0

    Hi, you may have a look in the DeviceInfo demo project, it is part of your Delphi/C++ Builder installation. It gives examples how to get device type and OS version for both iOS and Android.

    Regarding telephone number, please notice that this will not be always available. In most countries this is not stored on the telephone sim, but resolved at the telephone exchange during the calll (so outside the device).

    Regarding UUID, as far as I know, this is not available on Android, only on iOS.

     

    The reply is currently minimized Show
  • Accepted Answer

    Sunday, October 18 2015, 10:49 AM - #Permalink
    0

    Hi,

    This really depends on the platform you are using. For iOS & Android there are standardised methods to get the device UUID whereas for OS X one will need to generate and store a UUID to the NSUserDefaults. I have not tried this on Windows so cannot provide guidance there.

    On iOS since you're app is Sandboxed there isn't an easy way to get WiFi & Storage info nor the phone number, hence most iOS apps that use your phone number request that you verify it by SMS. Im not sure on Android, but a simple Google search will throw up results.

    In order to access information that is provided by an iOS/OS X/Android library you will need to bridge into it, for this I recommend you view Brian Long's videos on the topic at the following links:

    Below is an example which will get a UUID from an iOS Device and store it in NSUserDefaults to explain the functionality of both the frameworks. In order to use these frameworks we are including the following Units:

    • FMX.Platform.iOS (For Logging)
    • iOSapi.Foundation (For NSUserDefaults)
    • iOSapi.UIKit (For UIDevice to get UUID)

    To view the Object Pascal units look in \Source\rtl\ios or for C++ \include\ios\rtl 

            String manufacturer = "APPLE";
    	String device = NSStrToStr(TUIDevice::Wrap(TUIDevice::OCClass->currentDevice())->model());
    	String deviceUUID;
    
    	_di_NSUserDefaults userDefaults;
    	_di_NSData archivedUUID;
    	_di_NSUUID uuid;
    	void * unarchivedUUID;
    	String finalString;
    
    	__try
    	{
    		userDefaults = TNSUserDefaults::Alloc();
    		userDefaults = TNSUserDefaults::Wrap(TNSUserDefaults::OCClass->standardUserDefaults());
    
    		archivedUUID = TNSData::Wrap(userDefaults->objectForKey(StrToNSStr("DeviceUUID")));
    		unarchivedUUID = TNSKeyedUnarchiver::OCClass->unarchiveObjectWithData(archivedUUID);
    		uuid = TNSUUID::Wrap(unarchivedUUID);
    	}
    	__finally
    	{
    		finalString = NSStrToStr(uuid->UUIDString());
    		uuid->release();
    		archivedUUID->release();
    	}
    
    	if(finalString.Length() < 1)
    	{
    		_di_UIDevice device;
    		_di_NSUUID nsuuid;
    		_di_NSData data;
    		void * ptrUUID;
    		void * dataPtr;
    
    		device = TUIDevice::Wrap(TUIDevice::OCClass->currentDevice());
    		nsuuid = device->identifierForVendor();
    		deviceUUID = UTF8ToString(nsuuid->UUIDString()->UTF8String());
    
    		__try
    		{
    			ptrUUID = ((_di_ILocalObject)nsuuid)->GetObjectID();
    			data = TNSKeyedArchiver::OCClass->archivedDataWithRootObject(ptrUUID);
    			dataPtr = ((_di_ILocalObject)data)->GetObjectID();
    
    			userDefaults->setObject(dataPtr, StrToNSStr("VMUUID"));
    		}
    		__finally
    		{
    			data->release();
    			nsuuid->release();
    			device->release();
    		}
    
    		if(userDefaults->synchronize())
    		{
    			Log::d("User Defaults Synchronised. UUID is now: " + deviceUUID);
    			userDefaults->release();
    		}
    		else
    			Log::d("User Default Sync Failed"); 
    	}
    	else
    	{
    		deviceUUID = finalString;
    		Log::d("We Already Have Stored A UUID Of: " + deviceUUID);
    	}

    I havn't tested this but it should work - let me know if you have any questions.

    The reply is currently minimized Show
Your Reply

Please login to post a reply