Android:如何知道SD卡何时被卸载
我正在开发一个从 sd 卡读取媒体并播放它的应用程序。但是,当 sd 卡从设备中物理移除或设备连接到计算机并且 sd 卡被移除时,会发生某些事件。安装在计算机上。每当移除 SD 卡时,都会生成一条通知,并可以在通知栏中看到。我希望我的应用程序能够响应这些通知。例如,每当用户物理移除卡或将其连接到计算机时,我希望我的应用程序显示类似“SD 卡已移除”的消息。有什么方法可以响应这些通知吗?
I am working on an application that reads media from the sd-card and plays it.. However, there are certain events when the sd-card is physically removed from the device or the device is attached to a computer and the sd-card is mounted on the computer.. Whenever the sd-card is removed, a notification is generated and can be seen in the notification bar. I want my application to respond to those notifications. For example, whenever the user physically removes the card or attaches it to the computer, I want my application to display a message like "sd card removed".. Is there any way to respond to these notifications??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,你不知道。您想要响应广播
意图
,该广播也用于创建这些通知
。查看
Intent
类的文档 ,位于ACTION_MEDIA_*
广播操作集。No, you don't. You want to respond to the broadcast
Intents
that are also used to create thoseNotifications
.Look at the documentation for the
Intent
class, at theACTION_MEDIA_*
set of broadcast actions.我知道问题很旧,但我最终在这里寻找这段代码,所以就在这里。
在manifest.xml中注册接收器:
然后创建接收器类:
I know question is old but I ended up here looking for this code, so here it is.
In the manifest.xml register the receiver:
Then create receiver class: