Android震動與提示音實(shí)現(xiàn)代碼
本文實(shí)例為大家分享了android消息提示的具體代碼,供大家參考,具體內(nèi)容如下
protected AudioManager audioManager;
protected Vibrator vibrator;
audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); //此方法是由Context調(diào)用的
vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE); //同上
/**
* vibrate and play tone
*/
public void vibrateAndPlayTone(EMMessage message) {
if (System.currentTimeMillis() - lastNotifiyTime < 1000) {
// received new messages within 2 seconds, skip play ringtone
return;
}
try {
lastNotifiyTime = System.currentTimeMillis();
// check if in silent mode
if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT)
{
Log.e("TAG","已經(jīng)調(diào)成靜音");
return;
}
long[] pattern = new long[] { 0, 180, 80, 120 };
vibrator.vibrate(pattern, -1); //震動
if (ringtone == null) {
Uri notificationUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
ringtone = RingtoneManager.getRingtone(appContext, notificationUri);
if (ringtone == null) {
Log.d(TAG, "cant find ringtone at:" + notificationUri.getPath());
return;
}
}
if (!ringtone.isPlaying()) {
//String vendor = Build.MANUFACTURER;
ringtone.play();
// for samsung S3, we meet a bug that the phone will
// continue ringtone without stop
// so add below special handler to stop it after 3s if
// needed
if (vendor != null && vendor.toLowerCase().contains("samsung")) {
Thread ctlThread = new Thread() {
public void run() {
try {
Thread.sleep(3000);
if (ringtone.isPlaying()) {
ringtone.stop();
}
} catch (Exception e) {
}
}
};
ctlThread.run();
}
} catch (Exception e) {
e.printStackTrace();
}
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- android開發(fā)之蜂鳴提示音和震動提示的實(shí)現(xiàn)原理與參考代碼
- Android實(shí)現(xiàn)調(diào)用震動的方法
- android滑動解鎖震動效果的開啟和取消
- android獲取情景模式和鈴聲 實(shí)現(xiàn)震動、鈴聲提醒
- android 觸屏的震動響應(yīng)接口調(diào)用方法
- Android實(shí)現(xiàn)手機(jī)震動效果
- android鬧鈴簡單實(shí)現(xiàn)
- Android設(shè)置鈴聲實(shí)現(xiàn)代碼
- Android鬧鈴服務(wù)AlarmManager用法深入分析
- Android編程實(shí)現(xiàn)震動與振鈴的方法詳解
相關(guān)文章
Android中通過RxJava進(jìn)行響應(yīng)式程序設(shè)計的入門指南
響應(yīng)式編程在Android中的運(yùn)用是非常犀利的,比如在異常處理和調(diào)度器方面,這里我們將從生命周期等方面來講解Android中通過RxJava進(jìn)行響應(yīng)式程序設(shè)計的入門指南:2016-06-06
android viewpager實(shí)現(xiàn)豎屏滑動效果
這篇文章主要為大家詳細(xì)介紹了android viewpager實(shí)現(xiàn)豎屏滑動效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-07-07
Android:利用SharedPreferences實(shí)現(xiàn)自動登錄
本篇文章主要介紹了Android實(shí)現(xiàn)自動登錄,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-11-11
Android使用OkHttp進(jìn)行重定向攔截處理的方法
這篇文章主要介紹了Android使用OkHttp進(jìn)行重定向攔截處理的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-08-08
android新建草稿刪除后下次開機(jī)還會顯示保存的草稿
android 新建一個草稿,保存,然后全部刪除會話,關(guān)機(jī)再開機(jī)后還會顯示保存的草稿,下面與大家分享下具體的解決方法2013-06-06
Flutter配置代理抓包實(shí)現(xiàn)過程詳解
這篇文章主要為大家介紹了Flutter配置代理抓包實(shí)現(xiàn)過程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02
react native打包apk文件安裝好之后進(jìn)入應(yīng)用閃退的解決方案
這篇文章主要介紹了react native打包apk文件安裝好之后進(jìn)入應(yīng)用閃退的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09

