在未找到android studio照片中将图像上传到网站
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在未找到android studio照片中将图像上传到网站相关的知识,希望对你有一定的参考价值。
我是java和android工作室的新手,我只有5天左右的时间,但我遇到了障碍,我需要帮助找出如何让android studio识别照片的文件路径。
该程序应该打开并在mainActivity上显示一个imageView,当你点击它时,它将打开相机,让你拍照后将照片反馈到mainActivity并在imageView中显示全分辨率照片将照片上传到运行一些php代码的网站,收听帖子并将其写入在线存储文件夹一切正常,除非它试图上传照片时会说没有文件存在我已检查设备上的存储照片是否有可能它因为我不得不使用FileProvider使uri从文件转到内容以保存图像php脚本工作所以我需要帮助解决无法找到文件问题感谢您在高级项目代码中的帮助在设备下面:Galexy note 8
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.photo">
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="@string/file_provider_authority"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>
</application>
</manifest>
main activity.Java
package com.example.photo;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
public class MainActivity extends AppCompatActivity {
public interface ApplicationConstant {
String UPLOAD_IMAGE_URL = "http://www.example.com/upload.php";
String TAG = "DEBUG1";
}
String Barcode="9999";
int permsRequestCode;
int RC_PERMISSIONS;
final int CAMERA_REQUEST = 1;
private Uri photoUri;
ImageView mImg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mImg = (ImageView) findViewById(R.id.imageView);
mImg.setOnClickListener(new View.OnClickListener() {
//@Override
public void onClick(View v) {
Log.i(ApplicationConstant.TAG," " + "click");
showCamera();
}
});
}
private class uploadFileToServerTask extends AsyncTask<String, String, Object> {
@Override
protected String doInBackground(String... args) {
try {
String lineEnd = "
";
String twoHyphens = "--";
String boundary = "*****";
int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
@SuppressWarnings("PointlessArithmeticExpression")
int maxBufferSize = 1 * 1024 * 1024;
java.net.URL url = new URL((ApplicationConstant.UPLOAD_IMAGE_URL));
Log.i(ApplicationConstant.TAG, "url " + url);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// Allow Inputs & Outputs.
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
// Set HTTP method to POST.
connection.setRequestMethod("POST");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
FileInputStream fileInputStream;
DataOutputStream outputStream;
{
outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.writeBytes(twoHyphens + boundary + lineEnd);
String filename = args[0];
outputStream.writeBytes("Content-Disposition: form-data; name="file";filename="" + filename + """ + lineEnd);
outputStream.writeBytes(lineEnd);
Log.i(ApplicationConstant.TAG, "filename: " + filename);
fileInputStream = new FileInputStream(filename);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];
// Read file
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0) {
outputStream.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
outputStream.writeBytes(lineEnd);
outputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
}
int serverResponseCode = connection.getResponseCode();
String serverResponseMessage = connection.getResponseMessage();
Log.i(ApplicationConstant.TAG, "serverResponseCode: " + serverResponseCode);
Log.i(ApplicationConstant.TAG, "serverResponseMessage: " + serverResponseMessage);
fileInputStream.close();
outputStream.flush();
outputStream.close();
if (serverResponseCode == 200) {
return "true";
}
} catch (Exception e) {
e.printStackTrace();
}
return "false";
}
@Override
protected void onPostExecute(Object result) {
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST) {
if (resultCode == RESULT_OK) {
if (photoUri != null) {
mImg.setImageURI(photoUri);
Log.i(ApplicationConstant.TAG,"photo_Uri: " + photoUri);
new uploadFileToServerTask().execute(photoUri.toString());
}
}
}
}
private void showCamera() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (intent.resolveActivity(this.getPackageManager()) != null) {
File file = null;
try {
file = createImageFile();
} catch (IOException e) {
e.printStackTrace();
}
photoUri = null;
if (file != null) {
photoUri = FileProvider.getUriForFile(MainActivity.this,
getString(R.string.file_provider_authority),
file);
//photoUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
startActivityForResult(intent, CAMERA_REQUEST);
}
}
}
private File createImageFile() throws IOException {
// Create an image file name
File storageDir = new File(this.getExternalFilesDir(Environment.DIRECTORY_PICTURES),Barcode + ".jpg");
// File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
return storageDir;
}
}
值/ strings.xml中
<resources>
<string name="app_name">Photo</string>
<string name="file_provider_authority" translatable="false">com.example.photo.fileprovider</string>
</resources>
嗯/ buddy_path.kn
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="external_files" path="." />
</paths>
upload.php的
<?php
$target_dir = "";
$target_file = $target_dir . basename($_FILES["file"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["file"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["file"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["file"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
logcat的
03-20 02:33:39.234 32312-32312/? E/Zygote: v2
03-20 02:33:39.235 32312-32312/? I/libpersona: KNOX_SDCARD checking this for 10276
03-20 02:33:39.235 32312-32312/? I/libpersona: KNOX_SDCARD not a persona
03-20 02:33:39.235 32312-32312/? E/Zygote: accessInfo : 0
03-20 02:33:39.236 32312-32312/? W/SELinux: SELinux selinux_android_compute_policy_index : Policy Index[2], Con:u:r:zygote:s0 RAM:SEPF_SECMOBILE_7.1.1_0004, [-1 -1 -1 -1 0 1]
03-20 02:33:39.236 32312-32312/? I/SELinux: SELinux: seapp_context_lookup: seinfo=untrusted, level=s0:c512,c768, pkgname=com.example.photo
03-20 02:33:39.241 32312-32312/? I/art: Late-enabling -Xcheck:jni
03-20 02:33:39.452 32312-32312/com.example.photo I/InstantRun: starting instant run server: is main process
03-20 02:33:39.510 32312-32312/com.example.photo V/ActivityThread: performLaunchActivity: mActivityCurrentConfig={0 1.0 themeSeq = 0 showBtnBg = 0 310mcc260mnc [en_US,ja_JP] ldltr sw411dp w411dp h773dp 560dpi nrml long port ?dc finger -keyb/v/h -nav/h mkbd/h desktop/d s.112}
03-20 02:33:39.522 32312-32312/com.example.photo W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
03-20 02:33:39.611 32312-32312/com.example.photo D/TextView: setTypeface with style : 0
03-20 02:33:39.612 32312-32312/com.example.photo D/TextView: setTypeface with style : 0
03-20 02:33:39.649 32312-32312/com.example.photo D/ViewRootImpl@4c4ddef[MainActivity]: ThreadedRenderer.create() translucent=false
03-20 02:33:39.653 32312-32312/com.example.photo D/InputTransport: Input channel constructed: fd=87
03-20 02:33:39.654 32312-32312/com.example.photo D/ViewRootImpl@4c4ddef[MainActivity]: setView = DecorView@94b80fc[MainActivity] touchMode=true
03-20 02:33:39.663 32312-32312/com.example.photo D/ViewRootImpl@4c4ddef[MainActivity]: dispatchAttachedToWindow
03-20 02:33:39.688 32312-32312/com.example.photo V/Surface: sf_framedrop debug : 0x4f4c, game : false, logging : 0
03-20 02:33:39.688 32312-32312/com.example.photo D/ViewRootImpl@4c4ddef[MainActivity]: Relayout returned: oldFrame=[0,0][0,0] newFrame=[0,0][1440,2960] result=0x27 surface={isValid=true 548279813120} surfaceGenerationChanged=true
03-20 02:33:39.688 32312-32312/com.example.photo D/ViewRootImpl@4c4ddef[MainActivity]: mHardwareRenderer.initialize() mSurface={isValid=true 548279813120} hwInitialized=true
03-20 02:33:39.691 32312-32379/com.example.photo D/libEGL: loaded /vendor/lib64/egl/libEGL_adreno.so
03-20 02:33:39.703 32312-32379/com.example.photo D/libEGL: loaded /vendor/lib64/egl/libGLESv1_CM_adreno.so
03-20 02:33:39.709 32312-32312/com.example.photo W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
03-20 02:33:39.711 32312-32379/com.example.photo D/libEGL: loaded /vendor/lib64/egl/libGLESv2_adreno.so
03-20 02:33:39.715 32312-32312/com.example.photo D/ViewRootImpl@4c4ddef[MainActivity]: MSG_RESIZED_REPORT: frame=Rect(0, 0 - 1440, 2960) ci=Rect(0, 84 - 0, 168) vi=Rect(0, 84 - 0, 168) or=1
03-20 02:33:39.715 32312-32312/com.example.photo D/ViewRootImpl@4c4ddef[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1
03-20 02:33:39.715 32312-32312/com.example.photo D/ViewRootImpl@4c4ddef[MainActivity]: mHardwareRenderer.initializeIfNeeded()#2 mSurface={isValid=true 548279813120}
03-20 02:33:39.716 32312-32312/com.example.photo V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@72b6a0b nm : com.example.photo ic=null
03-20 02:33:39.716 32312-32312/com.example.photo I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
03-20 02:33:39.721 32312-32324/com.example.photo D/InputTransport: Input channel constructed: fd=95
03-20 02:33:39.725 32312-32379/com.example.photo I/Adreno: QUALCOMM build : 33f9106, Ia8660bee96
Build Date : 08/09/17
OpenGL ES Shader Compiler Version: XE031.14.00.01
Local Branch :
Remote Branch : refs/tags/AU_LINUX_ANDROID_LA.UM.5.7.C2.07.01.01.292.070
Remote Branch : NONE
Reconstruct Branch : NOTHING
03-20 02:33:39.726 32312-32379/com.example.photo I/Adreno: PFP: 0x005ff104, ME: 0x005ff063
03-20 02:33:39.727 32312-32379/com.example.photo I/OpenGLRenderer: Initialized EGL, version 1.4
03-20 02:33:39.727 32312-32379/com.example.photo D/OpenGLRenderer: Swap behavior 1
03-20 02:33:39.745 32312-32312/com.example.photo V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@b83b500 nm : com.example.photo ic=null
03-20 02:33:42.813 32312-32312/com.example.photo D/ViewRootImpl@4c4ddef[MainActivity]: ViewPostImeInputStage processPointer 0
03-20 02:33:42.888 32312-32312/com.example.photo D/ViewRootImpl@4c4ddef[MainActivity]: ViewPostImeInputStage processPointer 1
03-20 02:33:42.891 32312-32312/com.example.photo I/DEBUG1: click
03-20 02:33:42.915 32312-32312/com.example.photo D/ViewRootImpl@4c4ddef[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 0
03-20 02:33:43.165 32312-32312/com.example.photo D/ViewRootImpl@4c4ddef[MainActivity]: mHardwareRenderer.destroy()#1
03-20 02:33:43.173 32312-32312/com.example.photo D/ViewRootImpl@4c4ddef[MainActivity]: Relayout returned: oldFrame=[0,0][1440,2960] newFrame=[0,0][1440,2960] result=0x5 surface={isValid=false 0} surfaceGenerationChanged=true
03-20 02:33:43.173 32312-32312/com.example.photo D/InputTransport: Input channel destroyed: fd=95
03-20 02:33:49.502 32312-32312/com.example.photo D/ViewRootImpl@4c4ddef[MainActivity]: mHardwareRenderer.destroy()#1
03-20 02:33:49.508 32312-32312/com.example.photo D/ViewRootImpl@4c4ddef[MainActivity]: Relayout returned: oldFrame=[0,0][1440,2960] newFrame=[0,0][1440,2960] result=0x1 surface={isValid=false 0} surfaceGenerationChanged=false
03-20 02:33:49.531 32312-32312/com.example.photo V/Surface: sf_framedrop debug : 0x4f4c, game : false, logging : 0
03-20 02:33:49.532 32312-32312/com.example.photo D/ViewRootImpl@4c4ddef[MainActivity]: Relayout returned: oldFrame=[0,0][1440,2960] newFrame=[0,0][1440,2960] result=0x7 surface={isValid=true 548279813120} surfaceGenerationChanged=true
03-20 02:33:49.532 32312-32312/com.example.photo D/ViewRootImpl@4c4ddef[MainActivity]: mHardwareRenderer.initialize() mSurface={isValid=true 548279813120} hwInitialized=true
03-20 02:33:49.545 32312-32312/com.example.photo D/ViewRootImpl@4c4ddef[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1
03-20 02:33:49.545 32312-32312/com.example.photo D/ViewRootImpl@4c4ddef[MainActivity]: mHardwareRenderer.initializeIfNeeded()#2 mSurface={isValid=true 548279813120}
03-20 02:33:49.545 32312-32312/com.example.photo V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@4c32418 nm : com.example.photo ic=null
03-20 02:33:49.545 32312-32312/com.example.photo I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
03-20 02:33:49.547 32312-32312/com.example.photo D/InputTransport: Input channel constructed: fd=91
03-20 02:33:49.797 32312-32312/com.example.photo I/DEBUG1: photo_Uri: content://com.example.photo.fileprovider/external_files/Android/data/com.example.photo/files/Pictures/9999.jpg
03-20 02:33:49.799 32312-2026/com.example.photo I/DEBUG1: url http://www.example.com/upload.php
03-20 02:33:49.802 32312-2026/com.example.photo D/NetworkSecurityConfig: No Network Security Config specified, using platform default
03-20 02:33:49.803 32312-2026/com.example.photo I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
03-20 02:33:49.803 32312-2026/com.example.photo I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
03-20 02:33:49.903 32312-2026/com.example.photo D/TcpOptimizer: TcpOptimizer-ON
03-20 02:33:49.983 32312-2026/com.example.photo I/DEBUG1: filename: content://com.example.photo.fileprovider/external_files/Android/data/com.example.photo/files/Pictures/9999.jpg
03-20 02:33:49.983 32312-2026/com.example.photo W/System.err: java.io.FileNotFoundException: content:/com.example.photo.fileprovider/external_files/Android/data/com.example.photo/files/Pictures/9999.jpg (No such file or directory)
03-20 02:33:49.983 32312-2026/com.example.photo W/System.err: at java.io.FileInputStream.open(Native Method)
03-20 02:33:49.983 32312-2026/com.example.photo W/System.err: at java.io.FileInputStream.<init>(FileInputStream.java:146)
03-20 02:33:49.983 32312-2026/com.example.photo W/System.err: at java.io.FileInputStream.<init>(FileInputStream.java:99)
03-20 02:33:49.983 32312-2026/com.example.photo W/System.err: at com.example.photo.MainActivity$uploadFileToServerTask.doInBackground(MainActivity.java:94)
03-20 02:33:49.983 32312-2026/com.example.photo W/System.err: at com.example.photo.MainActivity$uploadFileToServerTask.doInBackground(MainActivity.java:55)
03-20 02:33:49.983 32312-2026/com.example.photo W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:305)
03-20 02:33:49.983 32312-2026/com.example.photo W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-20 02:33:49.983 32312-2026/com.example.photo W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
03-20 02:33:49.983 32312-2026/com.example.photo W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
03-20 02:33:49.983 32312-2026/com.example.photo W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
03-20 02:33:49.983 32312-2026/com.example.photo W/System.err: at java.lang.Thread.run(Thread.java:762)
03-20 02:33:52.113 32312-32312/com.example.photo D/ViewRootImpl@4c4ddef[MainActivity]: mHardwareRenderer.destroy()#4
03-20 02:33:52.113 32312-32312/com.example.photo D/ViewRootImpl@4c4ddef[MainActivity]: dispatchDetachedFromWindow
03-20 02:33:52.117 32312-32312/com.example.photo D/InputTransport: Input channel destroyed: fd=87
03-20 02:33:52.117 32312-32312/com.example.photo W/SemDesktopModeManager: unregisterListener: Listener is null
03-20 02:33:52.120 32312-32312/com.example.photo V/ActivityThread: performLaunchActivity: mActivityCurrentConfig={0 1.0 themeSeq = 0 showBtnBg = 0 310mcc260mnc [en_US,ja_JP] ldltr sw411dp w797dp h387dp 560dpi nrml long land ?dc finger -keyb/v/h -nav/h mkbd/h desktop/d s.113}
03-20 02:33:52.134 32312-32312/com.example.photo D/TextView: setTypeface with style : 0
03-20 02:33:52.134 32312-32312/com.example.photo D/TextView: setTypeface with style : 0
03-20 02:33:52.141 32312-32312/com.example.photo D/ViewRootImpl@b05cbf4[MainActivity]: ThreadedRenderer.create() translucent=false
03-20 02:33:52.179 32312-32312/com.example.photo D/InputTransport: Input channel constructed: fd=93
03-20 02:33:52.179 32312-32312/com.example.photo D/ViewRootImpl@b05cbf4[MainActivity]: setView = DecorView@8545f1d[MainActivity] touchMode=true
03-20 02:33:52.183 32312-32312/com.example.photo E/ViewRootImpl: sendUserActionEvent() returned.
03-20 02:33:52.183 32312-32312/com.example.photo D/ViewRootImpl@b05cbf4[MainActivity]: dispatchAttachedToWindow
03-20 02:33:52.210 32312-32312/com.example.photo V/Surface: sf_framedrop debug : 0x4f4c, game : false, logging : 0
03-20 02:33:52.211 32312-32312/com.example.photo D/ViewRootImpl@b05cbf4[MainActivity]: Relayout returned: oldFrame=[0,0][0,0] newFrame=[0,0][2960,1440] result=0x27 surface={isValid=true 548279813120} surfaceGenerationChanged=true
03-20 02:33:52.211 32312-32312/com.example.photo D/ViewRootImpl@b05cbf4[MainActivity]: mHardwareRenderer.initialize() mSurface={isValid=true 548279813120} hwInitialized=true
03-20 02:33:52.220 32312-32312/com.example.photo D/ViewRootImpl@b05cbf4[MainActivity]: MSG_RESIZED_REPORT: frame=Rect(0, 0 - 2960, 1440) ci=Rect(168, 84 - 0, 0) vi=Rect(168, 84 - 0, 0) or=2
03-20 02:33:52.231 32312-32312/com.example.photo D/ViewRootImpl@b05cbf4[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1
03-20 02:33:52.231 32312-32312/com.example.photo D/ViewRootImpl@b05cbf4[MainActivity]: mHardwareRenderer.initializeIfNeeded()#2 mSurface={isValid=true 548279813120}
03-20 02:33:52.232 32312-32312/com.example.photo V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@e558592 nm : com.example.photo ic=null
03-20 02:33:52.232 32312-32312/com.example.photo I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
03-20 02:33:52.236 32312-32312/com.example.photo D/InputTransport: Input channel constructed: fd=95
03-20 02:33:52.236 32312-32312/com.example.photo D/InputTransport: Input channel destroyed: fd=91
String filename ="content://com.example.photo.fileprovider/external_files/Android/data/com.example.photo/files/Pictures/9999.jpg";
FileInputStream fis= new FileInputStream(filename);
由于没有文件方案,因此无法使用文件输入流。你有一个内容方案。所以改为:
InputStream is = getContentResolver().openInputStream(Uri.parse(filename));
并像以前一样使用该流。
您可以直接使用文件路径,而不是您自己的文件提供程序的此内容方案。因为是你确定了要采取的路径或图片。你在这里抛弃了很多不相关的代码,并省略了使用意图的设置。
在你的onActivityResult
中,你试图获取你提供的用于捕获的文件的URI。所以它说找不到文件。而是尝试从方法中获取Intent的url
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST) {
if (resultCode == RESULT_OK) {
if (data != null) {
photoUri= data.getData();
mImg.setImageURI(photoUri);
Log.i(ApplicationConstant.TAG,"photo_Uri: " + photoUri);
new uploadFileToServerTask().execute(photoUri.toString());
}
}
}
}
以上是关于在未找到android studio照片中将图像上传到网站的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Android Studio 中将文本设置为对应的图像
如何在 Android Studio 中将 ListView 更改为 RecyclerView?
如何使用android studio在flutter上加载图像
在android studio中将firebase添加到flutter时出错:插件项目:firebase_core_web未找到。请更新 settings.gradle [重复]