How can I get the identifier of the Android device that I get when dialing the number "* # * # 8255 # * # *"

How can I get the identifier of the Android device that I am dialing * # * # 8 2 5 5 # * # *

I use the following code, but it does not return the same ... what I want

String android_id = Secure.getString(getActivity() .getContentResolver(), Secure.ANDROID_ID); 

enter image description here

+4
source share
1 answer

I think the code you tried probably returns a dynamic id. Try it.

private static final Uri URI = Uri.parse ("content: //com.google.android.gsf.gservices"); private static final String ID_KEY = "android_id";

  String getAndroidId(Context ctx) { String[] params = { ID_KEY }; Cursor c = ctx.getContentResolver() .query(URI, null, null, params, null); try{ if (!c.moveToFirst() || c.getColumnCount() < 2){ return null; } }catch(Exception e){ return null; } try { Toast.makeText(ctx, Long.toHexString(Long.parseLong(c.getString(1))), 500).show(); System.out.println("android id " + Long.toHexString(Long.parseLong(c.getString(1)))); return Long.toHexString(Long.parseLong(c.getString(1))); } catch (NumberFormatException e) { return null; } } 

In the above code, Long.toHexString (Long.parseLong (c.getString (1))) returns the identifier of the Android device.

+5
source

Source: https://habr.com/ru/post/1480886/


All Articles