[英]How can I get a Picasa image folder on my Marshmallow device?
My application allows users to select an image to upload. 我的应用程序允许用户选择要上传的图像。 When users select an image from a picasa album my data intent comes back with
dat=content://com.sec.android.gallery3d.provider/picasa/item/...
. 当用户从Picasa相册中选择图像时,我的数据意图是
dat=content://com.sec.android.gallery3d.provider/picasa/item/...
Apparently when selecting an image from a picasa folder, I must handle getting the image differently as noted in this answer . 显然,当从picasa文件夹中选择图像时,我必须按照此答案中所述处理不同的图像。
But before I implement a fix, I want to be able to reproduce the crash so I can verify my fix actually works. 但是在实施修补程序之前,我希望能够重现崩溃,以便可以验证我的修补程序确实有效。 So how can I get a Picasa folder on my new (marshmallow) Android test device since Picasa has been killed by Google?
那么,既然Picasa被Google杀死了,该如何在新的(棉花糖)Android测试设备上获取Picasa文件夹?
The most guaranteed way of getting a file send inside an intent, is to open a stream to it and copy it over to a private folder on your app. 将文件发送到意图中,最有保证的方法是打开一个流,然后将其复制到应用程序的专用文件夹中。
This way works for local file, content
uri, picasa, all of it. 这种方式适用于本地文件,
content
uri,picasa及其所有。
Something like that: 像这样:
private File getSharedFile() {
Uri uri = intent.getExtras().getParcelable(Intent.EXTRA_STREAM);
// or using the new compat lib
Uri uri = ShareCompat.IntentReader(this).getStream();
InputStream is = null;
OutputStream os = null;
try {
File f = ... define here a temp file // maybe getCacheDir();
is = getContentResolver().openInputStream(uri);
os = new BufferedOutputStream(new FileOutputStream(f));
int read;
byte[] bytes = new byte[2048];
while ((read = is.read(bytes)) != -1) {
os.write(bytes, 0, read);
}
return f;
} catch (Exception e) {
... handle exceptions, buffer underflow, NPE, etc
} finally {
try { is.close(); } catch (Exception e) { /* u never know */ }
try {
os.flush();
os.close();
} catch (Exception e) { /* seriously can happen */ }
}
return null;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.