日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網(wǎng)為廣大站長提供免費收錄網(wǎng)站服務(wù),提交前請做好本站友鏈:【 網(wǎng)站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(wù)(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

準(zhǔn)備資料

接口準(zhǔn)備

準(zhǔn)備get請求接

 

Post接口

 

如何集成

在項目級別的build.gradle添加如下代碼

<pre class="prettyprint hljs Nginx" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">allprojects {
    repositories {
        maven {
            url 'https://repo.huaweicloud.com/repository/maven/'
        }
        maven {
            url 'https://developer.huawei.com/repo/'</pre>

在entry的build.gradle添加如下代碼

<pre class="prettyprint hljs delphi" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">'io.openharmony.tpc.thirdlib:okgo:1.0.2'
    implementation 'io.openharmony.tpc.thirdlib:okrx:1.0.2'
    implementation 'io.openharmony.tpc.thirdlib:okrx2:1.0.2'
    implementation 'io.openharmony.tpc.thirdlib:okserver:1.0.2'</pre>

在entry的config.json添加 權(quán)限 ? 代碼如下

<pre class="prettyprint hljs lua" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">"reqPermissions": [
      {
        "name": "ohos.permission.INTE.NET"</pre>

注意事項

如果接口是https的話需要在config.json的deviceConfig里添加如下代碼

<pre class="prettyprint hljs lua" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">"deviceConfig": {
    "default": {
      "network": {
        "cleartextTraffic": true</pre>

界面實現(xiàn)

在layout的xml中寫三個Text標(biāo)簽,第一個Text用于觸發(fā)get請求的事件,第二個Text用于觸發(fā)Post請求的事件,第三個Text用于顯示結(jié)果,代碼和效果圖如下

<pre class="prettyprint hljs vim" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:alignment="horizontal_center"
    ohos:orientation="vertical">

    <Text
        ohos:id="$+id:text_type_get"
        ohos:height="100vp"
        ohos:width="match_parent"
        ohos:text_alignment="center"
        ohos:layout_alignment="horizontal_center"
        ohos:text="Get請求"
        ohos:text_size="40vp"
    <Text
        ohos:id="$+id:text_type_Post"
        ohos:height="100vp"
        ohos:text_alignment="center"
        ohos:width="match_parent"
        ohos:background_element="#ed6262"
        ohos:layout_alignment="horizontal_center"
        ohos:text="Post請求"
        ohos:text_size="40vp"
    <Text
        ohos:id="$+id:text_result"
        ohos:height="match_parent"
        ohos:multiple_lines="true"
        ohos:text_alignment="center"
        ohos:width="match_parent"
        ohos:layout_alignment="horizontal_center"
        ohos:text="顯示結(jié)果"
        ohos:text_size="40vp"

</DirectionalLayout></pre>

 

?

Get請求實現(xiàn)

在Get的Text點擊事件,實現(xiàn) ? [Get請求和請求成功之后和請求失敗之后(參考 ? 線程管理開發(fā)指導(dǎo)需要將子線程切到Ui線程進(jìn)行顯示數(shù)據(jù),代碼如下

<pre class="prettyprint hljs JAVA" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                OkHttpClient client = new OkHttpClient();
                Request.Builder requestBuilder = new Request.Builder();
                HttpUrl.Builder urlBuilder=HttpUrl.parse("http://web.juhe.cn/environment/air/cityair").newBuilder();//todo 接口鏈接
                urlBuilder.addQueryParameter("city","shanghai");//todo  參數(shù)
                urlBuilder.addQueryParameter("Key","******");// todo 密鑰 key自己申請
                requestBuilder.url(urlBuilder.build());
                Call call = client.newCall(requestBuilder.build());
                call.enqueue(new Callback() {
                    @Override
                    public void onFailure(Call call, IOException e) {
                        //todo 失敗回調(diào) 需要回到主線程顯示結(jié)果
                        getUITaskDispatcher().asyncDispatch(new Runnable() {
                            @Override
                            public void run() {
                                textResult.setText(e.getMessage());
                            }
                        });

                    }

                    @Override
                    public void onResponse(Call call, Response response) throws IOException {
                        if(response.isSuccessful()){
                            String result = response.body().string();
                            //todo 處理UI需要切換到UI線程處理
                            getUITaskDispatcher().asyncDispatch(new Runnable() {
                                @Override
                                public void</pre>

Post請求實現(xiàn)

在Post的Text實現(xiàn)點擊事件,具體參考? ?Android OkHttp常用詳解?,代碼如下

<pre class="prettyprint hljs java" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">TextPost.setClickedListener(new Component.ClickedListener() {
    @Override
    public void onClick(Component component) {
        OkHttpClient client = new OkHttpClient();
        FormBody body = new FormBody.Builder()
                .add("key","*****")// todo 密鑰 key自己申請
                .add("date","10/1")//todo 日期參數(shù)
                .build();
        Request request = new Request.Builder()
                .url("http://v.juhe.cn/todayOnhistory/queryEvent.php")
                .post(body)
                .build();
        Call call = client.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                //todo 失敗回調(diào) 需要回到主線程顯示結(jié)果
                getUITaskDispatcher().asyncDispatch(new Runnable() {
                    @Override
                    public void run() {
                        textResult.setText(e.getMessage());
                    }
                });
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if(response.isSuccessful()){
                    String result = response.body().string();
                    //處理UI需要切換到UI線程處理
                    //todo 失敗回調(diào) 需要回到主線程顯示結(jié)果
                    getUITaskDispatcher().asyncDispatch(new Runnable() {
                        @Override
                        public void</pre>

運行效果

具體代碼如下

java 代碼

<pre class="prettyprint hljs java" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">package com.harmony.alliance.myApplication.slice;

import com.harmony.alliance.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import okhttp3.*;

import java.io.IOException;

public class MainAbilitySlice extends AbilitySlice
    Text TextGet,TextPost,textResult;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        TextGet=findComponentById(ResourceTable.Id_text_type_get);
        TextPost=findComponentById(ResourceTable.Id_text_type_Post);
        textResult=findComponentById(ResourceTable.Id_text_result);
        TextGet.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                OkHttpClient client = new OkHttpClient();
                Request.Builder requestBuilder = new Request.Builder();
                HttpUrl.Builder urlBuilder=HttpUrl.parse("http://web.juhe.cn/environment/air/cityair").newBuilder();//todo 接口鏈接
                urlBuilder.addQueryParameter("city","shanghai");//todo  參數(shù)
                urlBuilder.addQueryParameter("Key","6fba58dc50a8e3d92e8a2f63d25c7750");// todo key 密鑰
                requestBuilder.url(urlBuilder.build());
                Call call = client.newCall(requestBuilder.build());
                call.enqueue(new Callback() {
                    @Override
                    public void onFailure(Call call, IOException e) {
                        //todo 失敗回調(diào) 需要回到主線程顯示結(jié)果
                        getUITaskDispatcher().asyncDispatch(new Runnable() {
                            @Override
                            public void run() {
                                textResult.setText(e.getMessage());
                            }
                        });

                    }

                    @Override
                    public void onResponse(Call call, Response response) throws IOException {
                        if(response.isSuccessful()){
                            String result = response.body().string();
                            //todo 處理UI需要切換到UI線程處理
                            getUITaskDispatcher().asyncDispatch(new Runnable() {
                                @Override
                                public void run() {
                                    textResult.setText(result);
                                }
                            });

                        }
                    }
                });
            }
        });
        TextPost.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                OkHttpClient client = new OkHttpClient();
                FormBody body = new FormBody.Builder()
                        .add("key","7496ca7e5e12c408ef14e465c2bacc79")// todo 密鑰
                        .add("date","10/1")//todo 日期參數(shù)
                        .build();
                Request request = new Request.Builder()
                        .url("http://v.juhe.cn/todayOnhistory/queryEvent.php")
                        .post(body)
                        .build();
                Call call = client.newCall(request);
                call.enqueue(new Callback() {
                    @Override
                    public void onFailure(Call call, IOException e) {
                        //todo 失敗回調(diào) 需要回到主線程顯示結(jié)果
                        getUITaskDispatcher().asyncDispatch(new Runnable() {
                            @Override
                            public void run() {
                                textResult.setText(e.getMessage());
                            }
                        });
                    }

                    @Override
                    public void onResponse(Call call, Response response) throws IOException {
                        if(response.isSuccessful()){
                            String result = response.body().string();
                            //處理UI需要切換到UI線程處理
                            //todo 失敗回調(diào) 需要回到主線程顯示結(jié)果
                            getUITaskDispatcher().asyncDispatch(new Runnable() {
                                @Override
                                public void run() {
                                    textResult.setText(result);
                                }
                            });
                        }
                    }
                });
            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}</pre>

xml 代碼

<pre class="prettyprint hljs vim" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:alignment="horizontal_center"
    ohos:orientation="vertical">

    <Text
        ohos:id="$+id:text_type_get"
        ohos:height="100vp"
        ohos:width="match_parent"
        ohos:text_alignment="center"
        ohos:layout_alignment="horizontal_center"
        ohos:text="Get請求"
        ohos:text_size="40vp"
    <Text
        ohos:id="$+id:text_type_Post"
        ohos:height="100vp"
        ohos:text_alignment="center"
        ohos:width="match_parent"
        ohos:background_element="#ed6262"
        ohos:layout_alignment="horizontal_center"
        ohos:text="Post請求"
        ohos:text_size="40vp"
    <Text
        ohos:id="$+id:text_result"
        ohos:height="match_parent"
        ohos:multiple_lines="true"
        ohos:text_alignment="center"
        ohos:width="match_parent"
        ohos:layout_alignment="horizontal_center"
        ohos:text="顯示結(jié)果"
        ohos:text_size="40vp"

</DirectionalLayout></pre>

運行效果如下

 

分享到:
標(biāo)簽:鴻蒙
用戶無頭像

網(wǎng)友整理

注冊時間:

網(wǎng)站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨大挑戰(zhàn)2018-06-03

數(shù)獨一種數(shù)學(xué)游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學(xué)四六

運動步數(shù)有氧達(dá)人2018-06-03

記錄運動步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓(xùn)練成績評定2018-06-03

通用課目體育訓(xùn)練成績評定