Geo*_*mas 1

尝试这样

import android.content.Context;
import android.provider.Settings.Secure;

public class sample {


    public String getId(Context c)
    {

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

         return android_id;
    }
}
Run Code Online (Sandbox Code Playgroud)

传递您的活动的上下文

sample s=new sample();

    String udid=s.getId(getApplicationContext());
    Toast.makeText(getApplicationContext(), udid, Toast.LENGTH_LONG).show();
Run Code Online (Sandbox Code Playgroud)