主頁 > 移動端開發 > andriod andserver 全域轉發(部分介面在本地)

andriod andserver 全域轉發(部分介面在本地)

2021-12-22 08:40:45 移動端開發

安卓 andserver 全域轉發(部分介面在本地)的實作思路

  • 前言
    • 參考資料
  • 實作思路
      • 業務需求
      • 瓶頸
      • 思考
      • 最終解決
      • 升級版本

前言

AndServer 是 Android 平臺的 Web Server 和 Web Framework, 它基于編譯時注解提供了類似 SpringMVC 的注解和功能,如果您熟悉 SpringMVC,則可以非常快速地掌握它,----yanzhenjie

參考資料

鏈接:原始碼地址 https://github.com/yanzhenjie/AndServer/.
鏈接:檔案地址 https://yanzhenjie.github.io/AndServer/.
鏈接:舊版檔案 https://yanzhenjie.github.io/AndServer/1.x/.

實作思路

業務需求

專案采用了andserver的架構來實作一個安卓端的網路框架,由一個webview套一個網頁發請求到andserver,但是很多介面是需要中臺處理的,

安卓端代碼大概是這樣的:
專案前期在andserver的介面接收到請求后,使用retrofit轉發給中臺,接收到中臺的請求后,再由andserver回傳給網頁;甚至有的介面需要在安卓端做一些處理然后再轉發,

    @RequestMapping(method = {RequestMethod.OPTIONS, RequestMethod.GET}, path = "/test")
    public AndroidResponse test(@RequestParam("organizationId") String store, @RequestParam("customerId") String customer) throws IOException {
        AndroidResponse response = new AndroidResponse();
        //這里可以自己做處理(請求前)
        Call<AndroidResponse> call = api.test(store, customer);
        Response<AndroidResponse> responseResponse = call.execute();
        if (!responseResponse.isSuccessful() || responseResponse.errorBody() != null) {
            Logger.err("Unable to sysLookupItem request:isSuccessful" + responseResponse.isSuccessful() + ",errorBody:" + responseResponse.errorBody());
//                throw new RuntimeException("Unable to reqeust");
            List<LookupitemModel> lookupitemModels = offlineLookupitem();
            if (lookupitemModels != null) {
                response .setData(lookupitemModels);
            }
            return response ;
        }
        response = responseResponse.body();
        //這里可以自己做處理(請求后)
        return response ;
    }

瓶頸

前面寫的挺順暢的,看到這兒大家可能都覺得沒什么問題,這確實是一個能解決問題的方案,但是有一天前后臺的介面因為業務需求進行了一些改動,比如加了個入參之類的,這個時候安卓端不僅需要改動andserver的api,還需要改動retrofit的api,改一個介面沒有問題,改兩個介面也沒有問題,但是當改動的介面涉及到整個專案,且專案比較趕的時候,這個問題就很大了,

架構師說:“我們必須要有一個全域的轉發,然后還不能全轉發,一些調硬體的介面得你自己處理,一些登錄的初始化你的攔截做了處理然后發中臺…”

我的內心:“/-+!@#¥%&**”

我的回答:“好的,我下去看看”
在這里插入圖片描述

思考

然后就是查資料哇,面向百度編程嘛,開始我就想,既然andserver提供了類似 SpringMVC 的注解和功能,我是不是可以通過Interceptor攔截器來實作然后把檔案墻放好,一頭撞了上去

andserver的檔案是這么解釋的:
鏈接: HandlerInterceptor https://yanzhenjie.com/AndServer/class/HandlerInterceptor.html.

import com.aw.ccpos.client.logger.Logger;
import com.yanzhenjie.andserver.annotation.Interceptor;
import com.yanzhenjie.andserver.framework.HandlerInterceptor;
import com.yanzhenjie.andserver.framework.handler.RequestHandler;
import com.yanzhenjie.andserver.http.HttpRequest;
import com.yanzhenjie.andserver.http.HttpResponse;

