2014年1月28日 星期二

開發Android藍芽程式 出現閃退

發現是執行到mBluetoothAdapter.startDiscovery();出現閃退現象

利用logcat的Error Log level發現以下錯誤

com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:804)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:571)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.SecurityException: Need BLUETOOTH_ADMIN permission: Neither user 10148 nor current process has android.permission.BLUETOOTH_ADMIN.
            at android.os.Parcel.readException(Parcel.java:1425)
            at android.os.Parcel.readException(Parcel.java:1379)
            at android.bluetooth.IBluetooth$Stub$Proxy.startDiscovery(IBluetooth.java:1966)
            at android.bluetooth.BluetoothAdapter.startDiscovery(BluetoothAdapter.java:795)
            at com.nelson.app.FullscreenActivity.CommunicationWithBtDevice(FullscreenActivity.java:248)
            at com.nelson.app.FullscreenActivity.onActivityResult(FullscreenActivity.java:214)
            at android.app.Activity.dispatchActivityResult(Activity.java:5274)
            at android.app.ActivityThread.deliverResults(ActivityThread.java:3158)
            at android.app.ActivityThread.handleSendResult(ActivityThread.java:3205)
            at android.app.ActivityThread.access$1100(ActivityThread.java:136)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1249)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4881)
            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:804)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:571)
            at dalvik.system.NativeStart.main(Native Method)
01-28 23:06:03.001      522-676/? E/InputDispatcher﹕ channel '42ec6e68 com.nelson.app/com.nelson.app.FullscreenActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
01-28 23:06:03.462     830-1318/? E/ExternalAccountType﹕ Unsupported attribute readOnly


解決方法:
打開AndroidManifest.xml
加上
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"></uses-permission>

就不會出現閃退現象嚕

透過Facebook分享