Android 后台播放FM 手机切换到airplane mode FM不会停止 M

来源:互联网 发布:知柏地黄丸成分,含量 编辑:程序博客网 时间:2024/05/05 17:29

前言
        
欢迎大家我分享和推荐好用的代码段~~
声明
        
欢迎转载,但请保留文章原始出处:
         CSDN:
http://www.csdn.net
         雨季o莫忧离:http://blog.csdn.net/luckkof

正文

 

要求在播放FM时,手机切换到飞行模式,FM自动停止

 

在FM APP中添加相关消息处理函数,监听到飞行模式开启后将FM停止,修改code如下:
1.修改FMRadioService.java中        public void onReceive(Context context, Intent intent)

else {
                LogUtils.w(TAG, "Error: undefined action.");
  }
之前添加:
else if(Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(action)){
       
       boolean isAirPlaneMode = intent.getBooleanExtra("state",false);
       if(isAirPlaneMode){
        LogUtils.d(TAG, ">>>ACTION_AIRPLANE_MODE_CHANGED");
         if (mIsPowerUp) {
          //enableFMAudio(false);
          powerDown();
          }
        
       }
       else{
         if (!mIsPowerUp) {
          //enableFMAudio(true);
          //powerUpFM(float frequency);
          tuneStation(FMRadioUtils.computeFrequency(getFrequency()));
         }
       }
      
            }
2.修改    public void onCreate()
在        filter.addAction(Intent.ACTION_SCREEN_OFF);
之后添加        filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
原创粉丝点击