Add support for launching activities when attaching to a car or desk dock.
Categories CATEGORY_CAR_DOCK and CATEGORY_DESK_DOCK can be assigned to activities to make them launchable on docked events. This is a better mechanism than listening for ACTION_DOCK_EVENT with a broadcast receiver. Change-Id: Ic5f3ab3555ce02ca922bc31ebba41978cefe8bda Signed-off-by: Mike Lockwood <lockwood@android.com>
This commit is contained in:
@@ -35178,6 +35178,17 @@
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="ACTION_DOCK_EVENT"
|
||||
type="java.lang.String"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value=""android.intent.action.DOCK_EVENT""
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="ACTION_EDIT"
|
||||
type="java.lang.String"
|
||||
transient="false"
|
||||
@@ -35893,6 +35904,17 @@
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="CATEGORY_CAR_DOCK"
|
||||
type="java.lang.String"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value=""android.intent.category.CAR_DOCK""
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="CATEGORY_DEFAULT"
|
||||
type="java.lang.String"
|
||||
transient="false"
|
||||
@@ -35904,6 +35926,17 @@
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="CATEGORY_DESK_DOCK"
|
||||
type="java.lang.String"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value=""android.intent.category.DESK_DOCK""
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="CATEGORY_DEVELOPMENT_PREFERENCE"
|
||||
type="java.lang.String"
|
||||
transient="false"
|
||||
@@ -36123,6 +36156,50 @@
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="EXTRA_DOCK_STATE"
|
||||
type="java.lang.String"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value=""android.intent.extra.DOCK_STATE""
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="EXTRA_DOCK_STATE_CAR"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="2"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="EXTRA_DOCK_STATE_DESK"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="1"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="EXTRA_DOCK_STATE_UNDOCKED"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="0"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="EXTRA_DONT_KILL_APP"
|
||||
type="java.lang.String"
|
||||
transient="false"
|
||||
|
||||
@@ -529,6 +529,8 @@ import java.util.Set;
|
||||
* <li> {@link #CATEGORY_HOME}
|
||||
* <li> {@link #CATEGORY_PREFERENCE}
|
||||
* <li> {@link #CATEGORY_TEST}
|
||||
* <li> {@link #CATEGORY_CAR_DOCK}
|
||||
* <li> {@link #CATEGORY_DESK_DOCK}
|
||||
* </ul>
|
||||
*
|
||||
* <h3>Standard Extra Data</h3>
|
||||
@@ -1861,12 +1863,29 @@ public class Intent implements Parcelable {
|
||||
*/
|
||||
public static final String CATEGORY_FRAMEWORK_INSTRUMENTATION_TEST =
|
||||
"android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST";
|
||||
/**
|
||||
* An activity to run when device is inserted into a car dock.
|
||||
* Used with {@link #ACTION_MAIN} to launch an activity.
|
||||
* To monitor dock state, use {@link #ACTION_DOCK_EVENT} instead.
|
||||
*/
|
||||
@SdkConstant(SdkConstantType.INTENT_CATEGORY)
|
||||
public static final String CATEGORY_CAR_DOCK = "android.intent.category.CAR_DOCK";
|
||||
/**
|
||||
* An activity to run when device is inserted into a car dock.
|
||||
* Used with {@link #ACTION_MAIN} to launch an activity.
|
||||
* To monitor dock state, use {@link #ACTION_DOCK_EVENT} instead.
|
||||
*/
|
||||
@SdkConstant(SdkConstantType.INTENT_CATEGORY)
|
||||
public static final String CATEGORY_DESK_DOCK = "android.intent.category.DESK_DOCK";
|
||||
|
||||
/**
|
||||
* Broadcast Action: The phone was docked or undocked. Includes the extra
|
||||
* field {@link #EXTRA_DOCK_STATE}, containing the current dock state.
|
||||
* @hide
|
||||
* This is intended for monitoring the current dock state.
|
||||
* To launch an activity from a dock state change, use {@link #CATEGORY_CAR_DOCK}
|
||||
* or {@link #CATEGORY_DESK_DOCK} instead.
|
||||
*/
|
||||
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
|
||||
public static final String ACTION_DOCK_EVENT = "android.intent.action.DOCK_EVENT";
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
@@ -2005,28 +2024,24 @@ public class Intent implements Parcelable {
|
||||
* {@link android.content.Intent#EXTRA_DOCK_STATE_UNDOCKED},
|
||||
* {@link android.content.Intent#EXTRA_DOCK_STATE_DESK}, or
|
||||
* {@link android.content.Intent#EXTRA_DOCK_STATE_CAR}.
|
||||
* @hide
|
||||
*/
|
||||
public static final String EXTRA_DOCK_STATE = "android.intent.extra.DOCK_STATE";
|
||||
|
||||
/**
|
||||
* Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
|
||||
* to represent that the phone is not in any dock.
|
||||
* @hide
|
||||
*/
|
||||
public static final int EXTRA_DOCK_STATE_UNDOCKED = 0;
|
||||
|
||||
/**
|
||||
* Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
|
||||
* to represent that the phone is in a desk dock.
|
||||
* @hide
|
||||
*/
|
||||
public static final int EXTRA_DOCK_STATE_DESK = 1;
|
||||
|
||||
/**
|
||||
* Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
|
||||
* to represent that the phone is in a car dock.
|
||||
* @hide
|
||||
*/
|
||||
public static final int EXTRA_DOCK_STATE_CAR = 2;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.server;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
@@ -111,6 +112,30 @@ class DockObserver extends UEventObserver {
|
||||
Intent intent = new Intent(Intent.ACTION_DOCK_EVENT);
|
||||
intent.putExtra(Intent.EXTRA_DOCK_STATE, mDockState);
|
||||
mContext.sendStickyBroadcast(intent);
|
||||
|
||||
// Launch a dock activity
|
||||
String category;
|
||||
switch (mDockState) {
|
||||
case Intent.EXTRA_DOCK_STATE_CAR:
|
||||
category = Intent.CATEGORY_CAR_DOCK;
|
||||
break;
|
||||
case Intent.EXTRA_DOCK_STATE_DESK:
|
||||
category = Intent.CATEGORY_DESK_DOCK;
|
||||
break;
|
||||
default:
|
||||
category = null;
|
||||
break;
|
||||
}
|
||||
if (category != null) {
|
||||
intent = new Intent(Intent.ACTION_MAIN);
|
||||
intent.addCategory(category);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
try {
|
||||
mContext.startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Log.w(TAG, e.getCause());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user