Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. private Button tomarFoto;
  2. private Button subirFoto;
  3. private ImageView verFoto;
  4. private static final int TAKE_PICTURE=1;
  5.  
  6. double aleatorio = new Double(Math.random() * 100).intValue();
  7. String foto = Environment.getExternalStorageDirectory() + "/imagen/"+ aleatorio +".jpg";
  8. File imagen;
  9. @Override
  10. protected void onCreate(Bundle savedInstanceState) {
  11. super.onCreate(savedInstanceState);
  12. setContentView(R.layout.activity_main);
  13. tomarFoto = (Button) findViewById(R.id.toarFoto);
  14. subirFoto = (Button) findViewById(R.id.subirFoto);
  15. // verFoto = (ImageView) findViewById(R.id.imagen);
  16. tomarFoto.setOnClickListener(this);
  17. subirFoto.setOnClickListener(this);
  18. }
  19.  
  20. @Override
  21. public void onClick(View v) {
  22. v.getId();
  23. switch (v.getId()){
  24. case R.id.subirFoto:
  25. subirFoto();
  26. break;
  27. case R.id.toarFoto:
  28. tomarFoto();
  29. break;
  30. }
  31. }
  32. private void subirFoto(){
  33. AsyncHttpClient client = new AsyncHttpClient();
  34. String url = "http://192.168.0.103:8080/android/foto/subirfoto.php";
  35. RequestParams requestParams = new RequestParams();
  36. try {
  37. requestParams.put("imagen",imagen.getAbsolutePath());
  38. }catch (Exception e){
  39. Toast.makeText(this,e.getMessage().toString(),Toast.LENGTH_LONG).show();
  40. }
  41. RequestHandle post = client.post(url, requestParams, new AsyncHttpResponseHandler() {
  42. @Override
  43. public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
  44. if (statusCode == 200){
  45. Toast.makeText(getApplicationContext(),"Se ha subido la imagen", Toast.LENGTH_SHORT).show();
  46. }
  47. }
  48.  
  49. @Override
  50. public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
  51. Toast.makeText(getApplicationContext(),"Error al subir la imagen", Toast.LENGTH_SHORT).show();
  52. }
  53. });
  54. }
  55. private void tomarFoto(){
  56. Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  57. Uri output = Uri.fromFile(new File(foto));
  58. intent.putExtra(MediaStore.EXTRA_OUTPUT, output);
  59. startActivityForResult(intent, TAKE_PICTURE);
  60. }
  61.  
  62. @Override
  63. public void onActivityResult(int requestCode, int resultCode, Intent data){
  64. verFoto = (ImageView) findViewById(R.id.imagen);
  65. verFoto.setImageBitmap(BitmapFactory.decodeFile(foto));
  66. imagen = new File(foto);
  67.  
  68. Toast.makeText(getApplicationContext(),imagen.toString(),Toast.LENGTH_LONG).show();
  69. }
  70.  
  71. <?php
  72.  
  73. $image=$_FILES["imagen"]["name"];
  74. $ruta=$_FILES["imagen"]["tmp_name"];
  75. $destino="img/".$image;
  76. copy($ruta,$destino);
  77.  
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement