Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Button tomarFoto;
- private Button subirFoto;
- private ImageView verFoto;
- private static final int TAKE_PICTURE=1;
- double aleatorio = new Double(Math.random() * 100).intValue();
- String foto = Environment.getExternalStorageDirectory() + "/imagen/"+ aleatorio +".jpg";
- File imagen;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- tomarFoto = (Button) findViewById(R.id.toarFoto);
- subirFoto = (Button) findViewById(R.id.subirFoto);
- // verFoto = (ImageView) findViewById(R.id.imagen);
- tomarFoto.setOnClickListener(this);
- subirFoto.setOnClickListener(this);
- }
- @Override
- public void onClick(View v) {
- v.getId();
- switch (v.getId()){
- case R.id.subirFoto:
- subirFoto();
- break;
- case R.id.toarFoto:
- tomarFoto();
- break;
- }
- }
- private void subirFoto(){
- AsyncHttpClient client = new AsyncHttpClient();
- String url = "http://192.168.0.103:8080/android/foto/subirfoto.php";
- RequestParams requestParams = new RequestParams();
- try {
- requestParams.put("imagen",imagen.getAbsolutePath());
- }catch (Exception e){
- Toast.makeText(this,e.getMessage().toString(),Toast.LENGTH_LONG).show();
- }
- RequestHandle post = client.post(url, requestParams, new AsyncHttpResponseHandler() {
- @Override
- public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
- if (statusCode == 200){
- Toast.makeText(getApplicationContext(),"Se ha subido la imagen", Toast.LENGTH_SHORT).show();
- }
- }
- @Override
- public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
- Toast.makeText(getApplicationContext(),"Error al subir la imagen", Toast.LENGTH_SHORT).show();
- }
- });
- }
- private void tomarFoto(){
- Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
- Uri output = Uri.fromFile(new File(foto));
- intent.putExtra(MediaStore.EXTRA_OUTPUT, output);
- startActivityForResult(intent, TAKE_PICTURE);
- }
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data){
- verFoto = (ImageView) findViewById(R.id.imagen);
- verFoto.setImageBitmap(BitmapFactory.decodeFile(foto));
- imagen = new File(foto);
- Toast.makeText(getApplicationContext(),imagen.toString(),Toast.LENGTH_LONG).show();
- }
- <?php
- $image=$_FILES["imagen"]["name"];
- $ruta=$_FILES["imagen"]["tmp_name"];
- $destino="img/".$image;
- copy($ruta,$destino);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement