Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2091360
  • 博文数量: 413
  • 博客积分: 10926
  • 博客等级: 上将
  • 技术积分: 3862
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-09 18:14
文章分类

全部博文(413)

文章存档

2015年(5)

2014年(1)

2013年(5)

2012年(6)

2011年(138)

2010年(85)

2009年(42)

2008年(46)

2007年(26)

2006年(59)

分类: Java

2009-03-13 12:10:05

1, Define a class derived from class BroadcastReceiver;
2, Register broadcast receiver;
    MyBroadcastReceiver myReceiver = new MyBroadcastReceiver();
    IntentFilter filter = new IntentFilter(Intent.ACTION_MEDIA_MOUNTED);
    filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    filter.addAction(Intent.ACTION_MEDIA_EJECT);
    ...
    filter.addDataScheme("file"); //This is important. Otherwise, broadcast can'
t be received
    registerReceiver(myReceiver, filter);

About other broadcast actions for media, and extra data bind to the intent, please refer to http://developer.android.com/reference/android/content/Intent.html (please search ACTION_MEDIA_ on this web page)

Notes: The path of mounted media is Intent.mData. Intent.mData is not available in SDK 1.0, but it be retrieved by calling Intent.getDataString();
阅读(1626) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~