Android適配之版本適配

2021-09-22 01:50:42 字數 1562 閱讀 5552

windowmanager.layoutparams lp = getwindow().getattributes();

lp.layoutindisplaycutoutmode = windowmanager.layoutparams.layout_in_display_cutout_mode_default;

getwindow().setattributes(lp);

接下來看下如何使用:

1、定義 fileprovider

我們先在 androidmanifest 中進行註冊

2、指定可分享的檔案路徑

fileprovider 只能為指定的目錄中的檔案生成內容 uri。要指定目錄,就必須使用 元素的子元素在 xml 中指定其儲存區域和路徑。

我們先建立乙個名為 res/xml/file_paths_public.xml 的新檔案

在 paths 節點內部支援以下幾個子節點,分別為:

**中的常見用法:

intent intent = new intent("android.intent.action.view");

intent.addcategory("android.intent.category.default");

intent.addflags(intent.flag_grant_read_uri_permission); // fileprovider方式必須加這個臨時許可權

uri uri = fileprovider.geturiforfile(mcontext, "com.hccf.fileprovider", file);

mcontext.startactivity(intent);

還有一種用法是: 使用context 的 granturipermission() 方法和revokeuripermission(); 這種比較少用。

至此,fileprovider的介紹就差不多結束了。

還有一些其他的比較少遇到的,就不做贅述了,參考文章:

// 獲取許可權

rxpermissions rxpermissions = new rxpermissions(getactivity());

rxpermissions.request(manifest.permission.read_external_storage,

manifest.permission.write_external_storage)

.subscribe(new observer()

@override

public void onnext(boolean aboolean)

}@override

public void onerror(throwable e)

@override

public void oncomplete()

});

Android版本適配

判斷相容模式介面 返回值 true 應用以相容模式執行 false 應用以分割槽儲存特性執行 environment.i ternalstoragelegacy 複製 file path路徑訪問受影響介面 開啟分割槽儲存新特性,andrioid 10不能夠通過file path路徑直接訪問共享目錄下...

Android之螢幕適配

二 螢幕適配 總結 注意 尺寸和解析度無關 四個方面 禁用絕對布局 由於絕對布局 absolutelayout 適配性極差,所以極少使用。少用px 需求 按鈕佔螢幕的一半 效果 若以px為單位,在左側一半為120px,在右側,120px只佔據1 4的大小 搭配layout weight 使用 wra...

ios版本適配,機型適配,橫豎屏適配

1,版本適配 ios系統的判定,這個可以通過 uidevice currentdevice systemversion floatvalue 來獲得當前的系統版本。2,機型適配 螢幕尺寸 define device is iphone4s uiscreenmainscreen bounds size...