安卓充電提示音無效
阿新 • • 發佈:2018-12-19
Android 7.0 在設定中新增加了充電提示音的開啟選項,但開啟後,插上充電線也是聽不到充電音。根據檢視程式碼可知,其實該充電提示音是指無線充電提示音。
PowerManagerService.java中updateIsPoweredLocked函式中,
if (dockedOnWirelessCharger) {
mNotifier.onWirelessChargingStarted();
}
下面我們新增正常充電方式的提醒音量。
frameworks/base/services/core/java/com/android/server/notification/NotificationManagerService.java
///導包@{
import android.media.RingtoneManager;
import android.media.Ringtone;
///}@
在private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) 中新增如下方法
else if (action.equals(Intent.ACTION_USER_UNLOCKED)) {
final int user = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL);
mConditionProviders.onUserUnlocked(user);
mListeners.onUserUnlocked(user);
mAssistants.onUserUnlocked(user);
mZenModeHelper.onUserUnlocked(user);
/// for charge [email protected]{
}else if (action.equals(Intent.ACTION_POWER_CONNECTED)){
final boolean enabled = Settings.Global.getInt(getContext().getContentResolver(),
Settings.Global.CHARGING_SOUNDS_ENABLED, 1) != 0;
final String soundPath = Settings.Global.getString(getContext().getContentResolver(),
Settings.Global.WIRELESS_CHARGING_STARTED_SOUND);
if (enabled && soundPath != null) {
final Uri soundUri = Uri.parse("file://" + soundPath);
if (soundUri != null) {
final Ringtone sfx = RingtoneManager.getRingtone(getContext(), soundUri);
if (sfx != null) {
sfx.setStreamType(AudioManager.STREAM_SYSTEM);
sfx.play();
}
}
}
}
///}@
public void onStart() { //在方法中新增如下方法
filter.addAction(Intent.ACTION_USER_STOPPED);
filter.addAction(Intent.ACTION_USER_SWITCHED);
/// for charge [email protected]{
filter.addAction(Intent.ACTION_POWER_CONNECTED);
///}@
filter.addAction(Intent.ACTION_USER_ADDED);
filter.addAction(Intent.ACTION_USER_REMOVED);