編輯:關於Android編程
客戶要求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>
最近在開發的App中需要實現Toolbar與頂部內容區域級聯滾動的效果,一開始就想到了Android 5.0 中新添加的AppBarLayout控件,其正好是實現這個效果
Launcher3壁紙的規格默認是:壁紙高度=屏幕高度,壁紙寬帶=屏幕寬度*2倍 Android4.4的壁紙信息存放在/data/system/users/0/目錄下,W
RootLinux:Root == Windows:AdminstratorAndroid是Linux系統嗎?操作系統 = 系統內核 + 文件系統Linux發行版:Lin
1:服務端使用PHP 復制代碼 代碼如下:<?php echo date(Y-m-d H:i:s);?>2:activit