android studio java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.eeyiyu/com.example.eeyiyu.ListActivity}: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/audio/media from pid=3735, uid=10042 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
时间: 2023-12-10 07:02:21 浏览: 742
这个错误是因为你的应用程序没有被授予读取外部存储器的权限。你需要在 AndroidManifest.xml 文件中添加以下权限:
```xml
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
```
同时,你需要检查你的应用程序是否在运行时请求了这个权限。你可以使用以下代码来请求权限:
```java
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_CODE);
}
```
请确保在请求权限之前,你已经检查了权限是否已经被授予。否则,你的应用程序将在运行时崩溃。
相关问题
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.eeyiyu, PID: 396 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.eeyiyu/com.example.eeyiyu.PlayActivity}: java.lang.IllegalArgumentException: Invalid notification (no valid small icon): Notification(channel=651 shortcut=null contentView=null vibrate=null sound=null defaults=0x0 flags=0x0 color=0x00000000 vis=PRIVATE)
这个错误通常是由于未指定通知的小图标而导致的。在创建通知时,需要指定一个小图标,否则会出现该错误。请确保在创建通知时指定了小图标。可以在创建通知时使用 setSmallIcon() 方法来指定小图标。例如:
```
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle(title)
.setContentText(message)
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
```
其中 `R.drawable.notification_icon` 是指定的小图标资源。请确保该资源存在并已正确导入。
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androideight/com.example.androideight.MainActivity}: java.lang.RuntimeException: java.io.IOException: Cleartext HTTP traffic to localhost not permitted
这个错误是因为在Android 9 (API level 28)及以上版本中,默认禁止应用程序通过明文HTTP协议访问网络。如果您尝试通过HTTP访问网络,就会收到这样的错误。
为了解决这个问题,有两种方法:
1. 使用加密的HTTPS协议进行网络通信,这是安全的方式,也是推荐的方式。您可以在服务器上启用HTTPS,并在Android应用程序中使用HTTPS协议来访问它。您可以使用OkHttp等库来实现HTTPS协议的访问。
2. 如果您仍然想使用HTTP协议进行网络通信,可以在AndroidManifest.xml文件中添加一个`usesCleartextTraffic`标记来允许明文HTTP流量。例如:
```xml
<application
...
android:usesCleartextTraffic="true">
...
</application>
```
这个标记会允许您的应用程序在Android 9及以上版本中使用明文HTTP协议进行网络通信。但是请注意,这并不是推荐的方式,因为明文HTTP通信是不安全的,可能会泄漏敏感信息。如果您使用此方法,请确保您的应用程序只使用受信任的网络,并且不要从网络上获取任何敏感信息。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)