Code Monkey home page Code Monkey logo

catroomandroidnotes's Introduction

catroomAndroidnotes

个人安卓编程遇到难题或者资料的笔记

catroomandroidnotes's People

Contributors

catroom avatar

Stargazers

 avatar

Watchers

 avatar  avatar

catroomandroidnotes's Issues

webview的http错误码404等接收不了

http://www.lai18.com/content/1513532.html这个文章是没有用的。要webivew接收http的错误码
@OverRide
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
Log.d(LOG_TAG, "onReceivedHttpError: "+errorResponse.getStatusCode()+" "+errorResponse.getReasonPhrase());
super.onReceivedHttpError(view, request, errorResponse);
}
http://charlee.li/android-load-cert-err-ssl-in-webview.html
http://wolfeye.baidu.com/blog/webview-ignore-ssl-error/
https://www.servertastic.com/support/error-111-net-err-tunnel-connection-failed-unknown-error
接收不了ssl的即https的错误码
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {

检测当前插入的卡运营商和手机号码的运营商

`public class CarrieroperatorUtils {
private static String LOG_TAG = "carr";
private static String imsi;

/**
 * 获取当前sim的运营商信息
 */
public static int getCurrentCarInfo(Context context){
    TelephonyManager systemService = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (systemService != null) {
         imsi= systemService.getSubscriberId();
        if (imsi==null){
            Log.v(LOG_TAG,"识别不了插入sim卡");
            return ProxyConstant.UNKNOWN_CARRIERPERATOR;
        }
    }
    Log.v(LOG_TAG, "imsi码为 "+imsi);
    //三大运营商
    if(imsi.contains("46000") || imsi.contains("46002") || imsi.contains("46007")){
        Log.v(LOG_TAG,"**移动");
        return ProxyConstant.CHINA_MOBILE_CMCC;
    }else if(imsi.contains("46001") || imsi.contains("46006")){
        Log.v(LOG_TAG,"**联通");
        return ProxyConstant.CHINA_UNICOM_CUCC;
    }else if(imsi.contains("46003") || imsi.contains("46005") || imsi.contains("46011")){
        Log.v(LOG_TAG,"**电信");
        return ProxyConstant.CHINA_TELECOM_CTCC;
    }else{
        Log.v(LOG_TAG,"不支持的该运营商或者识别不了插入sim卡");
        return ProxyConstant.UNKNOWN_CARRIERPERATOR;
    }
}
/**
 * 判断传入的参数号码为哪家运营商
 * @param mobile
 * @return 运营商名称
 */
public static String validateMobile(String mobile){
    String returnString="";
    if(mobile==null || mobile.trim().length()!=11){
        return "-1";        //mobile参数为空或者手机号码长度不为11,错误!
    }
    if (mobile.trim().substring(0,3).equals("134")&&mobile.trim().substring(0,4).equals("1349")){
        returnString="3";//特殊卫星上网卡
    }
    if(mobile.trim().substring(0,3).equals("134") ||  mobile.trim().substring(0,3).equals("135") ||
            mobile.trim().substring(0,3).equals("136") || mobile.trim().substring(0,3).equals("137")
            || mobile.trim().substring(0,3).equals("138")  || mobile.trim().substring(0,3).equals("139") ||  mobile.trim().substring(0,3).equals("147") || mobile.trim().substring(0,3).equals("150")
            || mobile.trim().substring(0,3).equals("151") || mobile.trim().substring(0,3).equals("152")
            || mobile.trim().substring(0,3).equals("157") || mobile.trim().substring(0,3).equals("158") || mobile.trim().substring(0,3).equals("159")
            || mobile.trim().substring(0, 3).equals("178") || mobile.trim().substring(0, 3).equals("182") || mobile.trim().substring(0, 3).equals("183") || mobile.trim().substring(0, 3).equals("184")
            || mobile.trim().substring(0,3).equals("187") || mobile.trim().substring(0,3).equals("188")){
        returnString="1";   //**移动 19号段
    }
    if(mobile.trim().substring(0,3).equals("130") ||  mobile.trim().substring(0,3).equals("131")
            || mobile.trim().substring(0,3).equals("132") || mobile.trim().substring(0,3).equals("145")
            || mobile.trim().substring(0,3).equals("155") || mobile.trim().substring(0,3).equals("156")
            || mobile.trim().substring(0,3).equals("175") || mobile.trim().substring(0,3).equals("176")
            || mobile.trim().substring(0,3).equals("185")  || mobile.trim().substring(0,3).equals("186")){
        returnString="2";   //**联通 10个号段
    }
    if(mobile.trim().substring(0,3).equals("133") ||  mobile.trim().substring(0,3).equals("149")
            ||mobile.trim().substring(0,3).equals("153") || mobile.trim().substring(0, 3).equals("173")
            ||mobile.trim().substring(0,3).equals("177") || mobile.trim().substring(0, 3).equals("180")
            || mobile.trim().substring(0,3).equals("181") || mobile.trim().substring(0,3).equals("189")){
        returnString="3";   //**电信 9个号段
    }
    if(returnString.trim().equals("")){
        returnString="0";   //未知运营商
    }
    return returnString;
}

}
`

Http和https错误码的理解

http的返回码http://w3school.com.cn/tags/html_ref_httpmessages.asp
http://blog.sina.com.cn/s/blog_59b052fa0100it74.html
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
假如我们定义了537不属于标准(已知的)的http返回码,也会返回response中的537,536等等只要属于5xx

但是假如是https请求会得不到response,要try catch得到io异常里面的错误信息
E/IOException: java.io.IOException: Unexpected response code for CONNECT: 537

android studio如何分模块新建子包

我们常常新建了一个project的package name 是com.xxx.application.假如我们想分模块建立子包,在目录模式下面,例如在com.xxx.application.login登录模块后面直接new package 三个model ,view,presenter。必须切换目录模式为android才新建子包。这样看起来就不会login.view.model.presenter在一起。或者关掉 flatten package不是平铺。。

获取BaseActivity的view

View rootView = ((ViewGroup) (getWindow().getDecorView().findViewById(android.R.id.content))).getChildAt(0);或者ViewGroup content =(ViewGroup)findViewById(android.R.id.content);

gradel学习事项

Android Studio是用gradle来构建项目的,有很多环境方面的文件都不需要增加到SVN版本库。

以下为列出不需要增加到版本库的文件:

  1. .idea 文件夹,此文件夹是用来保存开发工具的设置信息。

  2. .gradle 文件夹,此文件夹是用来保存gradle的依赖信息。

  3. 所有的 build 文件夹,build文件夹是用来保存编译后的文件目录。

  4. 所有的 .iml 文件,是用来保存开发工具信息。

  5. local.properties 文件,是用来保存项目依赖信息

Android手机run apk遇到的问题

  1. 前提插入usb选择usb模式是mtp不是充电模式。windows要安装驱动对应厂商的。小米手机USB安装apk要打开开发者模式中的USB安装 还要申请小米账号是*****
    2.小米手机尽量关闭instant run 还要关闭MIUI优化

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.