开发者

Android private API

开发者 https://www.devze.com 2023-02-13 08:13 出处:网络
I know this sounds strange earlier I asked about similar question in one of my question I tried the way I was advised but after installing my app if I press home key then it opens up complete action u

I know this sounds strange earlier I asked about similar question in one of my question I tried the way I was advised but after installing my app if I press home key then it opens up complete action using dialog with default launcher app and my app.

As asked in above 开发者_如何学Cquestion however in Car home app it never let you reach home screen though it never ask you to replace the launcher using complete action.

So my question is if its registering itself as launcher how it is bypassing that dialog.


The short answer is that you won't be able to do what you want to do. Only a Launcher/Car Dock/Desk Dock program can act on the Home button, and that's only when in the appropriate mode (In a car dock, in a desktop dock, or other).

Long Answer:

The Home button in Android basically has three behaviors. It can either launch the Home or launch the Car Dock or launch the Desk Dock. This is seen in: android/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

When the Home button is hit, it tries to find out which intent to use with this function:

/**
 * Return an Intent to launch the currently active dock as home.  Returns
 * null if the standard home should be launched.
 * @return
 */
Intent createHomeDockIntent() {
    Intent intent;

    // What home does is based on the mode, not the dock state.  That
    // is, when in car mode you should be taken to car home regardless
    // of whether we are actually in a car dock.
    if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
        intent = mCarDockIntent;
    } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
        intent = mDeskDockIntent;
    } else {
        return null;
    }

    ActivityInfo ai = intent.resolveActivityInfo(
            mContext.getPackageManager(), PackageManager.GET_META_DATA);
    if (ai == null) {
        return null;
    }

    if (ai.metaData != null && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
        intent = new Intent(intent);
        intent.setClassName(ai.packageName, ai.name);
        return intent;
    }

    return null;
}

So if the phone is in a car dock or a desktop dock, indeed the launcher can be bypassed. But normally, when in no such dock, the launcher will be called.

If you're curious these are the intents. They're not hard coded for specific apps, but the default app for that category will be used.

    mHomeIntent =  new Intent(Intent.ACTION_MAIN, null);
    mHomeIntent.addCategory(Intent.CATEGORY_HOME);
    mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
            | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

    mCarDockIntent =  new Intent(Intent.ACTION_MAIN, null);
    mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
    mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
            | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

    mDeskDockIntent =  new Intent(Intent.ACTION_MAIN, null);
    mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
    mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
            | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号