Android Question google service framework id (how to get it?)

pliroforikos

Active Member
Licensed User
Hello everyone
I'm trying to figure how to get gsf id key . I tried this method and writed it as shown bellow.

B4XmainPage:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

#If JAVA
public String getGsfAndroidId(Context context)
{
    Uri URI = Uri.parse("content://com.google.android.gsf.gservices");
    String ID_KEY = "android_id";
    String params[] = {ID_KEY};
    Cursor c = context.getContentResolver().query(URI, null, null, params, null);
    if (!c.moveToFirst() || c.getColumnCount() < 2)
        return null;
    try
    {
        return Long.toHexString(Long.parseLong(c.getString(1)));
    }
    catch (NumberFormatException e)
    {
        return null;
    }
}
#End If

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
End Sub

Public Sub Initialize
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

Sub Button1_Click
    xui.MsgboxAsync(getGsf, "B4X")
End Sub

Private Sub getGsf As String
    Dim jo As JavaObject = Me
    Dim str As String = jo.RunMethod("getGsfAndroidId", Null)
    Return str
End Sub

but i am getting an error :
cannot find symbol
public String getGsfAndroidId(Context context)

B4A Version: 10.2
Java Version: 11
Parsing code. (0.05s)
Building folders structure. (0.03s)
Running custom action. (0.06s)
Compiling code. (0.21s)
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
(AndroidX SDK)
Generating R file. (0.00s)
Compiling debugger engine code. (0.01s)
Compiling generated Java code. Error
B4A line: 35
End Sub
src\gb4x\gsfid\b4xmainpage.java:121: error: cannot find symbol
public String getGsfAndroidId(Context context)
^
symbol: class Context
location: class b4xmainpage
1 error

I also put this <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> at manifest

Any ideas please?
 

Attachments

  • Project.zip
    13.8 KB · Views: 212

pataridis

Member
Licensed User
Android_id is totally different. There is a known bug for Android_ID with a popular handset from a manufacturer where every instance have the same ANDROID_ID. Clearly, the solution is not 100% reliable.
Google Service Framework ID (GSF ID) on the other hand is totally unique and it changes only on hard reset. You can't move it or backup it, to another device (or even to the same device) if you hard reset it.
So, i want it too!
How to get it from Β4Α?

Thanx
 
Upvote 0

pliroforikos

Active Member
Licensed User
Finaly after a lot of research i found EasyDeviceInfo (with inline Java Code) and made a lib with Simple Library Compiler tool.

i have a little java knowledge so maybe it doesnt work with all methods. I've checked gsfID and it works.
For gsfID we need to declare in manifest:
B4X:
 <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />)

I don't know what kind of permissions needs the other methods... :p

And of course we need JavaObject library to be selected.
 

Attachments

  • gsfLib.zip
    1.5 KB · Views: 261
Upvote 0
Top