强制关闭指定包名的app
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List appProcessInfos = activityManager
.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo appProcessInfo:appProcessInfos) {
if( !appProcessInfo.processName.contains("PackageName"))
continue;
String[] pkNameList=appProcessInfo.pkgList;
for(int i=0;i<pkNameList.length;i++){
String pkName=pkNameList[i];
activityManager.killBackgroundProcesses(pkName);
}
熄灭屏幕
private void closeScreen(Context context){
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); pm.goToSleep(SystemClock.uptimeMillis(), PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
}
apn设置
public static final Uri APN_URI = Uri.parse("content://telephony/carriers");
public static final Uri CURRENT_APN_URI = Uri
.parse("content://telephony/carriers/preferapn");
private void setApn(Context context,Intent intent){
Bundle bundle = intent.getExtras();
String _name = bundle.getString("name");
String _apn = bundle.getString("apn");
String _mcc = bundle.getString("mcc");
String _mnc = bundle.getString("mnc");
if(null==_name||null==_apn||null==_mcc||null==_mnc)
return;
String NUMERIC = getSIMInfo(context);
if (null==NUMERIC) {
return;
}
ContentResolver resolver = context.getContentResolver();
ContentValues values = new ContentValues();
values.put("name", _name);
values.put("apn", _apn);
values.put("mcc", _mcc);
values.put("mnc",_mnc);
Cursor c = null;
Uri newRow = resolver.insert(APN_URI, values);
int id =-1;
if (newRow != null) {
c = resolver.query(newRow, null, null, null, null);
int idIndex = c.getColumnIndex("_id");
c.moveToFirst();
id = c.getShort(idIndex);
}
if (c != null)
c.close();
ContentValues values1 = new ContentValues();
values1.put("apn_id", id);
resolver.update(CURRENT_APN_URI, values1, null, null);
}
private String getSIMInfo(Context context){
TelephonyManager iPhoneManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return iPhoneManager.getSimOperator();
}
静默安装apk
private void installApp(Context context,Intent intent){
Bundle bundle = intent.getExtras();
String apkPath = bundle.getString("apkPath");
PackageManager pm = context.getPackageManager();
String[] args = { "pm", "install", "-r", apkPath };
String result = "";
ProcessBuilder processBuilder = new ProcessBuilder(args);
Process process = null;
InputStream errIs = null;
InputStream inIs = null;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int read = -1;
process = processBuilder.start();
errIs = process.getErrorStream();
while ((read = errIs.read()) != -1) {
baos.write(read);
}
baos.write('\n');
inIs = process.getInputStream();
while ((read = inIs.read()) != -1) {
baos.write(read);
}
byte[] data = baos.toByteArray();
result = new String(data);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (errIs != null) {
errIs.close();
}
if (inIs != null) {
inIs.close();
}
} catch (IOException e) {
e.printStackTrace();
}
if (process != null) {
process.destroy();
}
}
}
卸载apk
private void uninstallApp(Context context, Intent intent){
Bundle bundle = intent.getExtras();
String appPackageName = bundle.getString("packageName");
PackageManager pm = context.getPackageManager();
IPackageDeleteObserver observer = new MyPackageDeleteObserver();
pm.deletePackage(appPackageName, observer, 0);
}
class MyPackageDeleteObserver extends IPackageDeleteObserver.Stub {
@Override
public void packageDeleted(String packageName, int returnCode) {
}
}
写节点
String path="节点路径"
try {
BufferedWriter bufWriter = null;
bufWriter = new BufferedWriter(new FileWriter(path));
bufWriter.write(value + "");
bufWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
修改默认窗口动画效果
frameworks\base\services\core\java\com\android\server\wm\WindowManagerService.java
float mWindowAnimationScaleSetting = 1.0f;
float mTransitionAnimationScaleSetting = 1.0f;
float mAnimatorDurationScaleSetting = 1.0f;
网友评论