应用程序在获取IMEI号时停止

时间:2013-12-20 07:47:54

标签: android

我正在尝试获取Android设备的IMEI号,但是当我调用此方法应用程序停止并且设备说应用程序停止不幸

这是方法

 public void startService(View view) 
{
    startService(new Intent(getBaseContext(), MyService.class));
    TextView tv = (TextView) findViewById(R.id.textView1);
    tv.setText("Started");
    TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    String S =telephonyManager.getDeviceId();
    TextView tv1 = (TextView) findViewById(R.id.textView4);
    tv1.setText(S);
}

清单文件:

      <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.app"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="15" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.app.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name=".MyService" />
        <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    </application>

</manifest>

logcat的:

完整的logCat

    12-20 14:07:41.548      229-263/? D/InputReader﹕ AP_PROF:AppLaunch_dispatchPtr:Down:648835
12-20 14:07:41.549      229-262/? I/InputDispatcher﹕ dispatchEventToCurrentInputTargets - resumeWithAppendedMotionSample=false
12-20 14:07:41.549      229-262/? I/InputDispatcher﹕ channel '4196cc98  (server)' ~ prepareDispatchCycle - flags=0x00000208, xOffset=-144.000000, yOffset=-3.000000, scaleFactor=1.000000, pointerIds=0x0, resumeWithAppendedMotionSample=false
12-20 14:07:41.549      229-262/? I/InputDispatcher﹕ channel '4196cc98  (server)' ~ startDispatchCycle
12-20 14:07:41.549      229-262/? I/InputDispatcher﹕ channel '418ea098 com.example.app/com.example.app.MainActivity (server)' ~ prepareDispatchCycle - flags=0x00000105, xOffset=0.000000, yOffset=0.000000, scaleFactor=1.000000, pointerIds=0x80000000, resumeWithAppendedMotionSample=false
12-20 14:07:41.549      229-262/? I/InputDispatcher﹕ channel '418ea098 com.example.app/com.example.app.MainActivity (server)' ~ startDispatchCycle
12-20 14:07:41.553      229-262/? D/InputManager-JNI﹕ pokeUserActivity : eventType=2
12-20 14:07:41.553      229-262/? D/PowerManagerService﹕ reactivateScreenLocksLocked mProxIgnoredBecauseScreenTurnedOff=false
12-20 14:07:41.553      229-262/? D/PowerManagerService﹕ newState=3, realDifference=2SCREEN_ON_BIT=1
12-20 14:07:41.553      229-262/? D/InputManager-JNI﹕ pokeUserActivity : eventType=2
12-20 14:07:41.556      229-262/? I/InputDispatcher﹕ channel '418ea098 com.example.app/com.example.app.MainActivity (server)' ~ finishDispatchCycle - 8.1ms since event, 7.7ms since dispatch, handled=true
12-20 14:07:41.559      229-262/? I/InputDispatcher﹕ channel '4196cc98  (server)' ~ finishDispatchCycle - 10.9ms since event, 10.6ms since dispatch, handled=true
12-20 14:07:41.563       96-162/? I/SurfaceFlinger﹕ [SurfaceFlinger] frames:51, duration:7.504000, fps:6.796230
12-20 14:07:41.647      229-263/? D/InputReader﹕ AP_PROF:AppLaunch_dispatchPtr:Up:648933
12-20 14:07:41.647      229-262/? I/InputDispatcher﹕ dispatchEventToCurrentInputTargets - resumeWithAppendedMotionSample=false
12-20 14:07:41.647      229-262/? I/InputDispatcher﹕ channel '418ea098 com.example.app/com.example.app.MainActivity (server)' ~ prepareDispatchCycle - flags=0x00000105, xOffset=0.000000, yOffset=0.000000, scaleFactor=1.000000, pointerIds=0x80000000, resumeWithAppendedMotionSample=false
12-20 14:07:41.647      229-262/? I/InputDispatcher﹕ channel '418ea098 com.example.app/com.example.app.MainActivity (server)' ~ startDispatchCycle
12-20 14:07:41.647      229-262/? D/InputManager-JNI﹕ pokeUserActivity : eventType=2
12-20 14:07:41.647      229-262/? D/InputManager-JNI﹕ pokeUserActivity : eventType=2
12-20 14:07:41.648      229-262/? I/InputDispatcher﹕ channel '418ea098 com.example.app/com.example.app.MainActivity (server)' ~ finishDispatchCycle - 1.3ms since event, 1.1ms since dispatch, handled=true
12-20 14:07:41.649      229-386/? D/Settings/Provide﹕ lookupValue, table system cache.containsKey sound_effects_enabled
12-20 14:07:41.657    4358-4358/com.example.app D/TelephonyManager﹕ getDefaultSim is sim1
12-20 14:07:41.659    4358-4358/com.example.app D/AndroidRuntime﹕ Shutting down VM
12-20 14:07:41.659    4358-4358/com.example.app W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40eb1258)
12-20 14:07:41.665    4358-4358/com.example.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.IllegalStateException: Could not execute method of the activity
            at android.view.View$1.onClick(View.java:3050)
            at android.view.View.performClick(View.java:3517)
            at android.view.View$PerformClick.run(View.java:14155)
            at android.os.Handler.handleCallback(Handler.java:605)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4511)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at android.view.View$1.onClick(View.java:3045)
            at android.view.View.performClick(View.java:3517)
            at android.view.View$PerformClick.run(View.java:14155)
            at android.os.Handler.handleCallback(Handler.java:605)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4511)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10094 nor current process has android.permission.READ_PHONE_STATE.
            at android.os.Parcel.readException(Parcel.java:1327)
            at android.os.Parcel.readException(Parcel.java:1281)
            at com.android.internal.telephony.IPhoneSubInfo$Stub$Proxy.getDeviceId(IPhoneSubInfo.java:182)
            at android.telephony.TelephonyManager.getDeviceId(TelephonyManager.java:274)
            at com.example.app.MainActivity.startService(MainActivity.java:34)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at android.view.View$1.onClick(View.java:3045)
            at android.view.View.performClick(View.java:3517)
            at android.view.View$PerformClick.run(View.java:14155)
            at android.os.Handler.handleCallback(Handler.java:605)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4511)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
            at dalvik.system.NativeStart.main(Native Method)
