我有这些作为我的权限:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Run Code Online (Sandbox Code Playgroud)
我在openInputStream行上收到了权限拒绝错误:
if(bgUri != null && !bgUri.isEmpty()) {
try {
InputStream inputStream = context.getContentResolver().openInputStream(Uri.parse(bgUri)); // <-- error
return Drawable.createFromStream(inputStream, bgUri);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
我首先加载我的图像
@Override
public void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
if (requestCode == SELECT_PHOTO && resultCode == Activity.RESULT_OK) {
try {
final Uri imageUri = imageReturnedIntent.getData();
final int takeFlags = imageReturnedIntent.getFlags()
& (Intent.FLAG_GRANT_READ_URI_PERMISSION …Run Code Online (Sandbox Code Playgroud) 我使用下面的代码从DCIM中的Camera文件夹中获取所有图像并显示在我的应用程序中.但我想在我的应用程序中显示设备上的所有图像,无论它们存储在设备上的哪个位置.我怎样才能做到这一点?
String ExternalStorageDirectoryPath = Environment
.getExternalStorageDirectory()
.getAbsolutePath();
String targetPath = ExternalStorageDirectoryPath + "/DCIM/Camera";
images=new ArrayList<String>();
File targetDirector = new File(targetPath);
File[] files = targetDirector.listFiles();
for (File file : files) {
images.add(file.getAbsolutePath());
}
gallerylist=new CameraGalleryAdapter(getActivity().getApplicationContext(),R.layout.giphy_grid,images);
gridview.setAdapter(gallerylist);
Run Code Online (Sandbox Code Playgroud) android android-gallery android-camera android-external-storage
我从我的应用程序调用默认图库应用程序来选择任何照片.下面是我从库中获取所选图像路径的代码.它对所有照片都很好,除了很少.当我从图库中选择任何PICASA上传的照片时,应用就会强行关闭.请帮我.
在onActivityResult()....
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String selectedPhotoPath = cursor.getString(columnIndex).trim(); <<--- NullPointerException here
cursor.close();
bitmap = BitmapFactory.decodeFile(selectedPhotoPath);
......
Run Code Online (Sandbox Code Playgroud) 我使用以下代码从库中选择一张图片.
Intent intent_gallery = new Intent();
intent_gallery.setType("image/*");
intent_gallery.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent_gallery, 1);
Run Code Online (Sandbox Code Playgroud)
但是,我不需要它来查看选择图片的其他应用程序.我希望它直接打开默认图库,而不是向我展示选择图片的其他应用程序.
我希望用户能够从他们的媒体库中选择一张照片,但不希望他们能够选择一个视频.我无法限制他们只选择照片.当我使用打开图库应用程序时
new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
Run Code Online (Sandbox Code Playgroud)
然后他们可以选择照片和视频.有没有办法限制他们只选择照片?
这是我从Gallery获取图像的代码.它给出了一个空指针异常并崩溃.我正在测试设备本身的代码,一旦我在库中选择了图像,它就会崩溃.我出错的任何想法?
AlertDialog.Builder builder = new AlertDialog.Builder(CreatePod.this);
builder.setMessage("Select") .setCancelable(false).setPositiveButton("Gallery", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent gallIntent=new Intent(Intent.ACTION_GET_CONTENT);
gallIntent.setType("image/*");
startActivityForResult(gallIntent, 10);
}
})
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 10:
if (resultCode == Activity.RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap b = (Bitmap) extras.get("data");
imgView.setImageBitmap(b);
String timestamp = Long.toString(System.currentTimeMillis());
MediaStore.Images.Media.insertImage(getContentResolver(), b, timestamp, timestamp);
HttpResponse httpResponse;
ByteArrayOutputStream bao = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 100, bao);
byte [] ba = bao.toByteArray(); …Run Code Online (Sandbox Code Playgroud) 我有一个问题:我有一个功能,可以从画廊中获取图像;但是当我选择图像时,我没有得到它.
public void funzione(View v){
int SELECT_IMAGE=1;
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),SELECT_IMAGE);
Run Code Online (Sandbox Code Playgroud)
我必须通过电子邮件发送此图片,但我现在不知道如何实现这个:
Intent i = new Intent();
i.setType("application/octet-stream");
i.setAction(Intent.ACTION_SEND);
i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ "prova@libero.it" });
i.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test subj");
i.putExtra(android.content.Intent.EXTRA_TEXT, "corpo mail test");
startActivity(Intent.createChooser(i, "Send email"));
}
Run Code Online (Sandbox Code Playgroud) 我有一个问题,我想在aNDROID中从图库中选择图像和视频我使用了以下代码但不成功.
setType("*/*);setType("video/*");setType("image/*");setType("image/* , video/*");setType("image/* video/*"); Intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 1);Intent i= new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
i.setType("*/*");
startActivityForResult(i, RESULT_LOAD_IMAGE);android ×10
cursor ×1
gallery ×1
java ×1
media ×1
mediastore ×1
permissions ×1
photo ×1
uri ×1
video ×1