1

I'm looking a way to get current device's serial number in my integration tests.

Now, when calling

TelephonyManager manager = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
String deviceId = manager.getDeviceId();

in my test method, I get java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10227 nor current process has android.permission.READ_PHONE_STATE.

I added <uses-permission android:name="android.permission.READ_PHONE_STATE"/> in my test project AndroidManifest.xml, but that did not helped.

Martynas Jurkus
  • 9,231
  • 13
  • 59
  • 101

1 Answers1

2

You should check whether Read_Phone_State permission is added in your application's AndroidManifest.xml or not.

like This::

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>  

If it is not there please add it, because your testcase can not have more privilege than your application.

King of Masses
  • 18,405
  • 4
  • 60
  • 77
kamal_prd
  • 543
  • 4
  • 16
  • 1
    Then it is not possible to access current device's serial number in testcase. Because, your **testcase can not have more privilege than your application**. – kamal_prd Aug 13 '13 at 11:37
  • After adding above line, still i am getting an issue how to resolve it – karthik pamidimarri Feb 11 '15 at 17:45
  • @karthikpamidimarri have you checked if the permission is present in both the Manifest files (main application as well as test application) – kamal_prd Feb 13 '15 at 05:59
  • I also faced same issue with permission. Finally, For development I hard coded the String deviceId. But for Production I used getDeviceId(); It is working in simulator. – Thirumalvalavan Oct 21 '15 at 12:29