如何在 android 中创建一个浏览按钮以从 SdCard 加载任何图像? 仅允许打开经过验证的扩展文件。
最佳答案
像下面这样使用它。将以下代码放入您的按钮点击事件中。
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE);
所以你的完整代码看起来像这样
((Button) findViewById(R.id.Button1))
.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), SELECT_PICTURE);
}
});
关于android - 如何在 android 中创建一个浏览按钮以从 sdcard 加载任何图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22066539/