我试图在android marshmallow中运行时请求权限。但我的应用程序崩溃在这里是我的代码。
private void showWebpage() {
if (checkSelfPermission(Manifest.permission.INTERNET) == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "Permission Granted", Toast.LENGTH_LONG).show();
} else {
requestPermissions(new String[]{Manifest.permission.INTERNET},REQUEST_INTERNET);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
当我调用showWebpage()方法时,应用程序崩溃了。控件将转到else部分并调用requestPermissions方法,但应用程序正在崩溃。 这是我的logcat错误
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: Failed to read uid_cputime
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: java.io.FileNotFoundException: /proc/uid_cputime/show_uid_stat: open failed: ENOENT (No such file or directory)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at libcore.io.IoBridge.open(IoBridge.java:452)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at java.io.FileInputStream.<init>(FileInputStream.java:76)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at java.io.FileInputStream.<init>(FileInputStream.java:103)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at java.io.FileReader.<init>(FileReader.java:66)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at com.android.internal.os.KernelUidCpuTimeReader.readDelta(KernelUidCpuTimeReader.java:71)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at com.android.internal.os.BatteryStatsImpl.updateCpuTimeLocked(BatteryStatsImpl.java:8031)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at com.android.internal.os.BatteryStatsImpl$MyHandler.handleMessage(BatteryStatsImpl.java:155)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at android.os.Handler.dispatchMessage(Handler.java:102)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at android.os.Looper.loop(Looper.java:148)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at android.os.HandlerThread.run(HandlerThread.java:61)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at com.android.server.ServiceThread.run(ServiceThread.java:46)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at libcore.io.Posix.open(Native Method)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at libcore.io.IoBridge.open(IoBridge.java:438)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at java.io.FileInputStream.<init>(FileInputStream.java:76)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at java.io.FileInputStream.<init>(FileInputStream.java:103)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at java.io.FileReader.<init>(FileReader.java:66)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at com.android.internal.os.KernelUidCpuTimeReader.readDelta(KernelUidCpuTimeReader.java:71)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at com.android.internal.os.BatteryStatsImpl.updateCpuTimeLocked(BatteryStatsImpl.java:8031)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at com.android.internal.os.BatteryStatsImpl$MyHandler.handleMessage(BatteryStatsImpl.java:155)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at android.os.Handler.dispatchMessage(Handler.java:102)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at android.os.Looper.loop(Looper.java:148)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at android.os.HandlerThread.run(HandlerThread.java:61)
11-14 01:33:11.575 1092-1106/system_process E/KernelUidCpuTimeReader: at com.android.server.ServiceThread.run(ServiceThread.java:46)
请帮助我,这非常重要:(
答案 0 :(得分:-1)
INTERNET
权限具有保护级别normal
,您无需在运行时请求它。您应该只声明您的应用在清单中使用它:
<uses-permission android:name="android.permission.INTERNET"/>