import androidx.annotation.NonNull;

@Interceptor
public class SysInterceptor implements HandlerInterceptor {

    /**
     * Intercept the execution of a handler.
     *
     * @param request  current request.
     * @param response current response.
     * @param handler  the corresponding handler of the current request.
     * @return true if the interceptor has processed the request and responded.
     */
    @Override
    public boolean onIntercept(@NonNull HttpRequest request, @NonNull HttpResponse response, @NonNull RequestHandler handler) throws Exception {
        RequestModel requestModel = new RequestModel();
        String app = request.getHeader("app");
        requestModel.setApp(app);
        String token = request.getHeader("x-token");
        requestModel.setToken(token);
        String storeId = request.getHeader("storeId");
        requestModel.setStoreId(storeId);
        String terminalId = request.getHeader("terminalId");
        requestModel.setTerminalId(terminalId);
        String terminalNo = request.getHeader("terminalNo");
        requestModel.setTerminalNo(terminalNo);

        String organizationId = request.getHeader("organizationId");
        requestModel.setOrganizationId(organizationId);

        String userid = request.getHeader("userid");
        requestModel.setUserid(userid);

        String username = request.getHeader("username");
        requestModel.setUsername(username);

        String displayName = request.getHeader("displayname");
        requestModel.setDisplayName(displayName);

        String customerId = request.getHeader("terminalCustomerId");
        requestModel.setCustomerId(customerId);

        String storeCode = request.getHeader("storeCode");
        requestModel.setStoreCode(storeCode);

        String sName = request.getHeader("storeName");
        requestModel.setStoreNameOriginal(sName);

        SysUtil.create(requestModel);
        Logger.d("SysInterceptor check : requestModel " + requestModel);

        //外部鏈接拒絕訪問
//        String ip = request.getHeader("Host");
//        if (!ip.equals("0.0.0.0:8080")){
//            Logger.w("External address access, blocked");
//            return true;
//        }
        return false;
    }
}

示例中寫的功能和我們需要轉發的介面功能差不多,看到過后我就開擼代碼,擼完一跑,確實能攔截到,可以轉發,就是所有的介面都被攔截了,我一個介面都別想處理,有的同學就說了,你每一個要處理的url判斷一下放過去不就行了?
在這里插入圖片描述
確實可以,沒有問題,但是這個方法和第一種有什么區別呢?所以還是另尋它法吧

最終解決

ExeceptionResolver
鏈接: ExeceptionResolverhttps://yanzhenjie.com/AndServer/class/ExceptionResolver.html.
andserver的檔案是這么解釋的:
ExeceptionResolver用來處理所有請求Http Api時發生的例外,默認情況下會輸出例外的Message到客戶端,

這個時候又有同學要說了,看起來和我們需求沒關系啊
在這里插入圖片描述
別著急,我給你講講我清晰的腦回路,當我們本地有介面的時候,andserver正常走介面,我們正常處理然后回傳,需要在介面中請求中臺就使用retrofit,介面有改動安卓端必須跟著改,這個是無法避免的,但是如果是直接轉發走的介面,我們自定義的ExeceptionResolver就會捕獲到例外然后從新轉發出去就好了
代碼如下:

import com.aw.ccpos.client.Client;
import com.aw.ccpos.client.logger.Logger;
import com.yanzhenjie.andserver.annotation.Resolver;
import com.yanzhenjie.andserver.error.MethodNotSupportException;
import com.yanzhenjie.andserver.error.NotFoundException;
import com.yanzhenjie.andserver.framework.ExceptionResolver;
import com.yanzhenjie.andserver.framework.body.JsonBody;
import com.yanzhenjie.andserver.http.HttpMethod;
import com.yanzhenjie.andserver.http.HttpRequest;
import com.yanzhenjie.andserver.http.HttpResponse;
import com.yanzhenjie.andserver.http.RequestBody;

import java.util.HashMap;
import java.util.Map;

