使用 GsonFormat 解析数组形式的 json 作者: Chuwen 时间: 2020-10-12 分类: Android,Java 评论 > 记下笔记,以访忘记 # 假设有以下数据 ``` [{ "CarId": 1, "Time": "2017-11-26 16:58:11", "Cost": 10 }, { "CarId": 1, "Time": "2017-11-26 16:58:19", "Cost": 20 }, { "CarId": 1, "Time": "2017-11-26 16:58:24", "Cost": 30 }, { "CarId": 1, "Time": "2017-11-26 16:58:28", "Cost": 40 }] ``` # 以下类 ``` public class GetCarAccountRecord { /** * CarId : 1 * Time : 2017-11-26 04:58:11 * Cost : 10 */ private int CarId; private String Time; private int Cost; public int getCarId() { return CarId; } public void setCarId(int CarId) { this.CarId = CarId; } public String getTime() { return Time; } public void setTime(String Time) { this.Time = Time; } public int getCost() { return Cost; } public void setCost(int Cost) { this.Cost = Cost; } } ``` # 使用 Gson 解析,然后遍历输出 ``` List list = new Gson().fromJson(jsonObject.optJSONArray("ROWS_DETAIL").toString(), new TypeToken>() {}.getType()); for (GetCarAccountRecord getCarAccountRecord : list) { Log.i("小车编号:", String.valueOf(getCarAccountRecord.getCarId())); Log.i("充值金额:", String.valueOf(getCarAccountRecord.getCost())); } ```
Android 使用 OkHttp 进行网络请求之 POST json数据 作者: Chuwen 时间: 2020-07-12 分类: Android 评论 # 相关代码 > 只是避免遗忘,然后记录下的,具体还是要自己去搜索 ``` OkHttpClient okHttpClient = new OkHttpClient(); //指定媒体类型 MediaType mediaType = MediaType.parse("application/json"); RequestBody requestBody = RequestBody.create(mediaType, json); Request request = new Request.Builder() .url(url) .post(requestBody) .build(); okHttpClient.newCall(request).enqueue(new Callback() { @Override public void onResponse(Call call, Response response) throws IOException { SetSuggesRes = response.body().string(); Log.d("请求成功", SetSuggesRes); /** * 在Ui线程更新UI */ runOnUiThread(new Runnable() { @Override public void run() { requestDialog.hide();//隐藏那个加载对话框 try { JSONObject resObj = new JSONObject(SetSuggesRes); if (resObj.getString("RESULT").equals("S")) { showNormalDialog("意见反馈", "意见反馈成功!", 1); } else { showNormalDialog("意见反馈", "意见反馈失败,原因:" + resObj.getString("ERRMSG").toString(), 2); } } catch (JSONException e) { e.printStackTrace(); showNormalDialog("意见反馈", "意见反馈失败,原因(远程服务器返回内容不符合预期):\n" + e.getMessage().toString(), 2); } } }); } @Override public void onFailure(Call call, final IOException e) { Log.d("请求失败", e.getMessage().toString()); runOnUiThread(new Runnable() { @Override public void run() { requestDialog.hide(); showNormalDialog("意见反馈", "意见反馈失败了,原因:\n" + e.getMessage(), 2); } }); } }); ```
Andoid 解决非主线程更新UI问题 作者: Chuwen 时间: 2020-07-12 分类: Android 评论 # 使用以下代码即可 ``` runOnUiThread(new Runnable() { @Override public void run() { //更新UI } }); ```
Android 加了电话权限,运行还是闪退报错 作者: Chuwen 时间: 2019-12-07 分类: Android 评论 `AndroidManifest.xml` 文件 ``` ``` # 运行报错 ``` D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: cc.nowtime.seven, PID: 12685 java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:xxxxx cmp=com.android.server.telecom/.components.UserCallActivity } from ProcessRecord{e2ed078 12685:cc.nowtime.seven/u0a135} (pid=12685, uid=10135) with revoked permission android.permission.CALL_PHONE at android.os.Parcel.createException(Parcel.java:2071) at android.os.Parcel.readException(Parcel.java:2039) at android.os.Parcel.readException(Parcel.java:1987) at android.app.IActivityTaskManager$Stub$Proxy.startActivity(IActivityTaskManager.java:3851) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1705) at android.app.Activity.startActivityForResult(Activity.java:5192) at android.app.Activity.startActivityForResult(Activity.java:5150) at android.app.Activity.startActivity(Activity.java:5521) at android.app.Activity.startActivity(Activity.java:5489) at cc.nowtime.seven.MainActivity$1.onClick(MainActivity.java:36) at android.view.View.performClick(View.java:7125) at android.view.View.performClickInternal(View.java:7102) at android.view.View.access$3500(View.java:801) at android.view.View$PerformClick.run(View.java:27336) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) Caused by: android.os.RemoteException: Remote stack trace: at com.android.server.wm.ActivityStackSupervisor.checkStartAnyActivityPermission(ActivityStackSupervisor.java:1043) at com.android.server.wm.ActivityStarter.startActivity(ActivityStarter.java:760) at com.android.server.wm.ActivityStarter.startActivity(ActivityStarter.java:583) at com.android.server.wm.ActivityStarter.startActivityMayWait(ActivityStarter.java:1288) at com.android.server.wm.ActivityStarter.execute(ActivityStarter.java:514) Process 12685 terminated. ``` > ` java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:xxxxx cmp=com.android.server.telecom/.components.UserCallActivity } from ProcessRecord{e2ed078 12685:cc.nowtime.seven/u0a135} (pid=12685, uid=10135) with revoked permission android.permission.CALL_PHONE` # 原因 你的 APP 添加**拨打电话权限**,但是未申请拨打电话权限,所以报错,解决办法: - **APP 主动申请获取** 拨打电话权限 - **手动授予** 拨打电话权限 # 主动授予拨打电话权限 1. 打开 **设置** > **应用和通知** 2. **找到你的应用** ![Snipaste_2019-12-07_20-13-40.png][1] 3. 然后允许对应权限就可以了 ![Snipaste_2019-12-07_20-14-38.png][2] # APP 主动申请获取 拨打电话权限 > 自己百度 ❀???? [1]: https://cdn.nowtime.cc/2019/12/07/512779244.png [2]: https://cdn.nowtime.cc/2019/12/07/1174856951.png
Magisk 卡刷包下载地址 | Magisk v19.0 作者: Chuwen 时间: 2019-04-16 分类: Android 评论 # Magisk 官方发布页 > https://github.com/topjohnwu/Magisk/releases > PS:由于某种原因,国内无法下载,需要特殊方法才能下载,所以我保存到了云盘,可以很快的下载到 # 第三方网盘下载: > 蓝奏云[**荐**]:https://www.lanzous.com/b680805