Android开发常用方法

Dialog打开和关闭键盘异常问题
/**打开键盘**/
public void openInputFromWindow() {
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
        InputMethodManager imm = (InputMethodManager)    mContext.getSystemService(mContext.INPUT_METHOD_SERVICE);
        imm.showSoftInput(rootView, 0); // 这里需要传入activity的根View
        imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    }

/**关闭键盘**/
public void cleanInputFromWindow() {
        if (editText != null) {
            InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
        }
    }
键盘事件执行2次
@Override
public boolean dispatchKeyEvent(KeyEvent event) { 
  if(event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() != KeyEvent.ACTION_DOWN) {//不响应按键抬起时的动作
     
    } 
    return super.dispatchKeyEvent(event); 
  }

因为键盘事件会执行ACTION_DOWN和ACTION_UP事件

Cipher加解密
private static byte[] encrypt(byte[] key, byte[] input) throws NoSuchPaddingException,NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
        SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
        byte[] encrypted = cipher.doFinal(input);
        return encrypted;
    }

private static byte[] decrypt(byte[] key, byte[] encrypted) throws NoSuchPaddingException,NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
        SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.DECRYPT_MODE, skeySpec);
        byte[] decrypted = cipher.doFinal(encrypted);
        return decrypted;
    }
判断Root权限
private static boolean isRoot() {
        String binaryName = "su";
        boolean found = false;
        if (!found) {
            String[] places = {"/sbin/", "/system/bin/", "/system/xbin/", "/data/local/xbin/","/data/local/bin/", "/system/sd/xbin/", "/system/bin/failsafe/", "/data/local/"};
            for (String where : places) {
                if (new File(where + binaryName).exists()) {
                    found = true;
                    break;
                }
            }
        }
        return found;
    }
TextView默认文字开发时显示运行时隐藏
xmlns:tools="http://schemas.android.com/tools"  
tools:text="默认文字" 
Hander移除Message或者Runnable

原文链接

handler.removeCallbacksAndMessages(null);
Android自带工具android.webkit.URLUtil

原文链接

boolean isUrl= URLUtil.isValidUrl(url);
防止截屏(阅后即焚)

https://juejin.im/post/594fe55d5188250d957612da

规律性动态获取资源文件

http://blog.csdn.net/jenly121/article/details/51564229

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值