import androidx.annotation.NonNull;

/**
 * @ProjectName : 
 * @Author : yifeng_zeng
 * @Time : 2021/2/5 10:09
 * @Description : Andserver GlobalExceptionSolver
 */
@Resolver
public class GlobalExceptionSolver implements ExceptionResolver {
    @Override
    public void onResolve(@NonNull HttpRequest request, @NonNull HttpResponse response, @NonNull Throwable e) {
        HttpMethod method = request.getMethod();
	//GlobalException后面再說
        if (!(e instanceof NotFoundException) && !(e instanceof MethodNotSupportException)
                && !(e instanceof GlobalException)) {
            Logger.err("handle request failed", e);
            return;
        }
        String uri = request.getURI();
        uri = uri.replace("scheme:", "");
//        uri = uri.replace("/spin/user","/user");
        if (uri.startsWith("/")) {
            uri = uri.substring(1);
        }
        Logger.i("redirect with URI " + uri);
        String url = Client.i().getServerUrl() + uri;

       	Logger.i("redirect to url " + url);
        String terminalId = request.getHeader("terminalId");
        SysUtil.requestModelLocal.setTerminalId(terminalId);

        String token = request.getHeader("x-token");
        SysUtil.requestModelLocal.setToken(token);

        String terminalNo = request.getHeader("terminalNo");
         SysUtil.requestModelLocal.setTerminalNo(terminalNo);

        String organizationId = request.getHeader("organizationId");
         SysUtil.requestModelLocal.setOrganizationId(organizationId);

        switch (method) {
            case POST:
                try {
                    RequestBody body = request.getBody();
                    String string = body.string();
                    if (e instanceof GlobalException){
                        string = e.getMessage();
                    }
                    Map<String, String> headers = new HashMap<>();
                    for (String header : request.getHeaderNames()) {
                        headers.put(header, request.getHeader(header));
                    }
//                    List<Cookie> cookies= request.getCookies();
                    String result = HttpUtils.postSync(url, string, headers);
                    response.setBody(new JsonBody(result));

                } catch (Exception ioException) {
                    Logger.err("Exception redirect post", ioException);
                }
                break;
            case GET:
                try {
                    Map<String, String> parameters = new HashMap<>();
//                    for (String parameter : request.getParameterNames()) {
//                        parameters.put(parameter, request.getParameter(parameter));
//                    }

                    Map<String, String> headers = new HashMap<>();
                    for (String header : request.getHeaderNames()) {
                        headers.put(header, request.getHeader(header));
                    }

                    String result = HttpUtils.getSync(url, headers, parameters);
                    response.setBody(new JsonBody(result));

                } catch (Exception ioException) {
                    Logger.err("Exception redirect get", ioException);
                }

                break;
            case DELETE:
                try {
                    Map<String, String> parameters = new HashMap<>();
                    for (String parameter : request.getParameterNames()) {
                        parameters.put(parameter, request.getParameter(parameter));
                    }
                    Map<String, String> headers = new HashMap<>();
                    for (String header : request.getHeaderNames()) {
                        headers.put(header, request.getHeader(header));
                    }
                    if (parameters.size() == 0) {
                        RequestBody body = request.getBody();
                        String string = body.string();
                        if (e instanceof GlobalException){
                            string = e.getMessage();
                        }
                        String result = HttpUtils.deleteSync(url, string, headers);
                        response.setBody(new JsonBody(result));
                    } else {
                        String result = HttpUtils.deleteSync(url, headers, parameters);
                        response.setBody(new JsonBody(result));
                    }


                } catch (Exception ioException) {
                    Logger.err("Exception redirect DELETE", ioException);
                }
                break;

            case PUT:
                try {
                    RequestBody body = request.getBody();
                    String string = body.string();
                    if (e instanceof GlobalException){
                        string = e.getMessage();
                    }
                    Map<String, String> headers = new HashMap<>();
                    for (String header : request.getHeaderNames()) {
                        headers.put(header, request.getHeader(header));
                    }
                    String result = HttpUtils.putSync(url, string, headers);
                    response.setBody(new JsonBody(result));

                } catch (Exception ioException) {
                    Logger.err("Exception redirect PUT", ioException);
                }

        }
    }

}

