在线服务器android上保存照片

时间:2015-06-08 15:30:15

标签: android android-camera

我有一个问题,我不知道如何解决它。 我创建了一个应用程序(android),使用相机拍照并将图片保存在内部存储中。是否可以在在线服务器上保存照片?

public class CameraActivity extends Activity {
int TAKE_PHOTO_CODE = 0;
public static int count=0;

/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera);

    //creating the folder to store the picture
    final String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/Error_pic/"; //path of the folder
    File newdir = new File(dir);
    newdir.mkdirs();

    Button capture = (Button) findViewById(R.id.btnCapture);
    capture.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            //counter will be incremented each time,and the picture taken by camera will be stored as 1.jpg,2.jpg and likewise.
            count++;
            String file = dir+count+".jpg";
            File newfile = new File(file);
            try {
                newfile.createNewFile();
            } catch (IOException e) {}

            Uri outputFileUri = Uri.fromFile(newfile);

            Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);

            startActivityForResult(cameraIntent, TAKE_PHOTO_CODE);
        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == TAKE_PHOTO_CODE && resultCode == RESULT_OK) {
        Log.d("CameraDemo", "Pic saved");
    }
}

这是我为内部存储编写的代码

1 个答案:

答案 0 :(得分:0)

是的,你可以。您可以使用库向服务器发出请求,将您的图片上传为https://github.com/loopj/android-async-httphttp://projects.spring.io/spring-android/