RK3288平台Android6.0系统修改默认Launcher

修改文件:

frameworks/base/core/java/com/android/internal/app/ResolverActivity.java

public class ResolverActivity extends Activity {
……//此处省略好多行
private static final String DEFAULT_HOME = "persist.sys.default.home";
……//此处省略好多行
    protected void onCreate(Bundle savedInstanceState, Intent intent,
            CharSequence title, int defaultTitleRes, Intent[] initialIntents,
            List rList, boolean alwaysUseOption) {
        setTheme(R.style.Theme_DeviceDefault_Resolver);
        super.onCreate(savedInstanceState);
        ……//此处省略好多行
        setupDefaultLauncher(); //封装一个设置默认桌面的函数
        ……//此处省略好多行
    }
……//此处省略好多行
    private void setupDefaultLauncher() {
        String first = "";
        try{
            first =  SystemProperties.get(DEFAULT_HOME);
        }catch(Exception e){
            Log.w(TAG,"exception error get DEFAULT_HOME");
        }
        int position = mAdapter.getDefaultHomePosition("com.XXX.home");//在此处获取指定包名的Launcher的位置,mAdapter是ResolveListAdapter的引用
        if (position == -1) {
            if (DEBUG)
                Log.w(TAG,"not find default Home");
            return;
        }
        ResolveInfo ri = mAdapter.resolveInfoForPosition(position, true);
        TargetInfo intent = mAdapter.targetInfoForPosition(position, true);
        onTargetSelected(intent, false);
        try{
            SystemProperties.set(DEFAULT_HOME,DEFAULT_HOME);
        }catch(Exception e){
            Log.w(TAG,"exception error set DEFAULT_HOME");
        }
        startSelected(position, true, true);
        dismiss();
}

    public int getDefaultHomePosition(String packageName){
        for (int i = 0; i < mDisplayList.size(); i++) {
            ResolveInfo info = mDisplayList.get(i).mResolveInfo;
            if (DEBUG)
                Log.w(TAG,"getDefaultHomePosition " + info.activityInfo.packageName);
            if (info.activityInfo.packageName.equals(packageName)) {
                return i;
            }
        }
        return -1;
    }
……//此处省略好多行
}

 

你可能感兴趣的:(Android开发)