android FM播放時拔出耳機後,FM APP出現”拔出耳機,Fm停止”的提示框,然後自動close

來源:互聯網
上載者:User
客戶要求 FM播放時拔出耳機後,FM APP出現“拔出耳機,Fm停止"的提示框,然後自動close
修改FMRadioService.java 1.添加如下import,以便能顯示toast

////AAAAA add start

import android.widget.Toast;

////AAAAA add end public class FMRadioService extends Service implements FMRecorder.OnRecorderStateChangedListener {   2.在下面函數onBind()前添加 

//AAAAA add start

 public static final int MSG_EXIT_FM = 1234;

 private Handler sHandler11 = new Handler() {

   @Override

   public void handleMessage(Message msg) {

    FMRadioLogUtils.d(TAG, "sHandler11 =  " + msg.what);

    switch (msg.what) {

     case MSG_EXIT_FM:

      android.os.Process.killProcess(android.os.Process.myPid());

      break;

    }

   }

 };  private Toast mToast = null;  private void showToast(CharSequence text) {

 if (null == mToast) {

     mToast = Toast.makeText(mContext, text, Toast.LENGTH_SHORT);

     }

        mToast.setText(text);

        mToast.show();

        LogUtils.v(TAG, "FMRadioActivity.showToast: toast = " + text);

    };

//AAAAA add end

@Override

    public IBinder onBind(Intent intent) {

        return mBinder;

    }   3.修改onReceive 方法,這樣子就可以顯示toast以及關閉Fm app了

在  switchAntennaAsync(mValueHeadSetPlug);

之後添加:

 if(mValueHeadSetPlug == 1 && mIsPowerUp )

{

   showToast(getString(R.string.toast_plugin_headphone_before_FM));

   sHandler11.sendMessageDelayed(sHandler.obtainMessage(MSG_EXIT_FM, FMRadioService.this),(long) 1000); mFmServiceHandler.removeCallbacksAndMessages(null);
stopFMFocusLoss(AudioManager.AUDIOFOCUS_LOSS);


}

 else

 sHandler11.removeMessages(MSG_EXIT_FM);   4.在alps\mediatek\packages\apps\FMRadio\res\values\
strings.xml中添加

<string name="toast_plugin_headphone_before_FM">The FM will close because you have been plug out the headphone</string>

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.