2

I would try to get the imei of a device in C/C++ (using ndk) and retrieve the result with JNI.

const char *res = exec_get_out("service call iphonesubinfo 3");

Works in shell, but does not in my application

I have the READ_PHONE_STATE permission set in the Manifest. This is targeted for Marshmallow Android (and I have accepted permission in settings)

Is there any other solution that would work or is it not possible without a JNI environment?

Stuart Siegler
  • 1,686
  • 4
  • 30
  • 38
sakdoss
  • 21
  • 1
  • 2

1 Answers1

1

check this and this

#include <sys/system_properties.h>

    //returns the string length of the value.
    int ir = __system_property_get("ro.gsm.imei", imei_start);           

      if(ir > 0)
    {
      imei_start[15]=0;//strz end      
      printf("method1 got imei %s len %d\r\n",imei_start,strlen(imei_start));
      strcpy(g_imei,imei_start);
    }
      else
    {
      printf("method1 imei failed - trying method2\r\n");
      //old dumpsys imei getter
      char* res = exec_get_out("dumpsys iphonesubinfo");  
      const char* imei_start_match = "ID = ";
      int imei_start_match_len = strlen(imei_start_match);
      char* imei_start = strstr(res,imei_start_match);
      if(imei_start && strlen(imei_start)>=15+imei_start_match_len)
        {
          imei_start += imei_start_match_len;
          imei_start[15] = 0;
          printf("method2 IMEI [%s] len %d\r\n",imei_start,strlen(imei_start));
          strcpy(g_imei,imei_start);
        }
    }      
Community
  • 1
  • 1
Behrouz.M
  • 3,445
  • 6
  • 37
  • 64