首页
工具
隐私协议
App Privacy Policy
更多
作品
关于我们
Search
1
android5遇到INSTALL_FAILED_DEXOPT 解决办法
1,664 阅读
2
设置max_connections无效
1,484 阅读
3
FlexboxLayout+recyclerView实现自动换行
1,375 阅读
4
Nginx配置多个域名
1,257 阅读
5
Android P http网络请求失败
1,230 阅读
默认分类
mysql
android
android深入
Jetpack Compose
Android传感器
php
Yii2
windows
webrtc
登录
Search
标签搜索
android
kotlin
webrtc
kurento
mysql
adb
nginx
flutter
rsa
微信
git
Yii2
md5
加密
dart
aes
wechat
windows
小程序
dexopt
Typecho
累计撰写
80
篇文章
累计收到
3
条评论
首页
栏目
默认分类
mysql
android
android深入
Jetpack Compose
Android传感器
php
Yii2
windows
webrtc
页面
工具
隐私协议
App Privacy Policy
作品
关于我们
搜索到
52
篇与
android
的结果
2020-10-28
WebView通过URL传值控制div是否显示
protocol.html... <div style="position:relative;" id="form"> <div class="flex"> <input type="checkbox" id="ck1"/><span class="checkboxText" style="color:#3789c5">阅读并同意《xxx》</span> </div> <div class="flex"> <button id="submit" class="round" onclick="join();">同意</button> </div> </div> ...protocol.js··· document.addEventListener("DOMContentLoaded", function() { var ckAll = document.getElementById("form") var type = getQueryVariable("type"); //获得变量后判断是否展示 if (type == 0) { ckAll.style.display = "block"; } else { ckAll.style.display = "none"; } }); //获取get变量值 function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split("="); if (pair[0] == variable) { return pair[1]; } } return (false); } ···Webview加载,通过get传值//0显示,1隐藏 webView.loadUrl("file:///android_asset/about/protocol.html?type=0")
2020年10月28日
270 阅读
0 评论
0 点赞
2020-10-26
WebView监听HTML的事件
添加addJavascriptInterfaceval ws: WebSettings = wv.getSettings() ws.javaScriptEnabled = true wv.addJavascriptInterface(object : Any() { @JavascriptInterface fun performClick(strl: String) { Toast.makeText(this@YourActivity, stringVariable, Toast.LENGTH_SHORT).show() } }, "ok")在onclick中添加对应方法,这里的"ok"是addJavascriptInterface的name参数<button type="button" onclick="ok.performClick();">OK</button>
2020年10月26日
244 阅读
0 评论
0 点赞
2020-10-26
解决启动时出现白屏 android
在app启动时屏幕会出现短暂的白屏现象,为了避免该现象加了一个启动页面并填充图片,图片用jpg格式。override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val view = ImageView(this) setContentView(view) view.setBackgroundResource(R.mipmap.bg_start) view.postDelayed({ startNext() finish() }, 2000) }
2020年10月26日
232 阅读
0 评论
0 点赞
2020-09-18
android 11 应用无法调起微信
targetSdkVersion设置为30后,无法调起微信,执行IWXAPI.isWXAppInstalled()时直接返回了false;起初降到29来解决,另外看到微信开放文档也有了解决方案:<manifest package="com.example.app"> ... // 在应用的AndroidManifest.xml添加如下<queries>标签 <queries> <package android:name="com.tencent.mm" /> // 指定微信包名 </queries> ... </manifest>相关链接:https://developer.android.google.cn/about/versions/11/privacy/package-visibilityhttps://developers.weixin.qq.com/doc/oplatform/Mobile_App/Access_Guide/Android.html#jump2
2020年09月18日
529 阅读
0 评论
0 点赞
2020-09-15
设置setCompoundDrawables不生效解决办法
设置setCompoundDrawables不生效时,是因为没有指定drawable的大小val drawable=resources.getDrawable(R.mipmap.icon) drawable.setBounds(0, 0, drawable.intrinsicWidth, drawable.intrinsicHeight)//设置drawable大小 text.setCompoundDrawables(drawable, null, null, null)另外调用setCompoundDrawablesWithIntrinsicBounds也可以解决text.setCompoundDrawablesWithIntrinsicBounds(resources.getDrawable(R.mipmap.icon), null, null, null)
2020年09月15日
735 阅读
0 评论
0 点赞
2020-09-15
Android加密算法之RSA(二)
The RSA algorithm can only encrypt data that has a maximum byte length of the RSA key length in bits divided with eight minus eleven padding bytes, i.e. number of maximum bytes = key length in bits / 8 - 11.使用RSA时,数据过长会报错,如:javax.crypto.IllegalBlockSizeException: input must be under 256 bytes因此,基本上,您将密钥长度除以8 -11(如果有填充)。例如,如果您具有2048位密钥,则可以加密2048/8 = 256字节(如果有填充则为11字节)。因此,可以使用更大的密钥,也可以使用对称密钥加密数据,然后使用rsa加密该密钥(推荐的方法)参考:https://stackoverflow.com/questions/10007147/getting-a-illegalblocksizeexception-data-must-not-be-longer-than-256-bytes-when通过分段加密解决1.生成公钥私钥@Throws(Exception::class) fun genKeyPair(): Map<String?, String> { val keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM) keyPairGen.initialize(2048) val keyPair = keyPairGen.generateKeyPair() val publicKey = keyPair.public as RSAPublicKey val privateKey = keyPair.private as RSAPrivateKey val keyMap: MutableMap<String?, String> = HashMap(2) keyMap[PUBLIC_KEY] = Base64.encodeToString(publicKey.encoded, Base64.DEFAULT) keyMap[PRIVATE_KEY] = Base64.encodeToString(privateKey.encoded, Base64.DEFAULT) return keyMap }2.公钥加密 @Throws(Exception::class) fun encryptByPublicKey(data: ByteArray, publicKey: String?): ByteArray { val keyBytes: ByteArray = Base64.decode(publicKey, Base64.DEFAULT) val x509KeySpec = X509EncodedKeySpec(keyBytes) val keyFactory = KeyFactory.getInstance(KEY_ALGORITHM) val publicK: Key = keyFactory.generatePublic(x509KeySpec) // 对数据加密 val cipher = Cipher.getInstance(keyFactory.algorithm) cipher.init(Cipher.ENCRYPT_MODE, publicK) val inputLen = data.size val out = ByteArrayOutputStream() var offSet = 0 var cache: ByteArray var i = 0 // 对数据分段加密 while (inputLen - offSet > 0) { cache = if (inputLen - offSet > MAX_ENCRYPT_BLOCK) { cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK) } else { cipher.doFinal(data, offSet, inputLen - offSet) } out.write(cache, 0, cache.size) i++ offSet = i * MAX_ENCRYPT_BLOCK } val encryptedData = out.toByteArray() out.close() return encryptedData }3.私钥解密 @Throws(Exception::class) fun decryptByPrivateKey(encryptedData: ByteArray, privateKey: String?): ByteArray { val keyBytes: ByteArray = Base64.decode(privateKey, Base64.DEFAULT) val pkcs8KeySpec = PKCS8EncodedKeySpec(keyBytes) val keyFactory = KeyFactory.getInstance(KEY_ALGORITHM) val privateK: Key = keyFactory.generatePrivate(pkcs8KeySpec) val cipher = Cipher.getInstance(keyFactory.algorithm) cipher.init(Cipher.DECRYPT_MODE, privateK) val inputLen = encryptedData.size val out = ByteArrayOutputStream() var offSet = 0 var cache: ByteArray var i = 0 // 对数据分段解密 while (inputLen - offSet > 0) { cache = if (inputLen - offSet > MAX_DECRYPT_BLOCK) { cipher.doFinal(encryptedData, offSet, MAX_DECRYPT_BLOCK) } else { cipher.doFinal(encryptedData, offSet, inputLen - offSet) } out.write(cache, 0, cache.size) i++ offSet = i * MAX_DECRYPT_BLOCK } val decryptedData = out.toByteArray() out.close() return decryptedData }4.调用方法: val keyMap: Map<String?, String?> = RSACrypt.genKeyPair() val publicKey = keyMap[RSACrypt.PUBLIC_KEY] val privateKey = keyMap[RSACrypt.PRIVATE_KEY] val source = "身高一米七左右,标准的九头身,五官立体宛如艺术大师鬼斧神工之作,肌肤赛雪,宛如白玉般似能反射光彩。" + "“我和茹雪两情相悦,但对我们而言,你是第三者,所以请你自己主动退出,我愿意给你一笔钱,你开个价码吧!”啪,一声清脆的响声,干净利落地狠狠扇在韩斌的脸上。" + "乔智愿意当陶家的女婿,除了偿还父亲欠下的人情债之外,还有一个重要原因,陶茹雪本身出众,是琼金一枝花,知名度高,追求者众多。" val data = source.encodeToByteArray() val encodedData: ByteArray = RSACrypt.encryptByPublicKey(data, publicKey) Log.w("rsa", "加密后文字:${Base64.encodeToString(encodedData, Base64.DEFAULT)}") val decodedData: ByteArray = RSACrypt.decryptByPrivateKey(encodedData, privateKey) Log.w("rsa", "解密后文字: \r\n${String(decodedData)}")完整代码object RSACrypt { /** * 加密算法RSA */ const val KEY_ALGORITHM = "RSA" /** * 签名算法 */ const val SIGNATURE_ALGORITHM = "MD5withRSA" /** * 获取公钥的key */ const val PUBLIC_KEY = "RSAPublicKey" /** * 获取私钥的key */ const val PRIVATE_KEY = "RSAPrivateKey" /** * RSA最大加密明文大小 */ private const val MAX_ENCRYPT_BLOCK = 245 /** * RSA最大解密密文大小 */ private const val MAX_DECRYPT_BLOCK = 256 /** * 生成密钥对(公钥和私钥) * @return * @throws Exception */ @Throws(Exception::class) fun genKeyPair(): Map<String?, String> { val keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM) keyPairGen.initialize(2048) val keyPair = keyPairGen.generateKeyPair() val publicKey = keyPair.public as RSAPublicKey val privateKey = keyPair.private as RSAPrivateKey val keyMap: MutableMap<String?, String> = HashMap(2) keyMap[PUBLIC_KEY] = Base64.encodeToString(publicKey.encoded, Base64.DEFAULT) keyMap[PRIVATE_KEY] = Base64.encodeToString(privateKey.encoded, Base64.DEFAULT) return keyMap } /** * 私钥解密 * * @param encryptedData 已加密数据 * @param privateKey 私钥(BASE64编码) * @return * @throws Exception */ @Throws(Exception::class) fun decryptByPrivateKey(encryptedData: ByteArray, privateKey: String?): ByteArray { val keyBytes: ByteArray = Base64.decode(privateKey, Base64.DEFAULT) val pkcs8KeySpec = PKCS8EncodedKeySpec(keyBytes) val keyFactory = KeyFactory.getInstance(KEY_ALGORITHM) val privateK: Key = keyFactory.generatePrivate(pkcs8KeySpec) val cipher = Cipher.getInstance(keyFactory.algorithm) cipher.init(Cipher.DECRYPT_MODE, privateK) val inputLen = encryptedData.size val out = ByteArrayOutputStream() var offSet = 0 var cache: ByteArray var i = 0 // 对数据分段解密 while (inputLen - offSet > 0) { cache = if (inputLen - offSet > MAX_DECRYPT_BLOCK) { cipher.doFinal(encryptedData, offSet, MAX_DECRYPT_BLOCK) } else { cipher.doFinal(encryptedData, offSet, inputLen - offSet) } out.write(cache, 0, cache.size) i++ offSet = i * MAX_DECRYPT_BLOCK } val decryptedData = out.toByteArray() out.close() return decryptedData } /** * * 公钥加密 * * @param data 源数据 * @param publicKey 公钥(BASE64编码) * @return * @throws Exception */ @Throws(Exception::class) fun encryptByPublicKey(data: ByteArray, publicKey: String?): ByteArray { val keyBytes: ByteArray = Base64.decode(publicKey, Base64.DEFAULT) val x509KeySpec = X509EncodedKeySpec(keyBytes) val keyFactory = KeyFactory.getInstance(KEY_ALGORITHM) val publicK: Key = keyFactory.generatePublic(x509KeySpec) // 对数据加密 val cipher = Cipher.getInstance(keyFactory.algorithm) cipher.init(Cipher.ENCRYPT_MODE, publicK) val inputLen = data.size val out = ByteArrayOutputStream() var offSet = 0 var cache: ByteArray var i = 0 // 对数据分段加密 while (inputLen - offSet > 0) { cache = if (inputLen - offSet > MAX_ENCRYPT_BLOCK) { cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK) } else { cipher.doFinal(data, offSet, inputLen - offSet) } out.write(cache, 0, cache.size) i++ offSet = i * MAX_ENCRYPT_BLOCK } val encryptedData = out.toByteArray() out.close() return encryptedData } }
2020年09月15日
520 阅读
0 评论
0 点赞
2020-09-15
Android加密算法之RSA(一)
RSA公钥加密私钥解密object RSACrypt { private const val transformation = "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" /** * 公钥加密 * @param input 原文 * @param publicKey 公钥 */ fun encryptByPublicKey(input: ByteArray, publicKey: PublicKey): String { val cipher = Cipher.getInstance(transformation)//创建cipher对象 cipher.init(Cipher.ENCRYPT_MODE, publicKey)//初始化cipher对象 val encrypt = cipher.doFinal(input) //加密或解密 return Base64.encodeToString(encrypt, Base64.NO_WRAP) } /** * 私钥解密 * @param input 密文 * @param privateKey 私钥 */ fun decryptByPrivateKey(input: ByteArray, privateKey: PrivateKey): String { val cipher = Cipher.getInstance(transformation) //创建cipher对象 cipher.init(Cipher.DECRYPT_MODE, privateKey)//初始化cipher对象 val encrypt = cipher.doFinal(input)//加密或解密 return String(encrypt) } //生成RSAKey fun generateRSAKeyPair(keyLength: Int): KeyPair? { return try { val kpg = KeyPairGenerator.getInstance("RSA") kpg.initialize(keyLength) kpg.genKeyPair() } catch (e: NoSuchAlgorithmException) { e.printStackTrace() null } } }调用方法var keyPair = RSACrypt.generateRSAKeyPair(2048) keyPair?.let { val input = "123木头人" val encryptPublicKey = RSACrypt.encryptByPublicKey(input.encodeToByteArray(), it.public) val decryptPrivateKey = RSACrypt.decryptByPrivateKey(Base64.decode(encryptPublicKey, Base64.NO_WRAP), it.private) Log.w("rsa", "公钥加密 $encryptPublicKey") Log.w("rsa", "私钥解密 $decryptPrivateKey") }注意加密时如果内容过长会报:Caused by: javax.crypto.IllegalBlockSizeException: input must be under 256 bytes
2020年09月15日
365 阅读
0 评论
0 点赞
2020-09-11
GSON常用转换方法
将bean转换成Json字符串:return Gson().toJson(bean)将Json字符串转换成对象:return GsonBuilder().create().fromJson(string, DemoBean::class.java)//DemoBean是你的实体类名称将Json字符串转换成JsonObject对象val json: JsonObject = JsonParser().parse(jsonStr).getAsJsonObject()//jsonStr是json字符串将JsonArray类型的Json字符串解析成对象val typeToken = object : TypeToken<List<DemoBean>>() {}.type return GsonBuilder().create().fromJson(array, typeToken)
2020年09月11日
273 阅读
0 评论
0 点赞
2020-09-11
NestedScrollView 滚动监听是否到底部
nestedScrollView.setOnScrollChangeListener( NestedScrollView.OnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY -> if (scrollY > oldScrollY) { Log.i(TAG, "Scroll DOWN") } if (scrollY < oldScrollY) { Log.i(TAG, "Scroll UP") } if (scrollY == 0) { Log.i(TAG, "TOP SCROLL") } if (scrollY == v.getChildAt(0).measuredHeight - v.measuredHeight) { Log.i(TAG, "BOTTOM SCROLL") } })
2020年09月11日
237 阅读
0 评论
0 点赞
2020-08-24
WIFI连接adb connect : Connection refused
adb connect 192.168.0.101出现错误failed to connect to '192.168.0.101:5555': Connection refused解决办法: 1. 手机用usb线连上电脑 2. adb tcpip 5555 3. adb connect 192.168.0.101connected to 192.168.0.104:5555连接成功
2020年08月24日
547 阅读
0 评论
0 点赞
1
...
3
4
5
6