分类 Android 下的文章

Android 使用 OkHttp 进行网络请求之 POST json数据

相关代码

只是避免遗忘,然后记录下的,具体还是要自己去搜索
        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);
                    }
                });
            }
        });

Android 加了电话权限,运行还是闪退报错

AndroidManifest.xml 文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="cc.nowtime.seven">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="GoogleAppIndexingWarning">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <!--拨打电话权限-->
    <uses-permission android:name="android.permission.CALL_PHONE" />

    <!--拨打电话权限-->
    <uses-permission android:name="android.permission.SEND_SMS"/>

</manifest>

运行报错

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
  3. 然后允许对应权限就可以了
    Snipaste_2019-12-07_20-14-38.png

APP 主动申请获取 拨打电话权限

自己百度 ❀????

Android 9.0(Pie) GApps arm,arm64 下载

Android Pie ARM64 GApps 下载地址:

https://builds.nezorfla.me/?dir=opengapps/pie/arm64

找到一个最近日期的目录,选择适合自己的 GApps,进 recovery 刷入即可

注:micro GApps 及以上 包含 人脸解锁

Android Pie ARM GApps 下载地址:

https://builds.nezorfla.me/?dir=opengapps/pie/arm

找到一个最近日期的目录,选择适合自己的 GApps,进 recovery 刷入即可

注:micro GApps 及以上 包含 人脸解锁