1、安卓BLE
Android6.0以上系統(tǒng),開(kāi)發(fā)的app(targetSdkVersion為23或以上)在vivo,oppo,一加上搜索不到附近BLE設(shè)備,手機(jī)自帶的設(shè)置-藍(lán)牙下面是可以搜索到附近BLE設(shè)備的,其他品牌手機(jī)均可正常運(yùn)行。
解決:
1、修改targetSdkVersion為23以下
2、打開(kāi)系統(tǒng)的位置信息開(kāi)關(guān)(判斷GPS是否打開(kāi),未打開(kāi)跳到系統(tǒng)設(shè)置位置信息)
2、加載大圖片內(nèi)存溢出
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包報(bào)錯(cuò)
defaultConfig {
? ? ? ? ndk {
//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導(dǎo)入方式:
1.靜態(tài)導(dǎo)入,就是放在jnilibs目錄
2.動(dòng)態(tài)導(dǎo)入,放在asets目錄,通過(guò)代碼將其復(fù)制到app包名目錄下,context.getFilesDir(),然后調(diào)用System.load(".so的絕對(duì)路徑“”);
4、安卓多語(yǔ)言
安卓app增加了多語(yǔ)言切換,用application和activity的context獲取的屏幕的方向和大小會(huì)有問(wèn)題,有一篇多語(yǔ)言的文章已解決
5、vlc rtsp播放
安卓vlc播放,手機(jī)是豎屏?xí)r,vlc展示的寬高比為16:9顯示沒(méi)問(wèn)題,橫屏?xí)r,vlc的寬設(shè)為屏幕的寬,高設(shè)為屏幕的高,顯示在屏幕上畫(huà)面錯(cuò)亂
手機(jī)為橫屏?xí)r,vlc展示的寬高比應(yīng)該設(shè)為16:9,這時(shí)候畫(huà)面就會(huì)正常
6、android fragment各種嵌套問(wèn)題
有篇fragment各種嵌套的文章已解決
7、android dialog默認(rèn)的遮蓋顏色不能改變
直接讓dialog全屏,在dialog的根布局設(shè)置前景自定義遮蓋,有篇dialog的文章已解決
8、服務(wù)器更換了圖片,android guide加載的還是緩存的圖片
服務(wù)器更換了圖片,卻沒(méi)有改變url,導(dǎo)致該問(wèn)題
可以獲取圖片url的最后修改時(shí)間,為0就不加載圖片,不為0就將時(shí)間戳設(shè)為guide加載圖片的簽名就可以解決該問(wèn)題
9、android guide設(shè)置placeholder問(wèn)題
在recyclerview中設(shè)置placeholder,recyclerview更新時(shí)圖片會(huì)閃爍出placeholder設(shè)置的圖片,所以不能設(shè)置placeholder,設(shè)置error就行
設(shè)置了placeholder就必須得設(shè)置dontAnimate,否則圖片顯示會(huì)不正常
10、dialog和activity狀態(tài)欄顯示不正常
有篇狀態(tài)欄設(shè)置文章已解決
11、Gradle sync failed: Connection refused: connect
解決:
1、沒(méi)有開(kāi)代理,打開(kāi)代理,auto-detect proxy settings
2、project目錄下的gradle.properties中設(shè)置了Proxy代理所致,打開(kāi)項(xiàng)目中的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文件中是否有和前述一樣存在著代理設(shè)置的問(wèn)題,這個(gè)屬于系統(tǒng)級(jí)的Proxy代理設(shè)置,它對(duì)所有的工程項(xiàng)目有效,如果有代理設(shè)置的話也刪除掉。刪除這一部分代碼,編譯就正常了。
12、調(diào)用設(shè)置值的api,新版本的代碼和過(guò)時(shí)的代碼一起調(diào)用,調(diào)用返回值得api,新版本的代碼和過(guò)時(shí)的代碼判斷版本來(lái)調(diào)用其中的一個(gè)
設(shè)置值:
public static Context updateLanguage(Context context) {
? ? Locale locale = getCurrentLocale(context);
? ? if (locale == null) {
? ? ? ? return context;
? ? }
? ? update(context, locale);
? ? //設(shè)置值的代碼,高版本的代碼和過(guò)時(shí)的代碼一起執(zhí)行
? ? 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;
? ? //返回值的代碼,高版本的代碼和過(guò)時(shí)的代碼條件執(zhí)行
? ? if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
? ? ? ? //7.0有多語(yǔ)言設(shè)置獲取頂部的語(yǔ)言
? ? ? ? locale = context.getResources().getConfiguration().getLocales().get(0);
? ? } else {
? ? ? ? locale = context.getResources().getConfiguration().locale;
? ? }
? ? return locale;
}
13、Androidstudio中的文件顯示錯(cuò)亂,但是在記事本中顯示正常
關(guān)閉Androidstudio,?刪除C:\Users\Administrator\.AndroidStudio3.5\system\caches中caches目錄,然后打開(kāi)Androidstudio
14、Androidstudio項(xiàng)目改名
項(xiàng)目名A改成B:項(xiàng)目根目錄下的settings.gradle文件中的rootProject.name='A'改成rootProject.name='B',關(guān)閉項(xiàng)目并在Androidstudio中清除該項(xiàng)目,將項(xiàng)目的文件夾名稱A修改成B,重新導(dǎo)入項(xiàng)目。
15、安卓藍(lán)牙uuid解釋
藍(lán)牙廣播中對(duì)服務(wù) UUID 格式定義都有三種 16 bit UUID、32 bit UUID、128 bit UUID。
但是熟悉安卓開(kāi)發(fā)的小伙伴都知道接口都 UUID 格式,fromString 時(shí)候 16bit 的 UUID 該咋辦呢?
16bit 和 32bit 的 UUID 與 128bit 的值之間轉(zhuǎn)換關(guān)系:
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
如果你想說(shuō)這是啥呀,那我這樣說(shuō)你應(yīng)該可以明白點(diǎn):
若 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[]轉(zhuǎn)String,再將字符串轉(zhuǎn)成字節(jié)數(shù)組,與原始數(shù)組不一樣
byte[] a = {0x25, 0x15, 0x25, (byte) 0xE8, (byte) 0x9B, 0x5C, 0x35, (byte) 0xF2};
String b = new String(a);
byte[] c = b.getBytes();
c的16進(jìn)制字符串是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);
這是為什么呢?原因是第一種方法默認(rèn)是用UTF-8編碼來(lái)生成String的,用System.getProperty("sun.jnu.encoding")可以得到Android默認(rèn)編碼是UTF-8。UTF-8是可變長(zhǎng)度的編碼,原來(lái)的字節(jié)數(shù)組就被改變了。而ISO8859-1通常叫做Latin-1,Latin-1包括了書(shū)寫(xiě)所有西方歐洲語(yǔ)言不可缺少的附加字符,其中?0~127的字符與ASCII碼相同,它是單字節(jié)的編碼方式,這樣第二種方式生成的String里的字節(jié)數(shù)組就跟原來(lái)的字節(jié)數(shù)組一樣。在new?String使用其他編碼如GBK,GB2312的話一樣也會(huì)導(dǎo)致字節(jié)數(shù)組發(fā)生變化,因此要想獲取String里單字節(jié)數(shù)組,就應(yīng)該使用iso8859-1編碼。
17、android APP無(wú)法使用http網(wǎng)絡(luò)請(qǐng)求了
打開(kāi)app/src/main目錄下的AndroidManifest.xml文件,在application節(jié)點(diǎn)上添加android:usesCleartextTraffic="true"
18、Android Q報(bào)錯(cuò)The user 10129 does not meet the requirements to access device identifiers
設(shè)置targetVersion<29
19、Android MQTT異常
MqttException 無(wú)權(quán)連接
org.eclipse.paho.client.mqttv3.internal.exceptionhelper.createmqttexception(exceptionhelper.java:28)
org.eclipse.paho.client.mqttv3.internal.clientstate.notifyReceiveDack(clientstate.java:885)
org.eclipse.paho.client.mqttv3.internal.commsreceiver.run(commsreceiver.java:118)
原因:mqttClientId有問(wèn)題,需要修改
20、Android Touch事件實(shí)現(xiàn)按鈕的選擇器效果
View view = new View(mActivity);
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
//設(shè)置點(diǎn)擊后的效果
return true;
case MotionEvent.ACTION_UP:
//恢復(fù)到點(diǎn)擊前的效果
{
//判斷手指彈起時(shí)的位置是否在控件區(qū)域內(nèi),在區(qū)域內(nèi)是點(diǎn)擊,在區(qū)域外是取消
float x = event.getX();
float y = event.getY();
if (x >= 0) {
if (x <= v.getWidth()) {
if (y >= 0) {
if (y <= v.getHeight()) {
//執(zhí)行目標(biāo)代碼
}
}
}
}
}
break;
case MotionEvent.ACTION_CANCEL:
//基本不會(huì)觸發(fā)
break;
default:
break;
}
return false;
}
});