有伸手黨就要說了,我沒有你轉發這個HttpUtils,我又難得找,你想不想要贊啊,emmm
在這里插入圖片描述

import java.io.IOException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;
import java.util.concurrent.TimeUnit;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class HttpUtils {

    public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
    public static OkHttpClient client = new OkHttpClient.Builder().
    connectTimeout(300, TimeUnit.SECONDS).
    readTimeout(300, TimeUnit.SECONDS)
    .sslSocketFactory(HttpsUtils.getSslSocketFactory(null,null,null))
    .hostnameVerifier(new HostnameVerifier() {
        @Override
        public boolean verify(String hostname, SSLSession session) {
            return true;
        }
    }).writeTimeout(300, TimeUnit.SECONDS).addInterceptor(new Interceptor() {
        @Override
        public Response intercept(Chain chain) throws IOException {
            Request.Builder builder = chain.request()
                    .newBuilder();
            if (SysUtil.get().getToken() != null) {
                builder.addHeader("x-token", SysUtil.get().getToken());
            }
            if (SysUtil.get().getOrganizationId() != null) {
                builder.addHeader("organizationId", SysUtil.get().getOrganizationId());
            }
            if (SysUtil.get().getTerminalId() != null) {
                builder.addHeader("terminalId", SysUtil.get().getTerminalId());
            }
            if (SysUtil.get().getTerminalNo() != null) {
                builder.addHeader("terminalNo", SysUtil.get().getTerminalNo());
            }
            Request request = builder.build();
            return chain.proceed(request);
        }
    }).build();
    /*
     *�?http post����
     */
    public static void postAsync(String url, String body) throws Exception {

        RequestBody params = RequestBody.create(JSON, body);
        Request request = new Request.Builder().addHeader("Content-Type", "application/json").url(url).post(params).build();
        try {
            Call call = client.newCall(request);
            call.enqueue(new Callback() {
                @Override
                public void onFailure(Call call, IOException e) {

                }

                @Override
                public void onResponse(Call call, Response response) throws IOException {
                    if (response.isSuccessful()) {
                        response.body().string();
                    }
                }
            });
        } catch (Exception e) {
            throw e;
        }
    }

    /*
     * �?http get����
     */
    public static void getAsync(String url, String body) throws Exception {

        Request request = new Request.Builder().addHeader("Content-Type", "application/json").url(url).get().build();
        try {
            Call call = client.newCall(request);
            call.enqueue(new Callback() {
                @Override
                public void onFailure(Call call, IOException e) {

                }

                @Override
                public void onResponse(Call call, Response response) throws IOException {
                    if (response.isSuccessful()) {
                        response.body().string();
                    }
                }
            });
        } catch (Exception e) {
            throw e;
        }
    }

    /*
     * ?��http post����
     */
    public static String postSync(String url, String body, Map<String, String> headers) throws Exception {

        String returnMessage = "";
        RequestBody params = RequestBody.create(JSON, body);
        Request.Builder builder = new Request.Builder();
        builder.addHeader("Content-Type", "application/json");
        for (Map.Entry<String, String> header : headers.entrySet()) {
            builder.addHeader(header.getKey(), header.getValue());
        }
        Request request = builder.url(url).post(params).build();

        try {
            Response response = client.newCall(request).execute();
            if (response.isSuccessful()) {

                returnMessage = response.body().string();
            } else {
                Exception e = new Exception("�������?��?��" + response.code() + ":" + response.message());
                throw e;
            }
        } catch (UnknownHostException e) {

            throw e;
        } catch (ConnectException e) {

            throw e;
        } catch (SocketTimeoutException e) {

            throw e;
        } catch (Exception e) {

            throw e;
        }
        return returnMessage;
    }

    /*
     * ?��http get����
     */
    public static String getSync(String url,Map<String, String> headers,Map<String, String> params) throws Exception {

        String returnMessage = "";

        HttpUrl.Builder httpBuilder = HttpUrl.parse(url).newBuilder();

        if (params != null) {
            for (Map.Entry<String, String> param : params.entrySet()) {
                httpBuilder.addQueryParameter(param.getKey(), param.getValue());
            }
        }

        Request.Builder builder = new Request.Builder();
        builder.addHeader("Content-Type", "application/json");

        for (Map.Entry<String, String> header : headers.entrySet()) {
            builder.addHeader(header.getKey(), header.getValue());
        }
        Request request = builder.url(httpBuilder.build())
                .build();
        try {
            Response response = client.newCall(request).execute();
            if (response.isSuccessful()) {

                returnMessage = response.body().string();
            } else {
                Exception e = new Exception("" + response.code() + ":" + response.message());
                throw e;
            }
        } catch (UnknownHostException e) {

            throw e;
        } catch (ConnectException e) {

            throw e;
        } catch (SocketTimeoutException e) {

            throw e;
        } catch (Exception e) {

            throw e;
        }
        return returnMessage;
    }

    /*
    * 同步put請求*
    /

     */

    public static String putSync(String url, String body,Map<String, String> headers) throws Exception {
        String returnMessage = "";
        RequestBody params = RequestBody.create(JSON, body);
        Request.Builder builder = new Request.Builder();
        builder.addHeader("Content-Type", "application/json");
        for (Map.Entry<String, String> header : headers.entrySet()) {
            builder.addHeader(header.getKey(), header.getValue());
        }
        Request request = builder.url(url).put(params).build();
        try {
            Response response = client.newCall(request).execute();
            if (response.isSuccessful()) {

                returnMessage = response.body().string();
            } else {
                Exception e = new Exception("�������?��?��" + response.code() + ":" + response.message());
                throw e;
            }
        } catch (UnknownHostException e) {

            throw e;
        } catch (ConnectException e) {

            throw e;
        } catch (SocketTimeoutException e) {

            throw e;
        } catch (Exception e) {

            throw e;
        }
        return returnMessage;
    }

    /*
     * 同步delete請求,body
     * */
    public static String deleteSync(String url, String body,Map<String, String> headers) throws Exception {
        String returnMessage = "";
        RequestBody params = RequestBody.create(JSON, body);
        Request.Builder builder = new Request.Builder();
        builder.addHeader("Content-Type", "application/json");
        for (Map.Entry<String, String> header : headers.entrySet()) {
            builder.addHeader(header.getKey(), header.getValue());
        }
        Request request = builder.url(url).delete(params).build();
        try {
            Response response = client.newCall(request).execute();
            if (response.isSuccessful()) {

                returnMessage = response.body().string();
            } else {
                Exception e = new Exception("�������?��?��" + response.code() + ":" + response.message());
                throw e;
            }
        } catch (UnknownHostException e) {

            throw e;
        } catch (ConnectException e) {

            throw e;
        } catch (SocketTimeoutException e) {

            throw e;
        } catch (Exception e) {

            throw e;
        }
        return returnMessage;
    }

    /*
     * 同步delete請求,body
     * */
    public static String deleteSync(String url,Map<String, String> headers,Map<String, String> params) throws Exception {
        String returnMessage = "";
        HttpUrl.Builder httpBuilder = HttpUrl.parse(url).newBuilder();


        if (params != null) {
            for (Map.Entry<String, String> param : params.entrySet()) {
                httpBuilder.addQueryParameter(param.getKey(), param.getValue());
            }
        }
        Request.Builder builder = new Request.Builder();
        builder.addHeader("Content-Type", "application/json");
        for (Map.Entry<String, String> header : headers.entrySet()) {
            builder.addHeader(header.getKey(), header.getValue());
        }

        Request request = builder.addHeader("Content-Type", "application/json")
                .url(httpBuilder.build())
                .delete()
                .build();

        try {
            Response response = client.newCall(request).execute();
            if (response.isSuccessful()) {

                returnMessage = response.body().string();
            } else {
                Exception e = new Exception("�������?��?��" + response.code() + ":" + response.message());
                throw e;
            }
        } catch (UnknownHostException e) {

            throw e;
        } catch (ConnectException e) {

            throw e;
        } catch (SocketTimeoutException e) {

            throw e;
        } catch (Exception e) {

            throw e;
        }
        return returnMessage;
    }
}

