PCHunter 打开后 随便点一个进程右键,查看-查看进程热键-再右键-显示所有进程热键
作者:root
Android判断应用在前台和切换应用到前台的方法
/**
* 判断应用在前台
*/
public static boolean isForeground(Context context) {
boolean isForeground = false;
ActivityManager activityManager = (ActivityManager) context.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
if (activityManager != null) {
ComponentName componentName = activityManager.getRunningTasks(1).get(0).topActivity;
if (componentName != null) {
isForeground = componentName.getPackageName().equals(context.getPackageName());
}
}
if (isForeground) {
isForeground = isForegroundByProcess();
}
return isForeground;
}
/**
* 根据进程判断应用在前台
*/
private static boolean isForegroundByProcess() {
boolean isForeground = true;
String filePath = "/proc/" + android.os.Process.myPid() + "/cgroup";
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
String line = br.readLine();
if (line != null && line.contains("bg_non_interactive")) {
isForeground = false;
}
} catch (IOException e) {
e.printStackTrace();
}
return isForeground;
}
/**
* 切换应用到前台
*/
public static void switchToForeground(Context context) {
ActivityManager activityManager = (ActivityManager) context.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> taskInfoList = activityManager.getRunningTasks(100);
for (ActivityManager.RunningTaskInfo taskInfo : taskInfoList) {
ComponentName componentName = taskInfo.topActivity;
if (componentName != null && componentName.getPackageName().equals(context.getPackageName())) {
activityManager.moveTaskToFront(taskInfo.id, 0);
break;
}
}
}
参考资料:
微信数据库解密
节选自:微信数据库解密
- 微信数据库加密方式:
1.获取手机IMEI码 2.获取当前登录微信账号的uin(存储在sp里面) 3.拼接IMEI和uin 4.将拼接完的字符串进行md5加密 5.截取加完密的字符串的前七位(字母必须为小写) 上面可以看到就两个变量,`uin`和`imei`
代码送上直接使用:https://github.com/l123456789jy/WxDatabaseDecryptKey
Android点击EditText文本框之外任意位置隐藏键盘
实现思路:通过 dispatchTouchEvent 每次 ACTION_DOWN 事件中动态判断非 EditText 本身区域的点击事件,然后在事件中进行屏蔽。
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
getWindow().getDecorView().postDelayed(() -> {
View view = getCurrentFocus();
if (isShouldHideInput(view, ev)) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
view.clearFocus();
}
}
}, 100);
}
return super.dispatchTouchEvent(ev);
}
private boolean isShouldHideInput(View v, MotionEvent event) {
if (v instanceof EditText) {
int[] leftTop = new int[]{0, 0};
//获取输入框当前的location位置
v.getLocationInWindow(leftTop);
int left = leftTop[0];
int top = leftTop[1];
int bottom = top + v.getHeight();
int right = left + v.getWidth();
return !(event.getRawX() > left && event.getRawX() < right && event.getRawY() > top && event.getRawY() < bottom);
}
return false;
}
参考链接:
Android取消EditText自动默认获取焦点行为
转载自:Android取消EditText自动默认获取焦点行为
Android控件EditText自动默认会获取屏幕焦点,取消这个行为只需要两行代码,如下:
android:focusable="true" android:focusableInTouchMode="true"
我们只需要把这两行代码添加至EditText控件的父级控件中,把屏幕焦点设置到父级控件上,EditText就会暂时失去焦点。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
<EditText
android:id="@+id/et_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Netty 相关文章
Android 判断网络连接是否可用
/**
* 判断网络是否已连接
*/
public static boolean isConnected(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
if (info != null) {
return info.isConnected();
}
return false;
}
/**
* 使用ping判断网络连接
*/
public static boolean ping() {
try {
Process process = Runtime.getRuntime().exec("ping -c 1 www.baidu.com");
int exitCode = process.waitFor();
return (exitCode == 0);
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
Android Gradle 相关文章
ProductFlavors 简单使用
概述
我们在开发过程中,会经常遇到,同样的业务逻辑,需要配置不同的资源的情况。有时是不同的渠道,有时是不同的语言环境,各种不同。
如果我们在业务逻辑中,去实现这些差异化,会导致两个问题:
- 代码量很大,分支路径很多。而很多路径在实际使用中是用不到的,造成代码质量差。
- 用业务逻辑去区分情况加载资源,会导致包内需要包含大量的资源,造成包体积过大。
所以,我们需要在编译阶段,就区分种种情况,给予相应的资源。
Android中build.gradle的productFlavors为我们提供了这样的能力。
快速使用
在module的build.gradle中,我们通过flavorDimensions和productFlavors的配合,来实现多维度的区分:
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.oceanlong.buildtestpro"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
...
flavorDimensions "country"
productFlavors {
china {
applicationId "com.example.oceanlong.buildtestfree"
dimension "country"
}
usa {
applicationId "com.example.oceanlong.buildtestpro"
dimension "country"
}
}
...
}
adb logcat 命令行用法
adb logcat -v time -s TAG