1. 程式人生 > >實際專案中遇到的問題總結(1)

實際專案中遇到的問題總結(1)

(新增第三方庫建立應用的時候,有的需要新增,網上搜很多,記下來)

keytool -list -v -keystoredebug.keystore //除錯

keytool -list -v -keystore [此處為自己生成簽名的完整路徑]//正式

//程式碼獲取
public static String sHA1(Context context) {
    try {
        PackageInfo info = context.getPackageManager().getPackageInfo(
                context.getPackageName(), PackageManager.GET_SIGNATURES);
        byte[] cert = info.signatures[0].toByteArray();
        MessageDigest md = MessageDigest.getInstance("SHA1");
        byte[] publicKey = md.digest(cert);
        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < publicKey.length; i++) {
            String appendString = Integer.toHexString(0xFF & publicKey[i])
                    .toUpperCase(Locale.US);
            if (appendString.length() == 1)
                hexString.append("0");
            hexString.append(appendString);
            hexString.append(":");
        }
        String result = hexString.toString();
        Log.d("xiaojingyu", result);
        return result.substring(0, result.length() - 1);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return null;
}

2、獲取裝置編號

1.public static String getDeviceId(Context context) {  
2.        String deviceId = null;  
3.        deviceId = ((TelephonyManager) context  
4.                .getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();  
5.        if (deviceId == null && Build.VERSION.SDK_INT > 9) {  
6.            deviceId = Secure.getString(context.getContentResolver(),  
7.                    Secure.ANDROID_ID);  
8.            if (deviceId == null) {  
9.                ConnectivityManager cm = (ConnectivityManager) context  
10.                        .getSystemService(Context.CONNECTIVITY_SERVICE);  
11.                NetworkInfo networkInfo = cm.getActiveNetworkInfo();  
12.                if (networkInfo != null  
13.                        && networkInfo.isAvailable()  
14.                        && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {  
15.                    WifiManager wm = (WifiManager) context  
16.                            .getSystemService(Context.WIFI_SERVICE);  
17.                    deviceId = wm.getConnectionInfo().getMacAddress();  
18.                } else {  
19.                    deviceId = UUID.randomUUID().toString();  
20.                }  
21.            }  
22.        }  
23.  
24.        if (deviceId != null && deviceId.length() < 28) {  
25.            int len = 28 - deviceId.length();  
26.            for (int i = 0; i < len; i++) {  
27.                deviceId = "0" + deviceId;  
28.            }  
29.        }  
30.  
31.        return deviceId;  
32.    }  

3、隱藏軟鍵盤:

InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
//強制顯示或者關閉系統鍵盤
    public void KeyBoard(final EditText txtSearchKey, final boolean status) {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                InputMethodManager m = (InputMethodManager)
                        txtSearchKey.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                if (status) {
                    m.showSoftInput(txtSearchKey, InputMethodManager.SHOW_FORCED);
                } else {
                    m.hideSoftInputFromWindow(txtSearchKey.getWindowToken(), 0);
                }
            }
        }, 300);
    }

4、

Fragment巢狀Fragment  + PullToRefreshListView 最好不要用LinerLayout  用FrameLayout

佈局高度用match_parent 否則佈局顯示不正常

PullToRefreshScrollView+RecyclerView顯示不全的問題:在RecyclerView父佈局新增

android:descendantFocusability="blocksDescendants"