最近APP升級(jí)N后發(fā)現(xiàn)應(yīng)用中所有的打開(kāi)文件的操作都失效了,檢查發(fā)現(xiàn)代碼中的操作基本入下:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.setDataAndType(contentUri, mime);
startActivity(intent);
檢查了之后,在N后用Provider進(jìn)行文件操作加上了钦听,Debug發(fā)現(xiàn)路徑也沒(méi)錯(cuò)倍奢。后來(lái)發(fā)現(xiàn)要把 intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 這行換成 intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);