![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Android
痞子小小崔
QQ:962935348
展开
-
【代码块】Android APP自动安装并重启
自动安装apk 或 静默安装原创 2022-03-01 11:02:43 · 1722 阅读 · 0 评论 -
Kotlin多维数组使用copyOf()的注意事项
多维数组直接使用copyOf() 会导致内元素地址覆盖,也就是改变其中一项数据会导致另一数据内数据也发生变化,即 === 判定为true原创 2021-06-03 16:08:03 · 697 阅读 · 0 评论 -
【简单封装】OkHttp(包含cookie)
PzOkHttp类public class PzOkHttp { private static final String TAG = "PzOkHttp"; private OkHttpClient client; public PzOkHttp() { client = new OkHttpClient.Builder() .connectTimeout(15, TimeUnit.SECONDS)//设置连接超时时间原创 2021-03-16 11:38:47 · 242 阅读 · 0 评论 -
【简单封装】Android实现USB转232通讯
封装类:PzHelpUSBclass PzHelpUSB implements SerialInputOutputManager.Listener { private static final String TAG = "PzHelpUSB"; Context context; UsbSerialPort usbSerialPort = null; SerialInputOutputManager usbIoMana原创 2021-03-10 16:47:56 · 1019 阅读 · 6 评论 -
【代码块】沉浸式界面
顶部状态栏与底部导航栏不会占据显示控件,并在界面获取焦点后隐藏/** * 沉浸式页面 * * @param hasFocus 焦点 */@Overridepublic void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if (hasFocus &...原创 2020-03-28 14:39:05 · 209 阅读 · 0 评论 -
【代码块】OkHttp下载文件
/** * 下载文件 * * @param url 文件网络路径 * @param filePath 文件下载本地路径 * @param fileName 文件名称(包含后缀) * @param callBack 回调 */public void okHttpDownloadFile(String url, String filePath, String fileName, final CallBackDownloadFile callBack) { final File原创 2021-02-24 11:56:48 · 665 阅读 · 0 评论 -
【代码块】字符串转时间戳
/** * 字符串转时间戳 * * @param dateString 待转字符串 * @param pattern 时间字符串格式 * @return 时间戳 */@SuppressLint("SimpleDateFormat")long stringToTimestamp(String dateString, String pattern) { SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);原创 2021-01-08 10:25:34 · 102 阅读 · 0 评论 -
【代码块】固定长度的串口byte数据解析参考(modbus等)
@RequiresApi(api = Build.VERSION_CODES.N)@Overridepublic void onNewData(byte[] data) { /** * 例如:01 03 12 34 00 01 C0 BC * 01 03为固定数据 * 12 34为编号 * 00 01为数据,最大值FF FF(十进制65535) * C0 BC为CRC校验码,低位在前 */ //将收到的数据添加到缓冲区原创 2020-11-19 10:07:28 · 428 阅读 · 0 评论 -
【代码块】跳至网络设置界面(WIFI与LAN)
跳转网络设置界面(包含wifi与lan)/*** 显示网络设置界面*/private void showNetworkActivity() { ComponentName componentName = new ComponentName("com.android.tv.settings", "com.android.tv.settings.connectivity.NetworkActivity"); Intent intent = new Intent(); intent.se原创 2020-11-23 11:28:27 · 452 阅读 · 0 评论 -
【代码块】带标签的字符串数据解析参考
/** * 数据检查 * * @param response 数据源 * @param checkStar 数据头标签 * @param checkEnd 数据尾标签 * @return 数据 */String responseChecker(String response, String checkStar, String checkEnd) { int star = response.indexOf(checkStar); int end = response.ind原创 2020-11-05 17:28:44 · 177 阅读 · 0 评论 -
TextView文字对齐(不同空白间隔的效果)
typeface="monospace"模式下:1个中文 = 1个 3个中文 = 5个  ,另外  =   =   =  非typeface="monospace"模式下:1个中文 = 2个  = 4个  = 4个  = 5个 ...原创 2020-10-17 16:00:16 · 360 阅读 · 0 评论 -
【简释】RecyclerView——OnScrollListener
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { /** * 滚动时回调 * @param recyclerView RecyclerView * @param newState 状态 * 0:SCROLL_STATE_IDLE: 结束,不处于滚动状态(The RecyclerV原创 2020-10-10 17:20:20 · 721 阅读 · 1 评论 -
【开发问题】Android——Fragment must be a public static class to be properly recreated from instanc
译文:Fragment 必须是公共静态类才能从实例状态正确地重新创建解决:public class SettingDialogFragment extends DialogFragment:添加 public 即可原创 2020-09-25 13:45:35 · 677 阅读 · 0 评论 -
【开发问题】Android——Adapter:IndexOutOfBoundsException: Inconsistency detected
数据源增删后应当随机刷新Adapter报错信息:IndexOutOfBoundsException: Inconsistency detected.原因和解决办法:在对绑定数据源,比如List进行增删操作后,应当随机进行一次刷新。尤其是删除或清空操作,否则会导致底层报错,程序崩溃。...原创 2020-09-15 16:03:41 · 345 阅读 · 0 评论 -
【简释】ViewPager——OnPageChangeListener
ViewPager.SimpleOnPageChangeListener mPageChangeListener = new ViewPager.SimpleOnPageChangeListener() { /** * 当页面滚动时触发 * @param position 切换过程中左侧页面的position * @param positionOffset 切换过程中左侧页面消失部分的比例 * @param positionOffsetPixels 切换过程中原创 2020-09-01 16:32:49 · 490 阅读 · 0 评论 -
【开发问题】HorizontalBarChart渐变色无效的问题
PS:渐变无效其实是BUG,直到2020年1月24号才解决,而目前的3.1.0版本是在19年打包的,所以需要手动下载源码并导入项目,导入module我就不阐述了源码地址:https://github.com/PhilJay/MPAndroidChart使用Fill:import com.github.mikephil.charting.utils.Fill;... ...List<Fill> mGradientColors = new ArrayList<>();...原创 2020-08-08 13:47:13 · 282 阅读 · 0 评论 -
【快速使用】解决USB权限弹窗——无障碍
一、简介别人的设备与系统,自己无能力修改源码,只能寻求其他手段,在网上看到有人说道“无障碍”,便开始试一试,发现是可行的,比adb好用多了;二、使用新建类 MyAccessibilityServicepublic class MyAccessibilityService extends AccessibilityService { String TAG = "AliAccessibilityService"; /** * event: EventType: TYP原创 2020-08-03 09:02:16 · 2161 阅读 · 8 评论 -
Android刷新UI导致崩溃的探究——Only the original thread
结论:Only the original thread that created a view hierarchy can touch its views不能粗暴的理解为由于刷新UI导致的,而是由于刷新修改View大小导致的,如果你的View设定了固定的长宽是不会出现这个错误的。当大小设置为wrap_content后,每次setText都会重新计算View的长宽并刷新,这会导致执行requestLayout方法,而这个方法需要执行checkThread方法,导致报错也就是在长宽设定为非wrap_con原创 2020-07-25 13:33:21 · 606 阅读 · 0 评论 -
Android设置主屏幕应用(桌面程序)
在 AndroidManifest.xml 内 activity 的 intent-filter 标签内添加<category android:name="android.intent.category.HOME"/><category android:name="android.intent.category.DEFAULT" />原创 2020-07-24 09:22:13 · 11657 阅读 · 0 评论 -
TextView——行间距与字母间隔
一、设置行间距android:lineSpacingExtra设置行间距,尺寸值是一个浮点数,后跟一个单位,例如“ 14.5sp”Extra spacing between lines of text. Must be a dimension value, which is a floating point number appended with a unit such as “14.5sp”.Available units are: px (pixels), dp (density-inde原创 2020-07-22 13:34:19 · 278 阅读 · 0 评论 -
【自定义View】自动滚动的TextView(跑马灯)——可获取完成一次滚动后的监听
AutoRollTextViewByRunnable类class AutoRollTextViewByRunnable extends androidx.appcompat.widget.AppCompatTextView implements Runnable { String TAG = "MarqueeText"; private int currentScrollX = 0;// 当前滚动的位置 private int textWidth; private int原创 2020-07-18 01:24:07 · 733 阅读 · 0 评论 -
Android Studio使用Lambda
jdk 8或更高版本在build.gradle内添加即可android { compileOptions{ sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }原创 2020-07-13 16:29:51 · 148 阅读 · 0 评论 -
RecyclerView内布局使用weight无效的解决方案
问题:如果使用的是LinearLayout,并内部使用了weight属性,会导致RecyclerView最终效果与weight不一致。解决:在LinearLayout外部套一层其他布局即可原创 2020-07-07 09:57:57 · 1100 阅读 · 0 评论 -
【开发问题】usb-serial-for-android
程序重启后无法再次读取USB设备插入USB设备,程序运行,一切正常。关闭程序再次打开,设备与端口皆可获取,直到Port.open(connection)出错使用的是RK3188 5.1系统传感器为体温传感器,使用此开源CH34转USB/MainActivity: connection: android.hardware.usb.UsbDeviceConnection@3b3b49f1...原创 2020-03-14 16:06:48 · 1747 阅读 · 2 评论 -
【自定义控件】EditText实现自动焦点(输入法的自动显示与隐藏)
效果EdiText默认不获取焦点,点击后进入输入模式,输入法弹出,获取焦点。当输入完成后,输入法隐藏,EditText自动清除焦点。实现1、先解决EditText自动获取焦点的问题,在父布局内添加 android:focusable="true" android:focusableInTouchMode="true"2、编写自定义EditTextpublic class EditText_AutoFocus extends androidx.appcompat.widget.AppCo原创 2020-06-10 11:16:02 · 485 阅读 · 0 评论 -
【自定义控件】RecyclerView实现自动滚动效果
MyRecyclerViewpublic class MyRecyclerView extends RecyclerView { Handler mHandler = new Handler(); public MyRecyclerView(@NonNull Context context) { super(context); } public MyRecyclerView(@NonNull Context context, @Nullable Att原创 2020-05-30 09:08:50 · 776 阅读 · 0 评论 -
RecyclerView跳转指定Position后将其置顶
MyLinearSmoothScrollerpublic class MyLinearSmoothScroller extends LinearSmoothScroller { public MyLinearSmoothScroller(Context context) { super(context); } @Override protected int getHorizontalSnapPreference() { return SNA原创 2020-05-30 09:01:41 · 198 阅读 · 0 评论 -
SimpleDateFormat日期格式转换及时间戳转换
String 转 DateString string= "2020-5-27 13:57:45";SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") ;Date date = simpleDateFormat.parse(string);Date 转 StringDate date = new Date();SimpleDateFormat simpleDateFormat = new原创 2020-05-27 14:55:24 · 3607 阅读 · 0 评论 -
【快速使用】RecyclerView(LinearLayoutManager)
1、添加依赖implementation ‘androidx.recyclerview:recyclerview:1.2.0-alpha03’2、构建Item布局略3、构建ItemBeanpublic class ItemBean_List { private String id = ""; private String productModel = ""; ItemBean_List(String id, String productMode原创 2020-05-23 16:43:57 · 1700 阅读 · 0 评论 -
【简单封装】Android——TCP服务端
使用tcp_server = new PZHelp_TCP_Server();tcp_server.creat(8000, new PZHelp_TCP_Server.ReceiveListener() { @Override public void Receive(String response) { Log.d(TAG, "Receive: " + respons...原创 2020-07-27 10:15:51 · 760 阅读 · 0 评论 -
【简单封装】Android——TCP客户端
使用tcp_client = new PZHelp_TCP_Client();tcp_client.creat("192.168.0.41", 9000, new PZHelp_TCP_Client.ReceiveListener() { @Override public void connect() { Log.d("PZHelp_TCP_Client", "...原创 2020-05-14 09:50:45 · 266 阅读 · 0 评论 -
Android——RecyclerView宽高自适应填充
基础知识GridLayoutManager 继承于 LinearLayoutManager,是 RecyclerView 的布局管理器,主要为了实现宫格布局。GridLayoutManager.setOrientation(GridLayoutManager.VERTICAL) 或 HORIZONTAL 可以设置 RecyclerView 的延展方向,VERTICAL 便是指纵方向延展。n...原创 2020-04-28 14:46:37 · 4076 阅读 · 0 评论 -
自适应文字大小的TextView
Android8.0以上可以在TextView中添加autoSizeTextType实现Android8.0以下要想达到根据TextView大小自动调整文字大小(不适合使用多行文字),只能自定义了public class PZHelp_TextView_AutoTextSize extends androidx.appcompat.widget.AppCompatTextView { ...原创 2020-04-16 11:46:18 · 262 阅读 · 0 评论 -
Android——AVD预览真机显示效果
Android——AVD预览真机显示效果。原创 2019-08-01 10:53:54 · 817 阅读 · 0 评论 -
【简单封装】UDP服务端
PZHelp_UDPServerpublic class PZHelp_UDPServer extends Thread { private static final String TAG = "PZHelp_UDPServer"; private DatagramSocket socket; private DatagramPacket packet; pri...原创 2020-04-11 12:06:07 · 222 阅读 · 0 评论 -
【代码块】Android代码执行ADB指令
【代码块】Android-kotlin执行ADB指令。原创 2020-04-10 11:30:00 · 4463 阅读 · 0 评论 -
【快速使用】Android6.0权限
检查是否可以使用该权限,调用ContextCompat.checkSelfPermission()例如:ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.WRITE_CALENDAR);如果应用有该权限,该方法将返回 PackageManager.PERMISSION_GRANTED ,应用可以进行相关的原创 2017-04-27 20:57:48 · 301 阅读 · 1 评论 -
AndroidStudio个人常用ADB与快捷键
netcfg 查看网络端口adb shell am start com.android.settings 进入设置界面com.android.settings.DevelopmentSettings 开发者设置com.android.settings.DeviceInfoSettings 关于手机com.android.settings.RadioInfo 手机信息com.an...原创 2019-05-30 14:04:34 · 1629 阅读 · 0 评论 -
Android——USB转COM口(CH340)与传感器进行通讯
本人使用环境CH340转接头Android5.1,RK3188Android6.0,RK3288关于官方的jar包与使用存在的问题(官方地址)最大的问题是无法修改串口波特率,一直以19200运行,但我的传感器为9600初始化使用GitHub:https://github.com/mik3y/usb-serial-for-android在你的build.gradle(pro...原创 2020-03-12 10:18:28 · 1943 阅读 · 1 评论 -
SeetaFace2在Android上的使用:工程创建
原GitHubhttps://github.com/seetafaceengine/SeetaFace2 这一项是需要自行编译的,没有条件的看下面这个。https://github.com/seetaface/SeetaFaceEngine2资源下载https://github.com/seetaface/SeetaFaceEngine2/blob/master/attachment...原创 2020-03-03 10:55:04 · 1457 阅读 · 3 评论