gpt4 book ai didi

java - glide 不从 SD 卡加载图像

转载 作者:行者123 更新时间:2023-12-01 06:03:54 25 4
gpt4 key购买 nike

我想把一张图像放在我的SD卡中,但它没有显示,我认为滑翔库或权限有问题,我在那里堆了两天,请帮助我。

public class MainActivity extends AppCompatActivity {

public final static String PATH_SD_CARD = "/Images/Mj.jpg";
private static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1;



@TargetApi(Build.VERSION_CODES.M)
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
!= getPackageManager().PERMISSION_GRANTED) {

// Should we show an explanation?
if (shouldShowRequestPermissionRationale(
Manifest.permission.READ_EXTERNAL_STORAGE)) {
// Explain to the user why we need to read the contacts
}

requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);

// MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE is an
// app-defined int constant that should be quite unique

return;
}

ImageView img = findViewById(R.id.imageView);

Glide.with(this)
.load(Environment.getExternalStorageDirectory().getAbsolutePath()+PATH_SD_CARD)
.into(img);
}
}

最佳答案

您是否在 Android list 文件中添加了权限,如下面的代码..

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

关于java - glide 不从 SD 卡加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50022589/

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