升級版本

有細心的同學發現我們還有一個GlobalException的例外,這個東西是我們在andserver接收到請求,對請求處理過后不需要處理回傳的資訊的時候使用的自定義Exception;可以根據你們自己的業務需求取用

/**
 * 
 * @Author : yifeng_zeng
 * @Time : 2021/11/5 14:22
 * @Description : 全域轉發例外,為了把body傳給GlobalExceptionSolver
 */
public class GlobalException extends BasicException {
    private static int statusCode = 100;

    public GlobalException(DataRequest request) {
        super(statusCode,JSON.toJSONString(request));
    }

    public GlobalException(String request) {
        super(statusCode,request);
    }
}

使用

@Override
	@RequestMapping(method = {RequestMethod.OPTIONS, RequestMethod.POST}, path = "/finishOrderSale")
	public Response finishOrderSale(@RequestBody Request requestModel)throws IOException{
		if (requestModel.getData()!=null){
		//這里可以對requestModel進行處理
			throw new GlobalException(requestModel);
		}
		Response  response = new  Response();
		return response;
	}

這個時候,坐在螢屏前的你是不是應該說一句:“秒啊!”
在這里插入圖片描述

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/389201.html

標籤:其他

上一篇:Android實作流光效果、光影移動效果

下一篇:Android開發之串列點擊事件定義的一些思考

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【從零開始擼一個App】Dagger2

    Dagger2是一個IOC框架,一般用于Android平臺,第一次接觸的朋友,一定會被搞得暈頭轉向。它延續了Java平臺Spring框架代碼碎片化,注解滿天飛的傳統。嘗試將各處代碼片段串聯起來,理清思緒,真不是件容易的事。更不用說還有各版本細微的差別。 與Spring不同的是,Spring是通過反射 ......

    uj5u.com 2020-09-10 06:57:59 more
  • Flutter Weekly Issue 66

    新聞 Flutter 季度調研結果分享 教程 Flutter+FaaS一體化任務編排的思考與設計 詳解Dart中如何通過注解生成代碼 GitHub 用對了嗎?Flutter 團隊分享如何管理大型開源專案 插件 flutter-bubble-tab-indicator A Flutter librar ......

    uj5u.com 2020-09-10 06:58:52 more
  • Proguard 常用規則

    介紹 Proguard 入口,如何查看輸出,如何使用 keep 設定入口以及使用實體,如何配置壓縮,混淆,校驗等規則。

    ......

    uj5u.com 2020-09-10 06:59:00 more
  • Android 開發技術周報 Issue#292

    新聞 Android即將獲得類AirDrop功能:可向附近設備快速分享檔案 谷歌為安卓檔案管理應用引入可安全隱藏資料的Safe Folder功能 Android TV新主界面將顯示電影、電視節目和應用推薦內容 泄露的Android檔案暗示了傳說中的谷歌Pixel 5a與折疊屏新機 谷歌發布Andro ......

    uj5u.com 2020-09-10 07:00:37 more
  • AutoFitTextureView Error inflating class

    報錯: Binary XML file line #0: Binary XML file line #0: Error inflating class xxx.AutoFitTextureView 解決: <com.example.testy2.AutoFitTextureView android: ......

    uj5u.com 2020-09-10 07:00:41 more
  • 根據Uri,Cursor沒有獲取到對應的屬性

    Android: 背景:呼叫攝像頭,拍攝視頻,指定保存的地址,但是回傳的Cursor檔案,只有名稱和大小的屬性,沒有其他諸如時長,連ID屬性都沒有 使用 cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATIO ......

    uj5u.com 2020-09-10 07:00:44 more
  • Android連載29-持久化技術

    一、持久化技術 我們平時所使用的APP產生的資料,在記憶體中都是瞬時的,會隨著斷電、關機等丟失資料,因此android系統采用了持久化技術,用于存盤這些“瞬時”資料 持久化技術包括:檔案存盤、SharedPreference存盤以及資料庫存盤,還有更復雜的SD卡記憶體儲。 二、檔案存盤 最基本存盤方式, ......

    uj5u.com 2020-09-10 07:00:47 more
  • Android Camera2Video整合到自己專案里

    背景: Android專案里呼叫攝像頭拍攝視頻,原本使用的 MediaStore.ACTION_VIDEO_CAPTURE, 后來因專案需要,改成了camera2 1.Camera2Video 官方demo有點問題,下載后,不能直接整合到專案 問題1.多次拍攝視頻崩潰 問題2.雙擊record按鈕, ......

    uj5u.com 2020-09-10 07:00:50 more
  • Android 開發技術周報 Issue#293

    新聞 谷歌為Android TV開發者提供多種新功能 Android 11將自動填表功能整合到鍵盤輸入建議中 谷歌宣布Android Auto即將支持更多的導航和數字停車應用 谷歌Pixel 5只有XL版本 搭載驍龍765G且將比Pixel 4更便宜 [圖]Wear OS將迎來重磅更新:應用啟動時間 ......

    uj5u.com 2020-09-10 07:01:38 more
  • 海豚星空掃碼投屏 Android 接收端 SDK 集成 六步驟

    掃碼投屏,開放網路,獨占設備,不需要額外下載軟體,微信掃碼,發現設備。支持標準DLNA協議,支持倍速播放。視頻,音頻,圖片投屏。好點意思。還支持自定義基于 DLNA 擴展的操作動作。好像要收費,沒體驗。 這里簡單記錄一下集成程序。 一 跟目錄的build.gradle添加私有mevan倉庫 mave ......

    uj5u.com 2020-09-10 07:01:43 more
