机器人:怎么听" SD卡意外&QUOT删除; [英] android: how to listen to "sd card removed unexpectedly"

查看:147
本文介绍了机器人:怎么听" SD卡意外&QUOT删除;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用的SD卡内容的程序。我想听听像安装SD卡或SD卡意外删除不同的状态。我怎么可以这样做。一个例子是有很大的帮助。

I have a program that uses content from sd-card. I want to listen to different states like sd-card mounted or sd-card removed unexpectedly. How can I do so. An example would be of a great help.

感谢所有

推荐答案

您需要侦听<一个href=\"http://developer.android.com/reference/android/content/Intent.html#ACTION_MEDIA_REMOVED\">ACTION_MEDIA_REMOVED和<一个href=\"http://developer.android.com/reference/android/content/Intent.html#ACTION_MEDIA_MOUNTED\">ACTION_MEDIA_MOUNTED.创建一个接收器和监听这个动作。

You need to listen for ACTION_MEDIA_REMOVED and ACTION_MEDIA_MOUNTED. Create a receiver and listen for this action.

编辑:

在你的manifest文件添加此

In your manifest file add this

<receiver android:name=".MyReceiver" >
    <intent-filter>
        <action android:name="android.intent.action.MEDIA_REMOVED" />
        <action android:name="android.intent.action.MEDIA_MOUNTED" />
    </intent-filter>
</receiver>

然后创建一个类MyReceiver这将延长广播接收器,然后捕获这些行动和执行您想要做什么。

then create a class MyReceiver which will extend BroadcastReceiver and then catch these actions and perform what you want to do.

这篇关于机器人:怎么听&QUOT; SD卡意外&QUOT删除;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