安卓问题记录

1、安卓BLE

Android6.0以上系统,开发的app(targetSdkVersion为23或以上)在vivo,oppo,一加上搜索不到附近BLE设备,手机自带的设置-蓝牙下面是可以搜索到附近BLE设备的,其他品牌手机均可正常运行。

解决:

1、修改targetSdkVersion为23以下

2、打开系统的位置信息开关(判断GPS是否打开,未打开跳到系统设置位置信息)

 

2、

java.lang.OutOfMemoryError
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:639)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:615)
at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:391)
at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:419)

        at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:419)

解决:

Try enabling large heap support, by adding this to your AndroidManifest.xml file:

<application android:largeHeap="true"

Also, you can reduce the memory required for your Bitmaps by using the Bitmap.Config type RGB_565 instead of ARGB_8888.

 

 

3、.so

defaultConfig {
        ndk {
//解决了高德地图和vlc的.so库的冲突,Can't load vlcjni library: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/steelmate.com.iot_hardware-1/base.apk"],nativeLibraryDirectories=[/data/app/steelmate.com.iot_hardware-1/lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "libvlcjni.so"
            abiFilters "arm64-v8a","armeabi", "armeabi-v7a", "x86","x86_64"
        }
        applicationId "steelmate.com.equipment"
        minSdkVersion 19
        targetSdkVersion 21
        versionCode 2
        versionName "1.1"
        multiDexEnabled true

    }

.so导入方式:

1.静态导入,就是放在jnilibs目录

2.动态导入,放在asets目录,通过代码将其复制到app包名目录下,context.getFilesDir(),然后调用System.load(".so的绝对路径“”);

 

 

4、安卓多语言

安卓app增加了多语言切换,用application和activity的context获取的屏幕的方向和大小会有问题,有一篇多语言的文章已解决

 

5、vlc rtsp播放

安卓vlc播放,手机是竖屏时,vlc展示的宽高比为16:9显示没问题,横屏时,vlc的宽设为屏幕的宽,高设为屏幕的高,显示在屏幕上画面错乱

手机为横屏时,vlc展示的宽高比应该设为16:9,这时候画面就会正常

 

 

6、android fragment各种嵌套问题

有篇fragment各种嵌套的文章已解决

 

 

7、android dialog默认的遮盖颜色不能改变

直接让dialog全屏,在dialog的根布局设置前景自定义遮盖,有篇dialog的文章已解决

 

8、服务器更换了图片,android guide加载的还是缓存的图片

服务器更换了图片,却没有改变url,导致该问题

可以获取图片url的最后修改时间,为0就不加载图片,不为0就将时间戳设为guide加载图片的签名就可以解决该问题

 

 

9、android guide设置placeholder问题

在recyclerview中设置placeholder,recyclerview更新时图片会闪烁出placeholder设置的图片,所以不能设置placeholder,设置error就行

设置了placeholder就必须得设置dontAnimate,否则图片显示会不正常

 

10、dialog和activity状态栏显示不正常

有篇状态栏设置文章已解决

11、Gradle sync failed: Connection refused: connect

解决:

1、没有开代理,打开代理,auto-detect proxy settings

2、project目录下的gradle.properties中设置了Proxy代理所致,打开项目中的gradle.properties文件,查看其中是否有,删掉这些代码,就可以了。
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=1080
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=1080

3、查看C:\Users\Administrator\.gradle文件夹,看其中的gradle.properties文件中是否有和前述一样存在着代理设置的问题,这个属于系统级的Proxy代理设置,它对所有的工程项目有效,如果有代理设置的话也删除掉。删除这一部分代码,编译就正常了。

12、调用设置值的api,新版本的代码和过时的代码一起调用,调用返回值得api,新版本的代码和过时的代码判断版本来调用其中的一个

设置值:
public static Context updateLanguage(Context context) {

    Locale locale = getCurrentLocale(context);

    if (locale == null) {
        return context;
    }

    update(context, locale);

    //设置值的代码,高版本的代码和过时的代码一起执行
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        context = context.createConfigurationContext(context.getResources().getConfiguration());
        update(context, locale);
    }

    return context;
}

