2017-07-31 102 views
0

试图更改Web视图上的配置文件图像。 但尝试更新的图像显示崩溃的图像。如何在android的webview中的imageview上设置图像

webView.loadUrl("javascript: (function() {document.getElementById('SelectedImage').src='"+profilePath+"';})();"); 
+0

'profilePath'应该是图像的绝对路径。 –

+0

File destination = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),“Android”); uploadImageName = destination.getName(); imagepath = destination.toString(); MyProfileActivity.profilePath = destination.getAbsolutePath();是的,个人资料路径是绝对的,但不可更改图像 –

+0

如果我使用下面的代码,它将在整个网络视图中设置。 String imagePath =“file:///”+ profilePath; webView.loadUrl(imagePath); –

回答

0

如果profilePath是一个开放的对象,那么你就需要从对象的绝对路径。
使用File f = new File(profilePath.toString());

+0

是的,配置文件路径是绝对的File destination = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),“Android”); uploadImageName = destination.getName(); imagepath = destination.toString(); MyProfileActivity.profilePath = destination.getAbsolutePath(); –

+1

Uri selectedImageUri = data.getData(); String [] projection = {MediaStore.MediaColumns.DATA}; Cursor cursor = managedQuery(selectedImageUri,projection,null,null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA); cursor.moveToFirst(); imagepath = cursor.getString(column_index); MyProfileActivity.profilePath = imagepath; –

相关问题