gpt4 book ai didi

android - 棉花糖中存储资源管理器的 Intent ?

转载 作者:行者123 更新时间:2023-11-30 01:35:14 24 4
gpt4 key购买 nike

在 Android 6.0 Marshmallow 中,在设置 → 存储和 USB → 探索下有一个存储资源管理器。

是否可以使用 Intent 从应用内启动此 Activity

我发现我可以启动 SettingsACTION_INTERNAL_STORAGE_SETTINGS 的 Activity 或 ACTION_MEMORY_CARD_SETTINGS但是我还没有找到启动“探索” Activity 的方法。我想以预定义路径在探索模式下启动它,可能是通过额外的 Intent 或其他方式,例如 intent.putExtra("PATH", getFilesDir() + "/stuff");

Intent intent = new Intent(Settings.ACTION_INTERNAL_STORAGE_SETTINGS);
startActivity(intent);

是否可以启动以下任何一项?

  • com.android.externalstorage
  • com.android.documentsui
  • com.android.documentsui/.DocumentsActivity

是否可以使用预定义的路径启动 Activity ?

最佳答案

in Android 6.0, you can use Intent same as previous version of android OS which open default storage explorer with recent files you can also change its to show external storage using option menu there is also navigation drawer for more options like photos,image,videos,Audio filters etc. below is code

public void openFileEx() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, 15);
}

但是你必须在 android 6.0 Marshmallow 中请求 android.permission.READ_EXTERNAL_STORAGE 的许可才能从外部存储读取文件,如下所示/p>

if (Build.VERSION.SDK_INT < 23) {
openFileEx();
} else {
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
requestContactsPermissions();
} else {
openFileEx();
}
}

public void requestContactsPermissions() {
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.READ_EXTERNAL_STORAGE)) {
Log.i("PERMISIOM",
"Displaying contacts permission rationale to provide additional context.");
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
11);
} else {
// Contact permissions have not been granted yet. Request them directly.
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 11);
}
}

您还可以使用上面的代码检查更多权限,这里是 android-RuntimePermissions 的示例在 Github 上。

关于android - 棉花糖中存储资源管理器的 Intent ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35190080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com