Android get GSF ID (Google Services Framework Identifier)
The Google Services Framework Identifier (GSF ID) is a unique 16 character hexadecimal number that your device automatically requests from Google as soon as you log to your Google Account for the first time. For a specific device, the GSF ID will change only after a factory reset. To get this information programmatically, you need to do two steps.
A) Add the following to your manifest
1 | < uses-permission android:name = "com.google.android.providers.gsf.permission.READ_GSERVICES" /> |
B) Execute the following code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | private static final Uri sUri = Uri.parse( "content://com.google.android.gsf.gservices" ); public static String getGSFID(Context context) { try { Cursor query = context.getContentResolver().query(sUri, null , null , new String[] { "android_id" }, null ); if (query == null ) { return "Not found" ; } if (!query.moveToFirst() || query.getColumnCount() < 2 ) { query.close(); return "Not found" ; } final String toHexString = Long.toHexString(Long.parseLong(query.getString( 1 ))); query.close(); return toHexString.toUpperCase().trim(); } catch (SecurityException e) { e.printStackTrace(); return null ; } catch (Exception e2) { e2.printStackTrace(); return null ; } } |