12-20 14:07:41.674      229-388/? D/Settings/Provide﹕ lookupValue, table secure cache.containsKey dropbox:data_app_crash
12-20 14:07:41.675      229-388/? D/Settings/Provide﹕ lookupValue, table secure cache.containsKey send_action_app_error
12-20 14:07:41.675      229-388/? W/ActivityManager﹕ Force finishing activity com.example.app/.MainActivity
12-20 14:07:41.675      229-388/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:41.679     229-4377/? D/Settings/Provide﹕ lookupValue, table secure cache.containsKey logcat_for_data_app_crash
12-20 14:07:41.679     229-4377/? D/Settings/Provide﹕ lookupValue, table secure cache.fullyMatchesDisk() logcat_for_data_app_crash
12-20 14:07:41.680     229-4377/? W/AES﹕ Exception Log handling...
12-20 14:07:41.711      229-245/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:41.711      229-258/? I/WindowManager﹕ Gaining focus: Window{41ccdfc0  paused=false}
12-20 14:07:41.728      229-245/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:41.729      229-245/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:41.756      229-245/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:41.760      229-258/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:41.774      229-258/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:41.784     229-4377/? D/AES﹕ ExceptionLog: notify aed
12-20 14:07:41.785     229-4377/? D/AES﹕ process : com.example.app
12-20 14:07:41.786     229-4377/? D/AES﹕ module : com.example.app v1 (1.0)
12-20 14:07:41.789      229-258/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:41.791     229-4377/? D/AES﹕ cause : data_app_crash
12-20 14:07:41.791     229-4377/? D/AES﹕ pid : 4358
12-20 14:07:41.792     229-4377/? D/AEE/LIBAEE﹕ shell: raise_exp(2, 4358, -1361051648, com.example.app, 0x0x636738, 0x0x0)
12-20 14:07:41.792     229-4377/? E/AEE/LIBAEE﹕ read_cmdline:com.example.app
12-20 14:07:41.792        89-89/? D/AEE/AED﹕ $===AEE===AEE===AEE===$
12-20 14:07:41.792        89-89/? D/AEE/AED﹕ aes socket(10) is ready for read
12-20 14:07:41.792        89-89/? D/AEE/AED﹕ handling AED session (13)
12-20 14:07:41.793     229-4377/? D/AEE/LIBAEE﹕ shell: connected with AED OK
12-20 14:07:41.793        89-89/? D/AEE/AED﹕ read success, handling msg (Ind, AE_IND_EXP_RAISED)
12-20 14:07:41.793        89-89/? D/AEE/AED﹕ Skip for Exp level'0'
12-20 14:07:41.793        89-89/? D/AEE/AED﹕ not know revents:0
12-20 14:07:41.793        89-89/? D/AEE/AED﹕ not know revents:0
12-20 14:07:41.793     229-4377/? D/AEE/LIBAEE﹕ shell: got the request (cmd:Ind,AE_IND_LOG_CLOSE)
12-20 14:07:41.794     229-4377/? D/AEE/LIBAEE﹕ shell: Got session close ind from AED
12-20 14:07:41.803      229-258/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:41.817      229-258/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:41.831      229-258/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:41.845      229-258/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:41.858      229-258/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:41.873      229-258/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:41.887      229-258/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:41.900      229-258/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:41.915      229-258/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:41.928      229-258/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:41.943      229-258/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:41.956      229-258/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:41.970      229-258/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:41.984      229-258/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.196      229-244/? W/ActivityManager﹕ Activity pause timeout for ActivityRecord{418c1b20 com.example.app/.MainActivity}
12-20 14:07:42.197      505-505/? D/loc﹕ location=[0, 0]
12-20 14:07:42.198      229-283/? D/NetworkPolicy﹕ onRecv: MSG_FOREGROUND_ACTIVITIES_CHANGED pid:uid:act=505:10028:true
12-20 14:07:42.200      229-520/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.203      229-520/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.204      505-505/? D/loc﹕ location=[0, 0]
12-20 14:07:42.205      505-505/? D/0601﹕ GNLauncher onRestart
12-20 14:07:42.205      505-505/? D/jipf-a﹕ onRestart mIsOnStop=true
12-20 14:07:42.205      505-505/? D/0601﹕ GNLauncher onStart
12-20 14:07:42.205      505-505/? D/jipf-a﹕ onStart mIsOnStop=false
12-20 14:07:42.205      505-505/? D/0601﹕ GNLauncher onResume
12-20 14:07:42.205      505-505/? D/jipf-a﹕ onResume mIsOnStop=false
12-20 14:07:42.206      505-505/? D/WallPaperProxy﹕ drawable.getIntrinsicWidth() =640,drawable.getIntrinsicHeight()=480
12-20 14:07:42.206      505-505/? D/WallPaperProxy﹕ MultiSpan wallpaper...
12-20 14:07:42.206      505-505/? D/loc﹕ location=[0, 0]
12-20 14:07:42.210      229-229/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.210      229-229/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.212      505-505/? D/jipf﹕ surfaceCreated
12-20 14:07:42.212      505-505/? D/jipf﹕ surfaceChanged
12-20 14:07:42.216      229-905/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.217      229-905/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.218      505-505/? D/loc﹕ location=[0, 0]
12-20 14:07:42.219      229-244/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.221      229-903/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.221      229-903/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.225      229-240/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.226      505-505/? D/jipf-a﹕ init
12-20 14:07:42.226      505-505/? D/0601﹕ GNLauncher init 1
12-20 14:07:42.226      505-505/? D/loc﹕ location=[0, 0]
12-20 14:07:42.227      229-239/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.228      229-239/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.229      505-505/? D/inv-profiling﹕ mInvRecords.size()=1
12-20 14:07:42.229      505-505/? D/inval﹕ calcScreenArea dirtyInOut=Rect(0, 0 - 1600, 376)
12-20 14:07:42.229      505-505/? D/DRAW-profiling﹕ calc use 0ms; dirty=Rect(0, 0 - 320, 480)
12-20 14:07:42.232      505-505/? D/draw-improve﹕ start onDraw mChildren.isNull=false
12-20 14:07:42.232      505-505/? D/draw-screen﹕ TranslateDrawingTransform
12-20 14:07:42.233      505-505/? D/ds-profiling﹕ rejected...
12-20 14:07:42.233      505-505/? D/ds-profiling﹕ rejected...
12-20 14:07:42.233      505-505/? D/CDrawable﹕ setBounds b=Rect(34, 7 - 64, 37)
12-20 14:07:42.234      505-505/? D/CDrawable﹕ setBounds b=Rect(34, 7 - 64, 37)
12-20 14:07:42.235     229-4378/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.235      505-505/? D/CDrawable﹕ setBounds b=Rect(34, 7 - 64, 37)
12-20 14:07:42.235      505-505/? D/ds-profiling﹕ rejected...
12-20 14:07:42.236      505-505/? D/ds-profiling﹕ rejected...
12-20 14:07:42.238      505-505/? D/CDrawable﹕ setBounds b=Rect(34, 7 - 64, 37)
12-20 14:07:42.242      505-505/? D/CDrawable﹕ setBounds b=Rect(34, 7 - 64, 37)
12-20 14:07:42.242      505-505/? D/CDrawable﹕ setBounds b=Rect(34, 7 - 64, 37)
12-20 14:07:42.243      505-505/? D/CDrawable﹕ setBounds b=Rect(34, 7 - 64, 37)
12-20 14:07:42.243      505-505/? D/LauncherAppWidgetHostView﹕ onDraw
12-20 14:07:42.243      505-505/? D/ds-profiling﹕ rejected...
12-20 14:07:42.243      505-505/? D/ds-profiling﹕ rejected...
12-20 14:07:42.243      505-505/? D/ds-profiling﹕ rejected...
12-20 14:07:42.243      505-505/? D/CNP﹕ cache size=0
12-20 14:07:42.244      505-505/? D/HotSeatLayer﹕ HotSeatLayer onDraw
12-20 14:07:42.244      505-505/? D/CDrawable﹕ setBounds b=Rect(34, 0 - 64, 30)
12-20 14:07:42.245      505-505/? D/CDrawable﹕ setBounds b=Rect(26, 8 - 56, 38)
12-20 14:07:42.245      505-505/? D/CDrawable﹕ setBounds b=Rect(26, 8 - 56, 38)
12-20 14:07:42.245      505-505/? D/CDrawable﹕ setBounds b=Rect(26, 8 - 56, 38)
12-20 14:07:42.245      505-505/? D/CDrawable﹕ setBounds b=Rect(26, 8 - 56, 38)
12-20 14:07:42.246      505-505/? D/DRAW-profiling﹕ draw use 17ms; dirty=Rect(0, 0 - 320, 480)
12-20 14:07:42.246      505-505/? D/loc﹕ location=[0, 0]
12-20 14:07:42.248      229-482/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.249      229-482/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.258      229-476/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.263      229-476/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.267      229-476/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.270      229-229/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.271      229-229/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.275      229-258/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.290      229-258/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.303      229-258/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.317      229-258/? I/InputDispatcher﹕ setInputWindows
12-20 14:07:42.318      306-306/? D/dalvikvm﹕ GC_FOR_ALLOC freed 1316K, 29% free 

我正在使用带有ANDROID 4.0.4的低成本中国手机Qmobile

2 个答案:

答案 0 :(得分:1)

您的<uses-permission>代码应位于<manifest>代码内,而不是<application>代码。请参阅文档here

在AndroidManifest中,移动:

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

<application>标记之外。将其放在<manifest>部分内,例如:

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="15" />    

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

答案 1 :(得分:0)

我的低成本中国平板电脑出现了类似的错误:没有电话服务,它们是功能很差的简单平板电脑。

所以,在我的情况下,错误意味着:&#34;你没有任何电话&#39;所以你无法获得IMEI号码!&#34;

玩得开心。

修改

无论如何,我从中国买了大约1000片,其中2%有IMEI问题。