- 浏览: 214984 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (196)
- android (153)
- sqlite (1)
- java (3)
- os (4)
- tools (4)
- ResolveInfo 转 packageinf 取信息 (1)
- multimedia (2)
- fastboot (1)
- create user in samba (0)
- android qcn (0)
- windows (0)
- net (2)
- linux (1)
- git (0)
- proguard (0)
- android cpu (1)
- android gts (1)
- MySql (1)
- c/c++ (0)
- network (1)
- python (3)
- AI (1)
- Ultroedit (1)
- HarmonyOS NEXT (0)
from: http://stackoverflow.com/questions/3836215/android-change-default-home-application
Method installPackageMethod = null;
Method deletePackageMethod = null;
Method setPreferredActivityMethod = null;
Method replacePreferredActivityMethod = null;
Object pm = null;
@Override
public void onCreate() {
super.onCreate();
if (pm == null)
pm = getPackageManager();
try {
if (setPreferredActivityMethod == null)
setPreferredActivityMethod = pm.getClass().getMethod(
"addPreferredActivity", IntentFilter.class, int.class,
ComponentName[].class, ComponentName.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
private final class ServiceHandler extends Handler {
private Context context;
public ServiceHandler(Looper looper, Context ctx) {
super(looper);
context = ctx;
}
@Override
public void handleMessage(Message msg) {
Intent intent = (Intent) msg.getData().getParcelable(
UPDATER_SERVICE_ACTION);
int request = intent.getIntExtra(
REQUEST_KEY,
REQUEST_UNKNOWN);
Bundle bundle = intent.getExtras();
switch (request) {
case INSTALL_APPLICATION: {
if (bundle != null) {
String appPath = bundle
.getString(APP_PATH_KEY);
if (appPath != null) {
LogUtil.e(TAG, "try to install " + appPath);
try {
am.installPackage(appPath);
} catch (Exception e) {
e.printStackTrace();
}
LogUtil.e(TAG, "install of " + appPath + " done");
}
}
break;
}
case UNISTALL_PACKAGE: {
if (bundle != null) {
String packagename = bundle
.getString(PACKAGE_NAME_KEY);
if (packagename != null) {
LogUtil.e(TAG, "unistall " + packagename);
try {
deletePackageMethod
.invoke(pm, packagename, null, 0);
} catch (Exception e) {
e.printStackTrace();
}
}
}
break;
}
case SET_PREFERRED_LAUNCHER: {
if (bundle != null) {
String package_name = bundle
.getString(PREFERRED_PACKAGE_KEY);
if (package_name == null) {
LogUtil.e(TAG,
"WARNING: setDefaultActivity cannot continue, package is NULL");
return;
}
String activity_name = bundle
.getString(PREFERRED_ACTIVITY_KEY);
if (activity_name == null) {
LogUtil.e(TAG,
"WARNING: setDefaultActivity cannot continue, activity is NULL");
return;
}
LogUtil.e(TAG, "setDefaultActivity activity="
+ activity_name + " package=" + package_name);
IntentFilter filter = new IntentFilter(
"android.intent.action.MAIN");
filter.addCategory("android.intent.category.HOME");
filter.addCategory("android.intent.category.DEFAULT");
ComponentName[] components = new ComponentName[] {
new ComponentName("com.android.launcher",
"com.android.launcher2.Launcher"),
new ComponentName(package_name, activity_name) };
ComponentName activity = new ComponentName(package_name,
activity_name);
try {
setPreferredActivityMethod.invoke(pm, filter,
IntentFilter.MATCH_CATEGORY_EMPTY, components,
activity);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
}
发表评论
-
Android SnappyDB
2018-05-15 11:23 965https://blog.csdn.net/qq_214305 ... -
使用UncaughtExceptionHandler保存全局异常(转)
2018-05-07 15:04 644From: https://blog.csdn.net/dre ... -
android udp
2018-04-10 19:47 605Android之Socket的基于UDP传输 接收方创建步骤: ... -
android DownloadManager
2018-04-10 12:52 597From: https://www.jianshu.com/p ... -
Snackbar 可以交互的Toast
2018-04-08 21:44 765Snackbar 是 Android design sup ... -
android 操作串口
2018-03-19 18:20 661http://blog.csdn.net/akunainian ... -
proguard对 android-support-v4.jar 的配置
2018-03-16 15:32 725-libraryjars libs/android-sup ... -
apk 多个dex
2018-03-16 10:05 1008android studio 配置应用生成多个dex ... -
ddmlib 解决android n file explorer 为空问题
2018-03-16 09:27 939百度云:http://pan.baidu.com/s/1sl4 ... -
android 代码混淆
2018-03-15 08:38 1056打开混淆开关 Android.mk ... -
menu item 显示icon
2018-03-07 09:32 686@Override public boolean onMenu ... -
ubuntu 脚本切换root用户,并执行其它脚本
2018-03-05 09:58 0#!/bin/bash expect -c" ... -
DrawerLayout 滑动侧边栏
2018-03-01 10:42 0// TODO -
jack-server 多用户编译问题
2018-02-27 10:44 14043),需要同时修改 $HOME/.jack-server/co ... -
更新eclipse 遇到两个问题 Oxygen.2 Release (4.7.2)
2018-02-26 14:28 12311. the file dx.jar was not load ... -
监听系统开关变化
2018-02-05 14:02 814// 转屏开关 /** * Content obse ... -
android 8.0 模块编译命令
2018-02-02 14:42 1172Invoke ". build/envsetup.s ... -
svn checkout 忽略某个文件夹
2018-01-26 11:14 1367android源码更新时, frameworks\compil ... -
eclipse jni
2018-01-19 16:10 494试过,可以运行 http://blog.csdn.net/sb ... -
opencv for android
2018-01-19 14:37 440http://blog.csdn.net/sbsujjbcy/ ...
相关推荐
If operator forgets his password then administrator can change it to default password. i.e. op which is defined in this application. Logs ---- This application also logs Log in time and log out time ...
Using the Terminal Application: hotdog:/Users/Motoma/ motoma$ python pyloris-3.0.py motomastyle.com Using HTTPLoris in Windows is a little different. One will need to know the location of the ...
This is a big change from 1.4.2. Please read the smali updates here for more information -o / --output is now used for the output of apk/directory -t / --tag is required for tagging framework files...
"BEA Home"=[Enter new value or use default "/bea/weblogic/bea"] ``` **操作指导:** - 按回车键继续使用默认值。 ##### 4. 选择产品组件 在此步骤,用户可以选择安装哪些 WebLogic 组件。每个组件都提供了相应...
Z-Stack支持多种Zigbee应用框架,例如Smart Energy Profile (SEP)、Home Automation (HA)、Commercial Building Automation (CBA)等。 #### 二、Sample Application详解 在Z-Stack CC2430 DB和CC2430 EB开发板上的...
LSIP200232954 (DFCT) Need to Support all the MFC default values in the command AdpSettings. LSIP200245968 (DFCT) In EFICLI not able to flash latest firmware to controller without using -nosigchk -...
Add/delete entries from INI files, load pictures, change strings, dail phone numbers, send emails, view home pages, and more. Must see.<END><br>31 , fldrvw21.zip FolderView ActiveX Control 2.1 ...
returns default PrinterPreview object and shows data in default preview form. TDBEditEh component represents a single or multi-line edit control that can display and edit a field in a dataset or ...
returns default PrinterPreview object and shows data in default preview form. TDBEditEh component represents a single or multi-line edit control that can display and edit a field in a dataset or ...
SQL>select username,default_tablespace from user_users; 查看当前用户的角色 SQL>select * from user_role_privs; 查看当前用户的系统权限和表级权限 SQL>select * from user_sys_privs; SQL>select * ...
A quick reference guide to UltraEdit's default keyboard shortcuts Keymapping and custom hotkeys How to customize 键映射s and menu hotkeys Column Markers The benefit of a column maker is that it can ...
For example, she can easily change the phrase “Alice, I owe you $1000” to “Alice, I owe you $10,000”. Furthermore, Trudy can even drop the packets that are being sent by Bob to Alice (and vise-...
-t 允许安装 AndroidManifest.xml 里 application 指定 android:testOnly="true" 的应用 -s 将应用安装到 sdcard -d 允许降级覆盖安装 -g 授予所有运行时权限 运行命令后如果见到类似如下输出(状态为 Success)代表...
returns default PrinterPreview object and shows data in default preview form. TDBEditEh component represents a single or multi-line edit control that can display and edit a field in a dataset or ...
If you can provide me with a minimal application which reproduces the problem, I can almost guarantee that I will be able to fix the problem in very short time. Please supply only the source files ...
21.zip Parse phone fields 解析电话区域(11KB)<END><br>22,22.zip Changing the default file open/save dialogs in an MFC doc/view application 初始化对话框和支持动态数据交换(DDX)(15KB)<END><br>...
returns default PrinterPreview object and shows data in default preview form. TDBEditEh component represents a single or multi-line edit control that can display and edit a field in a dataset or ...
private final static String rootPath = System.getProperty("user.home")+File.separator+fileDir+File.separator; @RequestMapping("/upload") public Object uploadFile(@RequestParam("file") ...