Jump to content
Turan Can

Android hdd serial number

Recommended Posts

Hi,

Windows hdd serial number function It works very successfully.

Is there an example for Android?

 

function GetHardDiskSerial(const DriveLetter: Char): string;

var
  NotUsed, VolumeFlags, VolumeSerialNumber: DWORD;
  VolumeInfo: array [0 .. MAX_PATH] of Char;
begin
  ZeroMemory(@VolumeInfo, SizeOf(VolumeInfo));
  GetVolumeInformation(PChar(DriveLetter + ':\'), nil, SizeOf(VolumeInfo), @VolumeSerialNumber, NotUsed, VolumeFlags, nil, 0);
  Result := Format('%8.8X', [VolumeSerialNumber]);
end;

 

"android.os.SystemProperties"

 

Share this post


Link to post
1 hour ago, Kryvich said:

Have you obtain an Android phone with HDD? )

I'm assuming he means any file-based media that it can access.

9 hours ago, Turan Can said:

Is there an example for Android?

This may be of use to you:

uses
  Androidapi.JNI.JavaTypes, Androidapi.JNIBridge, Androidapi.JNI.Os, Androidapi.JNI.GraphicsContentViewText, Androidapi.Helpers;

type
  JStorageManager = interface;
  JStorageVolume = interface;

  JStorageManagerClass = interface(JObjectClass)
    ['{0F83E5E0-9AE5-41F8-9FA1-E91CABBC6720}']
    function _GetACTION_MANAGE_STORAGE: JString; cdecl;
    function _GetEXTRA_REQUESTED_BYTES: JString; cdecl;
    function _GetEXTRA_UUID: JString; cdecl;
    function _GetUUID_DEFAULT: JUUID; cdecl;
    property ACTION_MANAGE_STORAGE: JString read _GetACTION_MANAGE_STORAGE;
    property EXTRA_REQUESTED_BYTES: JString read _GetEXTRA_REQUESTED_BYTES;
    property EXTRA_UUID: JString read _GetEXTRA_UUID;
    property UUID_DEFAULT: JUUID read _GetUUID_DEFAULT;
  end;

  [JavaSignature('android/os/storage/StorageManager')]
  JStorageManager = interface(JObject)
    ['{A7190FB5-1DBE-4A4E-8A21-A6215C00243C}']
    function getAllocatableBytes(storageUuid: JUUID): Int64; cdecl;
    function getCacheQuotaBytes(storageUuid: JUUID): Int64; cdecl;
    function getCacheSizeBytes(storageUuid: JUUID): Int64; cdecl;
    function getMountedObbPath(rawPath: JString): JString; cdecl;
    function getPrimaryStorageVolume: JStorageVolume; cdecl;
    function getStorageVolume(&file: JFile): JStorageVolume; cdecl;
    function getStorageVolumes: JList; cdecl;
    function getUuidForPath(path: JFile): JUUID; cdecl;
    function isAllocationSupported(fd: JFileDescriptor): boolean; cdecl;
    function isCacheBehaviorGroup(path: JFile): boolean; cdecl;
    function isCacheBehaviorTombstone(path: JFile): boolean; cdecl;
    function isEncrypted(&file: JFile): boolean; cdecl;
    function isObbMounted(rawPath: JString): boolean; cdecl;
    function mountObb(rawPath: JString; key: JString; listener: JOnObbStateChangeListener): boolean; cdecl;
    // function openProxyFileDescriptor(mode : Integer; callback : JProxyFileDescriptorCallback; handler : JHandler) : JParcelFileDescriptor; cdecl;
    function unmountObb(rawPath: JString; force: boolean; listener: JOnObbStateChangeListener): boolean; cdecl;
    procedure allocateBytes(fd: JFileDescriptor; bytes: Int64); cdecl; overload;
    procedure allocateBytes(storageUuid: JUUID; bytes: Int64); cdecl; overload;
    procedure setCacheBehaviorGroup(path: JFile; group: boolean); cdecl;
    procedure setCacheBehaviorTombstone(path: JFile; tombstone: boolean); cdecl;
  end;

  TJStorageManager = class(TJavaGenericImport<JStorageManagerClass, JStorageManager>)
  end;

  JStorageVolumeClass = interface(JObjectClass)
    ['{C11D1D2A-77D0-4D1A-B4B9-5042B60BADB0}']
    function _GetCREATOR: JParcelable_Creator; cdecl;
    function _GetEXTRA_STORAGE_VOLUME: JString; cdecl;
    property CREATOR: JParcelable_Creator read _GetCREATOR;
    property EXTRA_STORAGE_VOLUME: JString read _GetEXTRA_STORAGE_VOLUME;
  end;

  [JavaSignature('android/os/storage/StorageVolume')]
  JStorageVolume = interface(JObject)
    ['{F6555252-D4E1-405B-BAAB-2C8F59A01F41}']
    function createAccessIntent(directoryName: JString): JIntent; cdecl;
    function describeContents: Integer; cdecl;
    function equals(obj: JObject): boolean; cdecl;
    function getDescription(context: JContext): JString; cdecl;
    function getState: JString; cdecl;
    function getUuid: JString; cdecl;
    function hashCode: Integer; cdecl;
    function isEmulated: boolean; cdecl;
    function isPrimary: boolean; cdecl;
    function isRemovable: boolean; cdecl;
    function toString: JString; cdecl;
    procedure writeToParcel(parcel: JParcel; flags: Integer); cdecl;
  end;
  TJStorageVolume = class(TJavaGenericImport<JStorageVolumeClass, JStorageVolume>)
  end;

procedure TForm1.Button1Click(Sender: TObject);
var
  LService: JObject;
  LStorageManager: JStorageManager;
  LVolumes: JList;
  LVolume: JStorageVolume;
  I: Integer;
begin
  LService := TAndroidHelper.Activity.getSystemService(TJContext.JavaClass.STORAGE_SERVICE);
  LStorageManager := TJStorageManager.Wrap(TAndroidHelper.JObjectToID(LService));
  LVolumes := LStorageManager.getStorageVolumes;
  for I := 0 to LVolumes.size - 1 do
  begin
    LVolume := TJStorageVolume.Wrap(LVolumes.get(I));
    Memo1.Lines.Add(Format('%s (%s)', [JStringToString(LVolume.getDescription(TAndroidHelper.Context)), JStringToString(LVolume.getUuid)]));
  end;
end;

 

  • Like 1
  • Thanks 1

Share this post


Link to post

Hello Dave,

 

Thanks for the example.

However, this only takes external hdd cards..

 

Should I give my uses permission authorization?

 

Is there a ready helper in Delphi android where we can get the class structure like this?

 

https://developer.android.com/reference/android/os/storage/StorageManager

 

c# xamarin

public static String getSerialNumber() {
    String serialNumber;

    try {
        Class<?> c = Class.forName("android.os.SystemProperties");
        Method get = c.getMethod("get", String.class);

        serialNumber = (String) get.invoke(c, "gsm.sn1");
        if (serialNumber.equals(""))
            serialNumber = (String) get.invoke(c, "ril.serialnumber");
        if (serialNumber.equals(""))
            serialNumber = (String) get.invoke(c, "ro.serialno");
        if (serialNumber.equals(""))
            serialNumber = (String) get.invoke(c, "sys.serialnumber");
        if (serialNumber.equals(""))
            serialNumber = Build.SERIAL;

        // If none of the methods above worked
        if (serialNumber.equals(""))
            serialNumber = null;
    } catch (Exception e) {
        e.printStackTrace();
        serialNumber = null;
    }

    return serialNumber;
}

 

uses.jpg

Share this post


Link to post
1 hour ago, Turan Can said:

android.os.SystemProperties

If there's a class called that, it's undocumented.

 

If you're after a unique id for the device, you're probably better off using something like this:

uses
  Androidapi.JNI.Provider, Androidapi.Helpers;

// **** NOTE: Use this value with care, as it is reset if the device is rooted, or wiped
function GetUniqueDeviceID: string;
var
  LName: JString;
begin
  LName := TJSettings_Secure.JavaClass.ANDROID_ID;
  Result := JStringToString(TJSettings_Secure.JavaClass.getString(TAndroidHelper.ContentResolver, LName));
end;

 

Share this post


Link to post

Thank you so much. It meets my need.

 

I wonder. Android is ultimately held in memory. Doesn't this memory have a serial number?

 

As far as I understand. if the user has root authority. it can change the imei numbers including androidid that you sent last.
I need something like the unique identification key of the device or borad.

Edited by Turan Can

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×