我有一个方法,在打开可以缩放、平移等的活动之前,从我的数据库中查询一个 Url 并作为额外发送。
topLevelMessageImage.setOnClickListener(v -> {
ParseQuery<ParseObject> imageQuery = new ParseQuery<>(ParseConstants.CLASS_YEET);
imageQuery.whereEqualTo(ParseConstants.KEY_OBJECT_ID, topLevelCommentObject.getObjectId());
imageQuery.findInBackground((user, e2) -> {
if (e2 == null) for (ParseObject userObject : user) {
if (userObject.getParseFile("image") != null) {
String imageURL = userObject.getParseFile("image").getUrl();
Log.w(getClass().toString(), imageURL);
// Asynchronously display the message image downloaded from Parse
if (imageURL != null) {
Intent intent = new Intent(getApplicationContext(), MediaPreviewActivity.class);
intent.putExtra("imageUrl", imageURL);
this.startActivity(intent);
}
}
}
});
});
当活动开始时,我得到以下异常:
10-01 20:46:08.202 16149-16460/com.yitter.android E/SubsamplingScaleImageView: Failed to initialise bitmap decoder
java.io.FileNotFoundException: No content provider: https://parsefiles.back4app.com/GDprTC66bNMp3mXWNvWJbZhWwjedoucvp6NlNKVl/03a8e1618392395811c9830333c0443f_6cf1e0ef-47af-4ddc-88cc-196debd77a9a.jpeg
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1090)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:942)
at android.content.ContentResolver.openInputStream(ContentResolver.java:662)
at com.davemorrissey.labs.subscaleview.decoder.SkiaImageRegionDecoder.init(SkiaImageRegionDecoder.java:67)
at com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView$TilesInitTask.doInBackground(SubsamplingScaleImageView.java:1415)
at com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView$TilesInitTask.doInBackground(SubsamplingScaleImageView.java:1391)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
我想我不能只为 SubsamplingScaleImageView 提供一个 Url 是吗?我想我也不能使用毕加索?我应该怎么做?
private void locateImageView() {
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
if (bundle.getString("imageUrl") != null) {
String imageUrl = bundle.getString("imageUrl");
Log.w(getClass().toString(), imageUrl);
imageView = (SubsamplingScaleImageView) findViewById(R.id.image);
URL url = new URL(imageUrl);
URI uri = url.toURI();
imageView.setImage(ImageSource.uri(String.valueOf(uri)));
/*Picasso.with(getApplicationContext())
.load(imageUrl)
.placeholder(R.color.placeholderblue)
.memoryPolicy(MemoryPolicy.NO_CACHE).into(((SubsamplingScaleImageView) findViewById(R.id.image)));*/
}
}
我试过这个,它奏效了......
try {
URL url = new URL(imageUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
imageView.setImage(ImageSource.bitmap(myBitmap);
} catch (IOException e) {
// Log exception
Log.w(getClass().toString(), e);
}