最新发布
  • 歡迎頁輪播影片

    如圖,引導開始,球從上落下,同時淡入文字,然后文字開始輪播,最后一頁時停止,點擊進入首頁。 在來看看效果圖。 重力球先不講,主要歡迎輪播簡單實作 首先新建一個類 TextTranslationXGuideView,用于影片展示 文本是類似的,最后會有個圖片箭頭影片,布局很簡單,就是一個 TextVi ......

    uj5u.com 2023-04-20 08:40:31 more
  • 【FAQ】關于華為推送服務因營銷訊息頻次管控導致服務通訊類訊息

    一. 問題描述 使用華為推送服務下發IM訊息時,下發訊息請求成功且code碼為80000000,但是手機總是收不到訊息; 在華為推送自助分析(Beta)平臺查看發現,訊息發送觸發了頻控。 二. 問題原因及背景 2023年1月05日起,華為推送服務對咨詢營銷類訊息做了單個設備每日推送數量上限管理,具體 ......

    uj5u.com 2023-04-20 08:40:11 more
  • 歡迎頁輪播影片

    如圖,引導開始,球從上落下,同時淡入文字,然后文字開始輪播,最后一頁時停止,點擊進入首頁。 在來看看效果圖。 重力球先不講,主要歡迎輪播簡單實作 首先新建一個類 TextTranslationXGuideView,用于影片展示 文本是類似的,最后會有個圖片箭頭影片,布局很簡單,就是一個 TextVi ......

    uj5u.com 2023-04-20 08:39:36 more
  • 【FAQ】關于華為推送服務因營銷訊息頻次管控導致服務通訊類訊息

    一. 問題描述 使用華為推送服務下發IM訊息時,下發訊息請求成功且code碼為80000000,但是手機總是收不到訊息; 在華為推送自助分析(Beta)平臺查看發現,訊息發送觸發了頻控。 二. 問題原因及背景 2023年1月05日起,華為推送服務對咨詢營銷類訊息做了單個設備每日推送數量上限管理,具體 ......

    uj5u.com 2023-04-20 08:39:13 more
  • iOS從UI記憶體地址到讀取成員變數(oc/swift)

    開發除錯時,我們發現bug時常首先是從UI顯示發現例外,下一步才會去定位UI相關連的資料的。XCode有給我們提供一系列debug工具,但是很多人可能還沒有形成一套穩定的除錯流程,因此本文嘗試解決這個問題,順便提出一個暴論:UI顯示例外問題只需要兩個步驟就能完成定位作業的80%: 定位例外 UI 組 ......

    uj5u.com 2023-04-19 09:16:23 more
  • FIDE重磅更新!性能飛躍!體驗有禮!

    FIDE 開發者工具重構升級啦!實作500%性能提升,誠邀體驗! 一直以來不少開發者朋友在社區反饋,在使用 FIDE 工具的程序中,時常會遇到諸如加載不及時、代碼預覽/渲染性能不如意的情況,十分影響開發體驗。 作為技術團隊,我們深知一件趁手的開發工具對開發者的重要性,因此,在2023年開年,FinC ......

    uj5u.com 2023-04-19 09:16:15 more
  • 游戲內嵌社區服務開放,助力開發者提升玩家互動與留存

    華為 HMS Core 游戲內嵌社區服務提供快速訪問華為游戲中心論壇能力,支持玩家直接在游戲內瀏覽帖子和交流互動,助力開發者擴展內容生產和觸達的場景。 一、為什么要游戲內嵌社區? 二、游戲內嵌社區的典型使用場景 1、游戲內打開論壇 您可以在游戲內繪制論壇入口,為玩家提供沉浸式發帖、瀏覽、點贊、回帖、 ......

    uj5u.com 2023-04-19 09:15:46 more
  • iOS從UI記憶體地址到讀取成員變數(oc/swift)

    開發除錯時,我們發現bug時常首先是從UI顯示發現例外,下一步才會去定位UI相關連的資料的。XCode有給我們提供一系列debug工具,但是很多人可能還沒有形成一套穩定的除錯流程,因此本文嘗試解決這個問題,順便提出一個暴論:UI顯示例外問題只需要兩個步驟就能完成定位作業的80%: 定位例外 UI 組 ......

    uj5u.com 2023-04-19 09:14:53 more
  • FIDE重磅更新!性能飛躍!體驗有禮!

    FIDE 開發者工具重構升級啦!實作500%性能提升,誠邀體驗! 一直以來不少開發者朋友在社區反饋,在使用 FIDE 工具的程序中,時常會遇到諸如加載不及時、代碼預覽/渲染性能不如意的情況,十分影響開發體驗。 作為技術團隊,我們深知一件趁手的開發工具對開發者的重要性,因此,在2023年開年,FinC ......

    uj5u.com 2023-04-19 09:14:08 more
  • 游戲內嵌社區服務開放,助力開發者提升玩家互動與留存

    華為 HMS Core 游戲內嵌社區服務提供快速訪問華為游戲中心論壇能力,支持玩家直接在游戲內瀏覽帖子和交流互動,助力開發者擴展內容生產和觸達的場景。 一、為什么要游戲內嵌社區? 二、游戲內嵌社區的典型使用場景 1、游戲內打開論壇 您可以在游戲內繪制論壇入口,為玩家提供沉浸式發帖、瀏覽、點贊、回帖、 ......

    uj5u.com 2023-04-19 09:08:34 more