Android相關知識記錄

以下內容均爲平時項目中用到的知識點,純屬個人記錄,不喜勿噴~

1、通信框架:Retrofit2 + Okhttp3 + Rxjava2

2、View的綁定工具:ButterKnife(插件Zelezny)

3、權限處理:EasyPermissions

4、側滑:SwipeLayout

5、帶手柄抽屜:SlidingDrawer,不帶手柄:Drawerlayout + NavigationView

6、指示器(導航器):MagicIndicator

7、工具類:DevUtils

8、接口管理工具:eolinker

9、Android平臺UI測試:Robotium

10、應用添加角標:shortcutBadger

11、按鈕添加角標:BadgeView

12、項目架構:MVP

13、圖片處理:Glide

14、Application類的應用場景(按優先級排序):

    a、初始化應用程序級別的資源,如全局對象,環境配置變量等

    b、數據共享,數據緩存,如設置全局共享變量、方法等

    c、獲取應用程序當前的內存使用情況,及時釋放資源,從而避免被系統殺死

    d、監聽應用程序配置信息的改變,如屏幕旋轉等

    e、監聽應用程序內所有Activity的生命週期

15、Android N讀寫文件路徑,以安裝apk爲例:

    a、核心代碼

    /**
     * @param context
     * @param apkPath 要安裝的APK
     */
    public static void installApk(Context context, String apkPath){
        //ANDROID8.0 將ACTION_VIEW改爲ACTION_INSTALL_PACKAGE
        Intent intent = new Intent(Intent.ACTION_VIEW);
        //版本在7.0以上是不能直接通過uri訪問的
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {
            File file = (new File(apkPath));
            // 由於沒有在Activity環境下啓動Activity,設置下面的標籤
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            //參數1 上下文, 參數2 Provider主機地址 和配置文件中保持一致   參數3  共享的文件
            Uri apkUri = FileProvider.getUriForFile(context, context.getPackageName() + ".provider", file);
            //添加這一句表示對目標應用臨時授權該Uri所代表的文件
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
        } else {
            intent.setDataAndType(Uri.fromFile(new File(apkPath)), "application/vnd.android.package-archive");
        }
        context.startActivity(intent);
    }

    b、新建res/xml/filepaths.xml文件,具體內容如下:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path
        name="external_path_apk"
        path="panda/download" />
</paths>

    c、在AndroidManifest.xml中添加

       <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="包名.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths" />
        </provider>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章