# Imei of an android device

**URL:** <https://discourse.processing.org/t/imei-of-an-android-device/7579>\
**Category:** Processing for Android\
**Created:** [January 17, 2019, 7:14am UTC](https://discourse.processing.org/t/imei-of-an-android-device/7579 "2019-01-17T07:14:35Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![sonichel](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@sonichel](https://discourse.processing.org/u/sonichel)\
**Post date:** [January 17, 2019, 7:14am UTC](https://discourse.processing.org/t/imei-of-an-android-device/7579/1 "2019-01-17T07:14:35Z")

</div>

Dear library what do you recommend to get the imei of my android device, or any unique identifier of the device?

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [January 17, 2019, 9:02am UTC](https://discourse.processing.org/t/imei-of-an-android-device/7579/2 "2019-01-17T09:02:01Z")

</div>

@sonichel===

see here : [https://developer.android.com/reference/android/telephony/TelephonyManager#getImei(int)](https://developer.android.com/reference/android/telephony/TelephonyManager#getImei(int))

---

<div class="post-metadata">

**Author:** ![sonichel](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@sonichel](https://discourse.processing.org/u/sonichel)\
**Post date:** [January 17, 2019, 7:41pm UTC](https://discourse.processing.org/t/imei-of-an-android-device/7579/3 "2019-01-17T19:41:23Z")

</div>

Thx akenaton. I am new in processing and I am learning to program, regarding the link that you sent me that library should use to obtain the imei?

---

<div class="post-metadata">

**Author:** ![sonichel](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@sonichel](https://discourse.processing.org/u/sonichel)\
**Post date:** [January 17, 2019, 8:17pm UTC](https://discourse.processing.org/t/imei-of-an-android-device/7579/4 "2019-01-17T20:17:35Z")

</div>

String IMEI;

void start(){  
IMEI = getImei ();  
println(IMEI);  
}

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [January 20, 2019, 10:47am UTC](https://discourse.processing.org/t/imei-of-an-android-device/7579/5 "2019-01-20T10:47:26Z")

</div>

@sonichel===

not so simple ! - You have to import TelephonyManager for that : code snippet below

```auto
import android.os.Build;
import android.content.Context;
import android.telephony.TelephonyManager;
Context ctx;
public String IME="";
public String SN="";

void setup(){
  size(800,600);
  background(255,0,0);
  ctx = this.getActivity().getApplicationContext();
  IME= getIme();
  
}

void draw(){
  background(255,0,0);
  textSize(18);
  text("IME=====" + IME, 100,200);
  text ("SERIAL NUMBER====="+ SN, 100,500);
}

public String getIme(){
TelephonyManager tm;
tm=(TelephonyManager)this.getActivity().getSystemService(ctx.TELEPHONY_SERVICE);  
//String imei = tm.getImei();///FOR DEVICES >>26//uncomment if your device is in this case

SN = Build.SERIAL;///for all devices

String IM=tm.getDeviceId(); ////for devices <<26,now deprecated; comment if your OS device is more recent
  
return IM;
}

```

---

<div class="post-metadata">

**Author:** ![sonichel](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@sonichel](https://discourse.processing.org/u/sonichel)\
**Post date:** [January 20, 2019, 1:47pm UTC](https://discourse.processing.org/t/imei-of-an-android-device/7579/6 "2019-01-20T13:47:08Z")

</div>

![33](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/ddbaa24d254251f3c27e16a6aaab607e8d8775de.png) ![26](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/4a1918a6b8efe9610d38ac4dfdb87d84c1d67a4c.png)

Apparently serial is obsolete …

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [January 20, 2019, 1:55pm UTC](https://discourse.processing.org/t/imei-of-an-android-device/7579/7 "2019-01-20T13:55:27Z")

</div>

@sonichel===  
deprecated for \>=oreo: in this case use `Build.getSerial()`  
Yet this code has to work (as for the other warning you can get easily rid of it creating some static method)

---

<div class="post-metadata">

**Author:** ![sonichel](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@sonichel](https://discourse.processing.org/u/sonichel)\
**Post date:** [January 20, 2019, 2:03pm UTC](https://discourse.processing.org/t/imei-of-an-android-device/7579/8 "2019-01-20T14:03:48Z")

</div>

great now it seems to work getSerial … but it throws me this error … and in the android tablet says “the IMEI application has stopped working”

 ![41](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/e43fcb26281806ffa93636a254b4bec1b47fd267.png)

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [January 20, 2019, 2:05pm UTC](https://discourse.processing.org/t/imei-of-an-android-device/7579/9 "2019-01-20T14:05:57Z")

</div>

@sonichel===  
add “READ\_PHONE\_STATE” permission to your sketch on runtime

---

<div class="post-metadata">

**Author:** ![sonichel](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@sonichel](https://discourse.processing.org/u/sonichel)\
**Post date:** [January 20, 2019, 2:09pm UTC](https://discourse.processing.org/t/imei-of-an-android-device/7579/10 "2019-01-20T14:09:31Z")

</div>

if I realized that you had to give that permission, but the fault persists … look

 ![07](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a4c97204d97fc045c1ab97201c6d7677b063fb31.png)

---

<div class="post-metadata">

**Author:** ![sonichel](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@sonichel](https://discourse.processing.org/u/sonichel)\
**Post date:** [January 20, 2019, 2:13pm UTC](https://discourse.processing.org/t/imei-of-an-android-device/7579/11 "2019-01-20T14:13:59Z")

</div>

friend, look, I reduced the sketch to this and it still fails…

 ![04](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/c8c8db3b3a20d96815a5bcc142baaa6c69447b17.png)

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [January 20, 2019, 2:55pm UTC](https://discourse.processing.org/t/imei-of-an-android-device/7579/12 "2019-01-20T14:55:00Z")

</div>

@sonichel===

- we cannot read your error, dont put a picture, cut & copy
- yet probably this error is fired because you dont ak the permission on runtime: after Mashmallow “pernicious” permissions cannot be set only adding them to the Manifest.

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [January 20, 2019, 2:57pm UTC](https://discourse.processing.org/t/imei-of-an-android-device/7579/13 "2019-01-20T14:57:23Z")

</div>

@sonichel==== dont change the code, the error you get now is another one!!!

---

<div class="post-metadata">

**Author:** ![sonichel](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@sonichel](https://discourse.processing.org/u/sonichel)\
**Post date:** [January 20, 2019, 6:14pm UTC](https://discourse.processing.org/t/imei-of-an-android-device/7579/14 "2019-01-20T18:14:16Z")

</div>

ok, I went back to how I should be … I enabled the permission “READ\_PHONE\_STATE” and in ctx.TELEPHONY\_SERVICE appears "The static field Context.TELEPHONY\_SERVICE should be accessed in a static way… and on line 30 String IM = tm.getDeviceId (); it indicates me “The method getDeviceId() from the type TelephonyManager is deprecated”.

when compiling I throw the following:

Build folder: /var/folders/\_c/z2br0db57y560\_mkrc58\_d100000gn/T/android1206249006627969043sketch  
:app:preBuild UP-TO-DATE  
:app:preDebugBuild  
:app:compileDebugAidl  
:app:compileDebugRenderscript  
:app:checkDebugManifest  
:app:generateDebugBuildConfig  
:app:prepareLintJar  
:app:generateDebugResValues  
:app:generateDebugResources  
:app:mergeDebugResources  
:app:createDebugCompatibleScreenManifests  
:app:processDebugManifest  
:app:splitsDiscoveryTaskDebug  
:app:processDebugResources  
:app:generateDebugSources  
:app:javaPreCompileDebug  
:app:compileDebugJavaWithJavac  
:app:compileDebugNdk NO-SOURCE  
:app:compileDebugSources  
:app:mergeDebugShaders  
:app:compileDebugShaders  
:app:generateDebugAssets  
:app:mergeDebugAssets  
:app:extractTryWithResourcesSupportJarDebug  
:app:transformClassesWithStackFramesFixerForDebug  
:app:transformClassesWithDesugarForDebug  
:app:transformClassesWithDexBuilderForDebug  
:app:transformDexArchiveWithExternalLibsDexMergerForDebug  
:app:transformDexArchiveWithDexMergerForDebug  
:app:mergeDebugJniLibFolders  
:app:transformNativeLibsWithMergeJniLibsForDebug  
:app:processDebugJavaRes NO-SOURCE  
:app:transformResourcesWithMergeJavaResForDebug  
:app:validateSigningDebug  
:app:packageDebug  
:app:assembleDebug

BUILD SUCCESSFUL in 28s  
28 actionable tasks: 28 executed  
FATAL EXCEPTION: Animation Thread  
Process: processing.test.sketch\_190120b, PID: 8388  
java.lang.SecurityException: getImeiForSlot: Neither user 10074 nor current process has android.permission.READ\_PHONE\_STATE.  
at android.os.Parcel.readException(Parcel.java:1684)  
at android.os.Parcel.readException(Parcel.java:1637)  
at com.android.internal.telephony.ITelephony$Stub$Proxy.getImeiForSlot(ITelephony.java:4481)  
at android.telephony.TelephonyManager.getImei(TelephonyManager.java:904)  
at android.telephony.TelephonyManager.getImei(TelephonyManager.java:887)  
at processing.test.sketch\_190120b.sketch\_190120b.getIme(sketch\_190120b.java:48)  
at processing.test.sketch\_190120b.sketch\_190120b.setup(sketch\_190120b.java:34)  
at processing.core.PApplet.handleDraw(PApplet.java:1838)  
at processing.core.PSurfaceNone.callDraw(PSurfaceNone.java:476)  
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:516)  
FATAL EXCEPTION: Animation Thread  
Process: processing.test.sketch\_190120b, PID: 8416  
java.lang.SecurityException: getImeiForSlot: Neither user 10074 nor current process has android.permission.READ\_PHONE\_STATE.  
at android.os.Parcel.readException(Parcel.java:1684)  
at android.os.Parcel.readException(Parcel.java:1637)  
at com.android.internal.telephony.ITelephony$Stub$Proxy.getImeiForSlot(ITelephony.java:4481)  
at android.telephony.TelephonyManager.getImei(TelephonyManager.java:904)  
at android.telephony.TelephonyManager.getImei(TelephonyManager.java:887)  
at processing.test.sketch\_190120b.sketch\_190120b.getIme(sketch\_190120b.java:48)  
at processing.test.sketch\_190120b.sketch\_190120b.setup(sketch\_190120b.java:34)  
at processing.core.PApplet.handleDraw(PApplet.java:1838)  
at processing.core.PSurfaceNone.callDraw(PSurfaceNone.java:476)  
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:516)

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [January 20, 2019, 6:55pm UTC](https://discourse.processing.org/t/imei-of-an-android-device/7579/15 "2019-01-20T18:55:21Z")

</div>

@sonichel===  
i have already explained that you have to get this permission on runtime and i think you have not asked for it: manifest has no sense in this type of cas (“dangerous permissions”) since Mashmallow…  
deprecated has not any importance with android.

---

<div class="post-metadata">

**Author:** ![sonichel](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@sonichel](https://discourse.processing.org/u/sonichel)\
**Post date:** [January 20, 2019, 7:00pm UTC](https://discourse.processing.org/t/imei-of-an-android-device/7579/16 "2019-01-20T19:00:01Z")

</div>

> [@akenaton](#):
>
> “dangerous permissions”

where do I give permission to “dangerous permissions” ??? should I declare it in the sketch setup or in the Sketch Permissions menu?

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [January 21, 2019, 8:19am UTC](https://discourse.processing.org/t/imei-of-an-android-device/7579/18 "2019-01-21T08:19:00Z")

</div>

@sonichel===  
see here=  
[https://android.processing.org/reference/permissions/request.html](https://android.processing.org/reference/permissions/request.html)
