I'm developing some kind of Car mode application and I want to replace default home screen while driving. But I want to activate it when user uses NFC label or exceeding the speed limit. I found one app on Google Play (https://play.google.com/store/apps/details?id=com.safedrivingassociation.everyonetexts) that does this, so it is possible, but I have no idea how to implement this.
Asked
Active
Viewed 2,053 times
0
-
Sounds interesting. Good luck! Head on back when you have a question. – admdrew Dec 09 '13 at 17:33
-
Not sure if this is what you are looking for, but it could help: http://stackoverflow.com/questions/5109407/how-do-i-test-my-dock-application – turbo Dec 09 '13 at 17:37
-
Not helpful if making an app is the goal but I wanted to do this so I just use Lama. It is an actions manager which lets you do things based on events Not sure if it supports nfc though but I know alternatives to it do for sure. – ghostbust555 Dec 09 '13 at 17:42
-
Did you ever get this working correctly in the end? Particularly the home activity part. – RED_ Feb 13 '15 at 16:13
1 Answers
2
Finally, I found a solution. First of all we need to get a UiModeManager instance:
UiModeManager uiModeManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
Next, to put phone to a car mode we just call
uiModeManager.enableCarMode(UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME);
To restore default phone mode:
uiModeManager.disableCarMode(UiModeManager.DISABLE_CAR_MODE_GO_HOME);
That's all. And for our activity that we want it to be a home screen for car mode, we just add intent-filter to a manifest:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.CAR_MODE" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.CAR_DOCK"/>
</intent-filter>

Vadym Kovalenko
- 699
- 1
- 11
- 27
-
The docs for enableCarMode() say that the flags parameter has to be 0 but the constant you're providing (ENABLE_CAR_MODE_GO_CAR_HOME) is 1. Maybe it was deprecated? – spaaarky21 Feb 28 '14 at 00:23
-
1Weird, but according to docs both constants have value of 1 http://developer.android.com/reference/android/app/UiModeManager.html#ENABLE_CAR_MODE_GO_CAR_HOME But here is from another part of the docs: ENABLE_CAR_MODE_GO_CAR_HOME Added in API level 8 Flag for use with enableCarMode(int): go to the car home activity as part of the enable. – Vadym Kovalenko Feb 28 '14 at 12:56
-
Yeah, it's certainly seems like a discrepancy. The docs for the constant say that it "ensures a clean transition between the current activity (in non-car-mode) and the car home activity". When I use the flag, it seems to force a transition, closing the activity and reopening it, even though I ultimately end up on the same screen. If I use 0, my activity's day/night theme changes without my activity noticeably re-opening. – spaaarky21 Feb 28 '14 at 20:01