我正在尝试使用UiModeManager检测汽车模式的ENTER和EXIT。但是当我启用/禁用未调用的Samsung S4 BroadcastReceiver中的“免提模式”时。这是我的代码
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.titut.car"
android:versionCode="1"
android:versionName="1.0.0">
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".CarModeReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.app.action.ENTER_CAR_MODE" />
<action android:name="android.app.action.EXIT_CAR_MODE" />
</intent-filter>
</receiver>
</application>
</manifest>
CarModeReceiver.java
public class CarModeReceiver extends BroadcastReceiver {
private static final String TAG = "CarModeReceiver";
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action != null) {
if (action.equals(UiModeManager.ACTION_ENTER_CAR_MODE)) {
Log.d(TAG, "Entering car mode!");
} else if (action.equals(UiModeManager.ACTION_EXIT_CAR_MODE)) {
Log.d(TAG, "Leaving car mode!");
}
}
}
}
参考:https://github.com/twaddington/android-obd-logger
任何建议/修复都会对我有所帮助。
答案 0 :(得分:0)
迟到的答案,但请尝试更改
android:exported="false"
到
android:exported="true"