zoukankan      html  css  js  c++  java
  • 自定义广播

    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();
                  }
                
            }
            
        }
    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 = mMusicFileList.get(mCurPlayIndex);
    				
    				bundle.putParcelable(MusicData.KEY_MUSIC_DATA, data);	
    				intent.putExtra(MusicData.KEY_MUSIC_DATA, bundle);
    			}
    			
    		
    			mContext.sendBroadcast(intent);
    		}
    		
    		
    	}
    

      

  • 相关阅读:
    shell--练习--简易计算器
    shell--运算符
    shell--传递参数
    PHP数学函数的练习
    PDO对数据库的操作
    PHP实现手机短信的验证
    ThinkPHP框架 _ 学习16
    ThinkPHP框架 _ 学习15
    ThinkPHP框架 _ 学习14
    ThinkPHP框架 _ 学习13
  • 原文地址:https://www.cnblogs.com/profession/p/3695795.html
Copyright © 2011-2022 走看看