1.禁用StatusBar相关功能
需要添加权限
<uses-permission android:name="android.permission.STATUS_BAR"></uses-permission>
enum StatusBarCmd {
DISABLE_EXPAND,
DISABLE_NONE,
DISABLE_RECENT,
DISABLE_NOTIFICATION_ICONS
}
public static void disableStatusBar(Context context, StatusBarCmd cmd) {
try {
Object service = context.getSystemService("statusbar");
Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
Method disable = statusbarManager.getMethod("disable",int.class);
disable.setAccessible(true);
Field disable_expand = statusbarManager.getField(cmd.name());
disable_expand.setAccessible(true);
int disable_code = disable_expand.getInt(statusbarManager);
Log.d("YYY","disable code = "+disable_code);
disable.invoke(service,disable_code);
}catch (Exception ex) {
ex.printStackTrace();
}
}
2.代码动态切换launcher
需要权限
<uses-permission android:name="android.permission.FORCE_STOP_PACKAGES"></uses-permission>
private void switchLauncher(Context context,ComponentName activity) {
PackageManager pm = context.getPackageManager();
Log.d("YYY","switch launcher "+activity);
try {
Class<?> packageManager = Class.forName("android.content.pm.PackageManager");
Method replacePreferedActivity = packageManager.getMethod("replacePreferredActivity",IntentFilter.class,int.class,ComponentName[].class,ComponentName.class);
IntentFilter homeFilter = new IntentFilter(Intent.ACTION_MAIN);
homeFilter.addCategory(Intent.CATEGORY_HOME);
homeFilter.addCategory(Intent.CATEGORY_DEFAULT);
List<ResolveInfo> resolveInfos = new ArrayList<ResolveInfo>();
ComponentName curLauncher = listHomeActivitys(context,resolveInfos);
if(resolveInfos != null && resolveInfos.size() > 0) {
ComponentName[] componentNames = new ComponentName[resolveInfos.size()];
for(int i =0 ; i<resolveInfos.size();i++) {
ActivityInfo activityInfo = resolveInfos.get(i).activityInfo;
if(activityInfo != null) {
ComponentName cn = new ComponentName(activityInfo.packageName, activityInfo.name);
componentNames[i] = cn;
Log.d("YYY","launcher:"+cn);
}
}
replacePreferedActivity.setAccessible(true);
replacePreferedActivity.invoke(pm,homeFilter,IntentFilter.MATCH_CATEGORY_EMPTY,componentNames,activity);
killPackage(context,curLauncher.getPackageName());
}else {
Log.e("YYY","get home resolve info empty");
}
} catch (Exception e) {
Log.e("YYY",""+e);
e.printStackTrace();
}
}
private ComponentName listHomeActivitys(Context context,List<ResolveInfo> outs){
PackageManager pm = context.getPackageManager();
Object cn = null;
try {
Class<?> packageManager = Class.forName("android.content.pm.PackageManager");
Method getHomeActivities = packageManager.getMethod("getHomeActivities",List.class);
getHomeActivities.setAccessible(true);
cn = getHomeActivities.invoke(pm,outs);
}catch (Exception e) {
Log.e("YYY",""+e);
e.printStackTrace();
}
return (ComponentName) cn;
}
private void killPackage(Context context,String pkg) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
am.killBackgroundProcesses(pkg);
}
3.挂断通话
public static void endCall(Context context) {
TelecomManager telecomManager = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
try {
SmartRft.invokeMethod(telecomManager,"endCall");
} catch (Exception e) {
e.printStackTrace();
}
}