Reputation: 20916
I want my application start automatically when the device is placed in the car doc. I find this useful code for manifest but I want to give user option with checkbox if he want to use this option.
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.CAR_DOCK" />
<category android:name="android.intent.category.DEFAULT" />
How to make this possible if user check option then app will be started when it is placed in the car dock, otherway not.
Upvotes: 0
Views: 210
Reputation: 24820
Use the above manifest entries for a broadcast reciever and not for a activity. And inside broadcast receiver you can check the preference and then launch the activity.
Edit: Register the DockReciever with above manifest changes. If that does not work then use below action
<action android:name="android.intent.action.ACTION_DOCK_EVENT"/>
you will have to check the state of the dock if you use this.
public class DockReciever extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg1) {
SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
boolean launch = settings.getBoolean(Utility.KEY_LAUNCH, false);
if(settings.getBoolean(Utility.KEY_LAUNCH, false)){
Intent intent = //your Activity intent goes here
arg0.startActivity(intent);
}
}
}
Upvotes: 2