4

我添加如下traceview代码:

Debug.startMethodTracing("perf_trance");
//code
Debug.stopMethodTracing();

然后,我在清单中设置了所需的权限。

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

但是当我运行我的应用程序以跟踪查看性能时,我得到了 RuntimeException:

06-04 14:57:23.083: E/AndroidRuntime(5584): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myxx.testapp/com.myxx.testapp.MainActivity}: java.lang.RuntimeException: Unable to open trace file '/mnt/sdcard/perf_trance.trace': Permission denied
06-04 14:57:23.083: E/AndroidRuntime(5584):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2007)
06-04 14:57:23.083: E/AndroidRuntime(5584):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2034)
06-04 14:57:23.083: E/AndroidRuntime(5584):     at android.app.ActivityThread.access$600(ActivityThread.java:129)
06-04 14:57:23.083: E/AndroidRuntime(5584):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1185)
06-04 14:57:23.083: E/AndroidRuntime(5584):     at android.os.Handler.dispatchMessage(SourceFile:99)
06-04 14:57:23.083: E/AndroidRuntime(5584):     at android.os.Looper.loop(SourceFile:137)
06-04 14:57:23.083: E/AndroidRuntime(5584):     at android.app.ActivityThread.main(ActivityThread.java:4518)
06-04 14:57:23.083: E/AndroidRuntime(5584):     at java.lang.reflect.Method.invokeNative(Native Method)
06-04 14:57:23.083: E/AndroidRuntime(5584):     at java.lang.reflect.Method.invoke(Method.java:511)
06-04 14:57:23.083: E/AndroidRuntime(5584):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(SourceFile:809)
06-04 14:57:23.083: E/AndroidRuntime(5584):     at com.android.internal.os.ZygoteInit.main(SourceFile:576)
06-04 14:57:23.083: E/AndroidRuntime(5584):     at dalvik.system.NativeStart.main(Native Method)
06-04 14:57:23.083: E/AndroidRuntime(5584): Caused by: java.lang.RuntimeException: Unable to open trace file '/mnt/sdcard/perf_trance.trace': Permission denied
06-04 14:57:23.083: E/AndroidRuntime(5584):     at dalvik.system.VMDebug.startMethodTracingNative(Native Method)
06-04 14:57:23.083: E/AndroidRuntime(5584):     at dalvik.system.VMDebug.startMethodTracing(VMDebug.java:175)
06-04 14:57:23.083: E/AndroidRuntime(5584):     at android.os.Debug.startMethodTracing(SourceFile:496)
06-04 14:57:23.083: E/AndroidRuntime(5584):     at android.os.Debug.startMethodTracing(SourceFile:444)
06-04 14:57:23.083: E/AndroidRuntime(5584):     at com.mediatek.oobe.basic.MainActivity.onCreate(MainActivity.java:154)
06-04 14:57:23.083: E/AndroidRuntime(5584):     at android.app.Activity.performCreate(Activity.java:4479)
06-04 14:57:23.083: E/AndroidRuntime(5584):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
06-04 14:57:23.083: E/AndroidRuntime(5584):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1971)
06-04 14:57:23.083: E/AndroidRuntime(5584):     ... 11

不知道为什么traceview不能写入/mnt/sdcard/?

我还注意到目录的权限是d---rwxr-x,这是根本原因吗?

4

0 回答 0