2014-11-24 51 views
0

我想檢測使用UiModeManager的汽車模式的ENTER和EXIT。但是,當我啓用/禁用 「免提模式」 在我的三星S4廣播接收器不invoked.Here是我的代碼Android ACTION_EXIT_CAR_MODE不工作

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

晚的答案,但嘗試改變

android:exported="false" 

android:exported="true"