I want to add image from the SD card or From CAMERA, my debugger is not coming in try block

StackOverflow https://stackoverflow.com/questions/23659290

  •  22-07-2023
  •  | 
  •  

سؤال

I want to add image from Sd card or CAMERA... How to Add .. here is my registration request code...I'm using WEB service I want to know how to add a image,,My debugger is not Coming in try And Json is giving response Successfully

'class loginAccess extends AsyncTask {

protected void onPreExecute() {
    super.onPreExecute();
    pDialog = new ProgressDialog(Signin.this);
    pDialog.setMessage("Sig in...");
    pDialog.setIndeterminate(false);
    pDialog.setCancelable(true);
    pDialog.show();
}
@Override
protected String doInBackground(String... arg0) {
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    String FullName=fullName.getText().toString();
    String UserName=userName.getText().toString();
    String DateOfBirth=dob.getText().toString();
    String Age=age.getText().toString();


    String Sex=gender.getText().toString();
    String InterestedIn=interestIn.getText().toString();
    String ToMeet=toMeet.getText().toString();


    String Email=email.getText().toString();
    String Password=pwd.getText().toString();


    params.add(new BasicNameValuePair("fullName", FullName));
    params.add(new BasicNameValuePair("userName", UserName));
    params.add(new BasicNameValuePair("dob", DateOfBirth));
    params.add(new BasicNameValuePair("age", Age));
    params.add(new BasicNameValuePair("gender", Sex));
    params.add(new BasicNameValuePair("interestIn", InterestedIn));
    params.add(new BasicNameValuePair("toMeet", ToMeet));
    params.add(new BasicNameValuePair("image", null));      
    params.add(new BasicNameValuePair("email", Email));
    params.add(new BasicNameValuePair("pwd", Password));




    JSONObject json = jsonParser.makeHttpRequest(url,"POST", params);

    Log.d("Create Response", json.toString());

    try {

        if (json.has((TAG_SUCCESS))) {
            String status = json.getString(TAG_SUCCESS);
            if (status.equals("Success")) 
         {
          flag=0;   
          Intent i = new Intent(getApplicationContext(),Welcome.class);
    /*i.putExtra("Email",email);
          i.putExtra("Password", pwd);*/
          startActivity(i);
          finish();
         }
         else
         {
            // failed to Sign in
            flag=1;
        }
    }
    }catch (JSONException e) {
        e.printStackTrace();
    }
    return null;
}
protected void onPostExecute(String file_url) {
    pDialog.dismiss();
    if(flag==1)
        Toast.makeText(Signin.this,"Please Enter Correct informations", Toast.LENGTH_LONG).show();

}

}

} '

هل كانت مفيدة؟

المحلول

i m using this code ..but i want know how add mg in mySql database

' private void selectImage() {

        final CharSequence[] options = { "Take Photo", "Choose from Gallery","Cancel" };

        AlertDialog.Builder builder = new AlertDialog.Builder(Signin.this);
        builder.setTitle("Add Photo!");
        builder.setItems(options, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int item) {
                if (options[item].equals("Take Photo"))
                {
                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg");
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
                    startActivityForResult(intent, 1);
                }
                else if (options[item].equals("Choose from Gallery"))
                {
                    Intent intent = new   Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                    startActivityForResult(intent, 2);

                }
                else if (options[item].equals("Cancel")) {
                    dialog.dismiss();
                }
            }
        });
        builder.show();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            ImageView viewImage = null;
            if (requestCode == 1) {
                File f = new File(Environment.getExternalStorageDirectory().toString());
                for (File temp : f.listFiles()) {
                    if (temp.getName().equals("temp.jpg")) {
                        f = temp;
                        break;
                    }
                }
                try {
                    Bitmap bitmap;
                    BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();

                    bitmap = BitmapFactory.decodeFile(f.getAbsolutePath(),
                            bitmapOptions); 

                    viewImage.setImageBitmap(bitmap);

                    String path = android.os.Environment
                            .getExternalStorageDirectory()
                            + File.separator
                            + "Phoenix" + File.separator + "default";
                    f.delete();
                    OutputStream outFile = null;
                    File file = new File(path, String.valueOf(System.currentTimeMillis()) + ".jpg");
                    try {
                        outFile = new FileOutputStream(file);
                        bitmap.compress(Bitmap.CompressFormat.JPEG, 85, outFile);
                        outFile.flush();
                        outFile.close();
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else if (requestCode == 2) {

                Uri selectedImage = data.getData();
                String[] filePath = { MediaStore.Images.Media.DATA };
                Cursor c = getContentResolver().query(selectedImage,filePath, null, null, null);
                c.moveToFirst();
                int columnIndex = c.getColumnIndex(filePath[0]);
                String picturePath = c.getString(columnIndex);
                c.close();
                Bitmap thumbnail = (BitmapFactory.decodeFile(picturePath));
                Log.w("path of image from gallery......******************.........", picturePath+"");
                viewImage.setImageBitmap(thumbnail);
            }
        }

'
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top