I can't using the following method because my class doesn't extends the Activity class: Is there a unique Android device ID?
Asked
Active
Viewed 1,517 times
5
-
1pass the context object to the method. – Blackbelt Jun 19 '14 at 12:15
-
Make your class Member object static . Then You can use like `Class.member` will work. – Shabbir Dhangot Jun 19 '14 at 12:17
-
Take a look at these questions -> http://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id http://stackoverflow.com/questions/16078269/android-unique-serial-number/16929647#16929647 – faraway Jun 19 '14 at 12:48
-
Thanks for all answers, But because I didn't using the activity class, I cant access to the context object. I do instrumentation to another apk and this is the reason that I cant use the activity class. All your solutions deals using with the Activity class (directly or indirectly) – Rotem E Jun 19 '14 at 13:37
-
...send the Context in a constructor parameter – EpicPandaForce Jun 19 '14 at 14:02
2 Answers
1
Try like this
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;
}
}
pass the context from your activity
sample s=new sample();
String udid=s.getId(getApplicationContext());
Toast.makeText(getApplicationContext(), udid, Toast.LENGTH_LONG).show();

George Thomas
- 4,566
- 5
- 30
- 65
-
Thanks for the answer, But because I didn't using the activity class, I cant access to the context object. I do instrumentation to another apk and this is the reason that I cant use the activity class. – Rotem E Jun 19 '14 at 12:39
0
Try like this
public class Sample {
public static String getId(Context c)
{
String android_id = Secure.getString(c.getContentResolver(),
Secure.ANDROID_ID);
return android_id;
}
}
when you need the device id
String id = Sample.getId(youractivity.this);// if ur in an activity
or try this
String id =Sample.getId(getApplicationContext());

Nithinlal
- 4,845
- 1
- 29
- 40