gpt4 book ai didi

android - 无法打开跟踪文件

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:33:30 26 4
gpt4 key购买 nike

我想测试我的应用程序的性能。我用简单的应用程序启动它并尝试放置 traceview 但它突然在我的 android 手机上失败并强制关闭。请指导我如何为简单的 android 应用程序设置我的代码 propley 以使用 Trace View 弄脏手

代码如下包测试.check;

import android.app.Activity;
import android.os.Bundle;
import android.os.Debug;

public class tracev extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Debug.startMethodTracing("traceview");
setContentView(R.layout.main);
}
@Override
protected void onStop() {
Debug.stopMethodTracing();
super.onStop();
}
}

这是 list 文件

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test.check"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".tracev"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

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

我也加了

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

但它不起作用。我认为这是因为 logcat 中的这一行,但我不确定如何处理它

05-20 23:39:43.913: ERROR/dalvikvm(11673): Unable to open trace file '/sdcard/traceview.trace': Permission denied

日志

05-20 23:39:43.903: DEBUG/dalvikvm(11673): +++ active profiler count now 1
05-20 23:39:43.913: INFO/dalvikvm(11673): TRACE STARTED: '/sdcard/traceview.trace' 8192KB
05-20 23:39:43.913: ERROR/dalvikvm(11673): Unable to open trace file '/sdcard/traceview.trace': Permission denied
05-20 23:39:43.913: DEBUG/dalvikvm(11673): +++ active profiler count now 0
05-20 23:39:43.913: DEBUG/AndroidRuntime(11673): Shutting down VM
05-20 23:39:43.913: WARN/dalvikvm(11673): threadid=3: thread exiting with uncaught exception (group=0x4001e390)
05-20 23:39:43.913: ERROR/AndroidRuntime(11673): Uncaught handler: thread main exiting due to uncaught exception
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): java.lang.RuntimeException: Unable to start activity ComponentInfo{test.check/test.check.tracev}: java.lang.RuntimeException: file open failed
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.app.ActivityThread.access$2200(ActivityThread.java:126)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.os.Handler.dispatchMessage(Handler.java:99)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.os.Looper.loop(Looper.java:123)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.app.ActivityThread.main(ActivityThread.java:4595)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at java.lang.reflect.Method.invokeNative(Native Method)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at java.lang.reflect.Method.invoke(Method.java:521)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at dalvik.system.NativeStart.main(Native Method)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): Caused by: java.lang.RuntimeException: file open failed
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at dalvik.system.VMDebug.startMethodTracing(Native Method)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at dalvik.system.VMDebug.startMethodTracing(VMDebug.java:156)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.os.Debug.startMethodTracing(Debug.java:443)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.os.Debug.startMethodTracing(Debug.java:391)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at test.check.tracev.onCreate(tracev.java:12)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): ... 11 more
05-20 23:39:44.013: INFO/Process(94): Sending signal. PID: 11673 SIG: 3
05-20 23:39:44.013: INFO/dalvikvm(11673): threadid=7: reacting to signal 3
05-20 23:39:44.023: INFO/dalvikvm(11673): Wrote stack trace to '/data/anr/traces.txt'
05-20 23:39:51.213: DEBUG/KeyguardViewMediator(94): pokeWakelock(15000)
05-20 23:39:51.213: INFO/HtcLockScreen(94): Press Menu key to unlock screen

我想知道有一点是 sdcard 中没有任何内容,并且在它前面没有选择设备。可能是错误的原因,这是图片 enter image description here

最佳答案

在 Marshmallow(Android 版本 6,API 级别 23)上,仅在 list 中具有“写入”权限是不够的。你必须要那个 permission at runtime ,或者您可以转到系统偏好设置并为您的应用授予存储权限。

关于android - 无法打开跟踪文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6077953/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com