ウェブビューでプロフィール画像を変更しようとしています。 しかし、更新されたイメージにクラッシュしたイメージを表示しようとするとき。androidのwebviewの画像ビューに画像を設定する方法
webView.loadUrl("javascript: (function() {document.getElementById('SelectedImage').src='"+profilePath+"';})();");
ウェブビューでプロフィール画像を変更しようとしています。 しかし、更新されたイメージにクラッシュしたイメージを表示しようとするとき。androidのwebviewの画像ビューに画像を設定する方法
webView.loadUrl("javascript: (function() {document.getElementById('SelectedImage').src='"+profilePath+"';})();");
profilePath
がウリオブジェクトである場合は、対象物からの絶対パスを取得する必要があります。
使用File f = new File(profilePath.toString());
はい、プロファイルのパスは絶対です。File destination = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)、 "Android"); uploadImageName = destination.getName(); imagepath = destination.toString(); MyProfileActivity.profilePath = destination.getAbsolutePath(); –
Uri selectedImageUri = data.getData(); String [] projection = {MediaStore.MediaColumns.DATA}; カーソルカーソル= managedQuery(selectedImageUri、projection、null、null、 null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA); cursor.moveToFirst(); imagepath = cursor.getString(column_index); MyProfileActivity.profilePath = imagepath; –
「profilePath」はイメージへの絶対パスにする必要があります。 –
ファイルの宛先=新しいファイル(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)、 "Android"); uploadImageName = destination.getName(); imagepath = destination.toString(); MyProfileActivity.profilePath = destination.getAbsolutePath();はい。プロファイルパスは絶対パスですが、画像を変更するにはunabeです。 –
以下のコードを使用すると、ウェブビュー全体に設定されます。 String imagePath = "file:///" + profilePath; webView.loadUrl(imagePath); –