Last active
July 12, 2022 09:13
-
-
Save iflove/a6bc1ee5c611358126d01b89ebac837e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
代码复制板 |
pm(Package Manager)
判断安装包已安装并可用
public static boolean isAppInstalledAndEnabled(Context context, String packageName) {
PackageInfo packageInfo;
ApplicationInfo applicationInfo = null;
try {
packageInfo = context.getPackageManager().getPackageInfo(packageName, 0);
applicationInfo = context.getPackageManager().getApplicationInfo(packageName, 0);
} catch (PackageManager.NameNotFoundException e) {
packageInfo = null;
e.printStackTrace();
}
return packageInfo != null && applicationInfo != null && applicationInfo.enabled;
}
GridLayout
layout = new GridLayout(getActivity());
layout.setPrinter(null); //GridLayout日志开关
网络相关
HttpURLConnection
记得释放:getInputStream
ssl
javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x69002d40: Failure in SSL library, usually a protocol error
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:741 0x67024d74:0x00000000)
https单向认证问题
android 4.4没有启用TLSv1.1 和 TLSv1.2 传输层安全协议
https://developer.android.com/reference/javax/net/ssl/SSLSocket
屏幕适配
Configuration config = getResources().getConfiguration();
int smallestScreenWidth = config.smallestScreenWidthDp;
Log.i("SW","smallest width : "+ smallestScreenWidth);
sw = 屏幕宽度 / (dpi/160)
{1.0 dualscreenflag=DISABLE ?mcc?mnc [zh_CN_#Hans] ldltr sw800dp w800dp h1208dp 160dpi xlrg port -touch qwerty/v/h -nav/h s.4}
/**
* 得到屏幕的物理尺寸,由于该尺寸是在出厂时,厂商写死的,所以仅供参考
* 计算方法:获取到屏幕的分辨率:point.x和point.y,再取出屏幕的DPI(每英寸的像素数量),
* 计算长和宽有多少英寸,即:point.x / dm.xdpi,point.y / dm.ydpi,屏幕的长和宽算出来了,
* 再用勾股定理,计算出斜角边的长度,即屏幕尺寸。
* @param context
* @return
*/
public static double getPhysicsScreenSize(Context context){
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Point point = new Point();
manager.getDefaultDisplay().getRealSize(point);
DisplayMetrics dm = context.getResources().getDisplayMetrics();
int densityDpi = dm.densityDpi;//得到屏幕的密度值,但是该密度值只能作为参考,因为他是固定的几个密度值。
double x = Math.pow(point.x / dm.xdpi, 2);//dm.xdpi是屏幕x方向的真实密度值,比上面的densityDpi真实。
double y = Math.pow(point.y / dm.ydpi, 2);//dm.xdpi是屏幕y方向的真实密度值,比上面的densityDpi真实。
double screenInches = Math.sqrt(x + y);
return screenInches;
}
调试相关
程序是否调试
if (!Debug.isDebuggerConnected()) {//判断当前应用有没有被调试
//超时操作
}
Application hook
Application get() {
try {
@SuppressLint("PrivateApi") final Class<?> activityThreadClass = Class.forName("android.app.ActivityThread");
final Method method = activityThreadClass.getMethod("currentApplication");
return (Application) method.invoke(null, (Object[]) null);
} catch (final ClassNotFoundException | NoSuchMethodException | IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
// handle exception
}
return null;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.