首页 > 代码库 > 自定义广播
自定义广播
mSDStateBrocast = new SDStateBrocast(); IntentFilter intentFilter2 = new IntentFilter(); intentFilter2.addAction(Intent.ACTION_MEDIA_MOUNTED); intentFilter2.addAction(Intent.ACTION_MEDIA_UNMOUNTED); intentFilter2.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED); intentFilter2.addAction(Intent.ACTION_MEDIA_EJECT); intentFilter2.addDataScheme("file"); registerReceiver(mSDStateBrocast, intentFilter2);
class SDStateBrocast extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub String action = intent.getAction(); if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) { // Log.i(TAG, "===================>Intent.ACTION_MEDIA_MOUNTED"); mIsSdExist = true; }else if (action.equals(Intent.ACTION_MEDIA_UNMOUNTED)) { // Log.i(TAG, "===================>Intent.ACTION_MEDIA_UNMOUNTED"); mIsSdExist = false; }else if (Intent.ACTION_MEDIA_SCANNER_FINISHED.equals(action)) { // Log.i(TAG, "===================>Intent.ACTION_MEDIA_SCANNER_FINISHED mIsSdExist = " + mIsSdExist); if (mIsSdExist) { m_MusicFileList = getMusicFileList(); mServiceManager.refreshMusicList(m_MusicFileList); if (m_MusicFileList.size() > 0) { mIsHaveData = true; } mListViewAdapter.refreshAdapter(m_MusicFileList); } }else if (Intent.ACTION_MEDIA_EJECT.equals(action)) { // Log.i(TAG, "===================>Intent.ACTION_MEDIA_EJECT"); // mServiceManager.reset(); m_MusicFileList.clear(); mListViewAdapter.refreshAdapter(m_MusicFileList); mIsHaveData = false; mUIManager.emptyPlayInfo(); } } }
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | public void sendPlayStateBrocast() { if (mContext != null ) { Intent intent = new Intent(BROCAST_NAME); intent.putExtra(MusicPlayState.PLAY_STATE_NAME, mPlayState); intent.putExtra(MusicPlayState.PLAY_MUSIC_INDEX, mCurPlayIndex); if (mPlayState != MusicPlayState.MPS_NOFILE) { Bundle bundle = new Bundle(); MusicData data = http://www.mamicode.com/mMusicFileList.get(mCurPlayIndex); bundle.putParcelable(MusicData.KEY_MUSIC_DATA, data); intent.putExtra(MusicData.KEY_MUSIC_DATA, bundle); } mContext.sendBroadcast(intent); } } |
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。