private static void update(Context context, Locale locale) {
    Resources      resources      = context.getResources();
    Configuration  configuration  = resources.getConfiguration();
    DisplayMetrics displayMetrics = resources.getDisplayMetrics();
    configuration.setLocale(locale);
    resources.updateConfiguration(configuration, displayMetrics);
}

返回值:

private static Locale getSystemLocale(Context context) {
    Locale locale;
    //返回值的代码,高版本的代码和过时的代码条件执行
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        //7.0有多语言设置获取顶部的语言
        locale = context.getResources().getConfiguration().getLocales().get(0);
    } else {
        locale = context.getResources().getConfiguration().locale;
    }
    return locale;
}

13、Androidstudio中的文件显示错乱,但是在记事本中显示正常

关闭Androidstudio, 删除C:\Users\Administrator\.AndroidStudio3.5\system\caches中caches目录,然后打开Androidstudio

14、Androidstudio项目改名

项目名A改成B:项目根目录下的settings.gradle文件中的rootProject.name='A'改成rootProject.name='B',关闭项目并在Androidstudio中清除该项目,将项目的文件夹名称A修改成B,重新导入项目。

15、安卓蓝牙uuid解释

蓝牙广播中对服务 UUID 格式定义都有三种 16 bit UUID、32 bit UUID、128 bit UUID。
但是熟悉安卓开发的小伙伴都知道接口都 UUID 格式,fromString 时候 16bit 的 UUID 该咋办呢?
16bit 和 32bit 的 UUID 与 128bit 的值之间转换关系:
128_bit_UUID = 16_bit_UUID * 2^96 + Bluetooth_Base_UUID
128_bit_UUID = 32_bit_UUID * 2^96 + Bluetooth_Base_UUID
其中 Bluetooth_Base_UUID 定义为 00000000-0000-1000-8000-00805F9B34FB 
如果你想说这是啥呀,那我这样说你应该可以明白点:
若 16 bit UUID为xxxx,那么 128 bit UUID 为 0000xxxx-0000-1000-8000-00805F9B34FB
若 32 bit UUID为xxxxxxxx,那么 128 bit UUID 为 xxxxxxxx-0000-1000-8000-00805F9B34FB

16、Java中byte[]转String,再将字符串转成字节数组,与原始数组不一样

byte[] a = {0x25, 0x15, 0x25, (byte) 0xE8, (byte) 0x9B, 0x5C, 0x35, (byte) 0xF2};
String b = new String(a);
byte[] c = b.getBytes();
c的16进制字符串是251525EFBFBD5C35EFBFBD
解决:
byte[] a = {0x25, 0x15, 0x25, (byte) 0xE8, (byte) 0x9B, 0x5C, 0x35, (byte) 0xF2};
String b = new String(a,StandardCharsets.ISO_8859_1);
byte[] c = b.getBytes(,StandardCharsets.ISO_8859_1);

这是为什么呢?原因是第一种方法默认是用UTF-8编码来生成String的,用System.getProperty("sun.jnu.encoding")可以得到Android默认编码是UTF-8。UTF-8是可变长度的编码,原来的字节数组就被改变了。而ISO8859-1通常叫做Latin-1,Latin-1包括了书写所有西方欧洲语言不可缺少的附加字符,其中 0~127的字符与ASCII码相同,它是单字节的编码方式,这样第二种方式生成的String里的字节数组就跟原来的字节数组一样。在new String使用其他编码如GBK,GB2312的话一样也会导致字节数组发生变化,因此要想获取String里单字节数组,就应该使用iso8859-1编码。

17、android APP无法使用http网络请求了

打开app/src/main目录下的AndroidManifest.xml文件,在application节点上添加android:usesCleartextTraffic="true"

18、Android Q报错The user 10129 does not meet the requirements to access device identifiers

设置targetVersion<29

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值