Files
fuzhu/doc/异常处理
renjianbo 73f866ca5b commit
2026-01-06 10:32:14 +08:00

129 lines
6.3 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
1.访问接口出错
java.net.UnknownServiceException: CLEARTEXT communication to * not permitted by network
在Android9版以上会发生如下异常
java.net.UnknownServiceException: CLEARTEXT communication to * not permitted by network
原因是Android9版本默认不允许http访问,他们认为http是不安全的,只能用https
解决办法
1:请求修改为https
2:targetSdkVersion 降到27以下
3:在 res 下新增一个 xml 目录,然后创建一个名为:network_security_config.xml 文件(名字自定) ,内容如下,大概意思就是允许开启http请求
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
   <base-config cleartextTrafficPermitted="true" />
</network-security-config>
在AndroidManifest.xml的Application中添加配置引用
<application
   ..
  android:networkSecurityConfig="@xml/network_security_config"
  ... >
------------------------------------------------------------------------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
------------------------------------------------------------------------------------------------------------------------------------------
2.Android-Android 10 创建不了文件夹
尝试了很久,AndroidManifest已加了权限:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
也动态申请了读写权限,但是创建文件夹一直失败,而运行以前的工程,没有问题!!,最后发现在AndroidManifest中配置一下android:requestLegacyExternalStorage="true" 搞定!!
<application
...
android:requestLegacyExternalStorage="true" // 这样就可以采用原有的存储策略
android:theme="@style/AppTheme">
更为诡异的是,这时你再把这个属性去掉,把apk卸载重装,它都有权限创建了!
------------------------------------------------------------------------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
------------------------------------------------------------------------------------------------------------------------------------------
3.解决Android10 imei不能获取的问题(适配Android 10)
https://blog.csdn.net/zqd1984309864/article/details/107410758?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-2.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-2.control
------------------------------------------------------------------------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
------------------------------------------------------------------------------------------------------------------------------------------
4.处理账号登录过程中弹出的推荐好友弹框
/**
* 关闭弹框
* @param instance
*/
public void closedDialog(AblService instance) {
//检查是否有弹框,并关闭所有弹窗
//处理发现通讯好好友的弹框
AccessibilityNodeInfo liebiaokong = AblViewUtil.findByText("好友推荐", 0);
if (liebiaokong != null) {
Log.e("TIAOSHI###", "弹出了好友推荐的弹框");
AccessibilityNodeInfo parent = liebiaokong.getParent();
AccessibilityNodeInfo child = parent.getChild(2);
instance.clickcommontwo(child, "关闭好友推荐弹框");
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
------------------------------------------------------------------------------------------------------------------------------------------
5.getText().toString() //要做空指针检测
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
------------------------------------------------------------------------------------------------------------------------------------------
6.字符串中去除表情符号
String s = EmojiFilter.filterEmoji(s1);//去除字符串中包含的表情符号
Log.e("提交的字符串(不包含表情符号)", s);
7.文本框自动输入功能
AccessibilityNodeInfo自动输入
在AccessibilityNoteInfo中实现自动输入时,有两种不同的方法:
(1).在android版本>21时可以使用两种,第一种是AccessibilityService自带的方法:
Bundle arguments = new Bundle();
arguments.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, Constents.mobile[mobile_j]);
info.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments);
(2).ClipboardManager clipboard = (ClipboardManager)this.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("text", "15066306736");
clipboard.setPrimaryClip(clip);
//焦点(n是AccessibilityNodeInfo对象)
info.performAction(AccessibilityNodeInfo.ACTION_FOCUS);
粘贴进入内容
info.performAction(AccessibilityNodeInfo.ACTION_PASTE);
8.在悬浮窗上显示运行的信息时候,会有延迟的原因是因为线程等待,将线程等待的代码写在发送消息的方法行面后正常,或者写在下一个步骤上也可以实现同步。
compileSdkVersion 29
defaultConfig {
applicationId "com.fisherbone.fuzhu"
minSdkVersion 24
targetSdkVersion 29
versionCode 121
versionName "1.2.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 16
targetSdkVersion 30
versionCode 121
versionName "1.2.1"
multiDexEnabled true //突破应用方法数65535的一个限制
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}