1

画像をキャプチャしてSDカードに保存していますが、すべて問題ありません。しかし、この画像をユーザー名、パスワードなどの他のデータを含む文字列またはbase64またはutf-8として送信する必要があります。そのデータ変数を処理し、httpリクエストを使用してサーバーに送信する方法を教えてください

@Override
public void onPictureTaken(byte[] data, Camera camera) {

    File pictureFileDir = getDir();

    if (!pictureFileDir.exists() && !pictureFileDir.mkdirs()) 
    {
        Toast.makeText(context, "Can't create directory to save image.",Toast.LENGTH_LONG).show();
        return;
    }


    String photoFile = "MyPicture.jpg";
    String filename  = pictureFileDir.getPath() + File.separator + photoFile;
    File pictureFile = new File(filename);
    //Need to send this data to server     
    data.toString();

    try 
    {
        FileOutputStream fos = new FileOutputStream(pictureFile);
        fos.write(data);
        fos.close();
        Toast.makeText(context, "New Image saved:" +        photoFile,Toast.LENGTH_LONG).show();
    }
    catch (Exception error) 
    {
        Toast.makeText(context, "Image could not be saved.",Toast.LENGTH_LONG).show();
    }
    public void postData(String emailId,String passwrd) {
            // Create a new HttpClient and Post Header
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://XXXXAAAA.com/login");

            try {
                // Data that I am sending
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                nameValuePairs.add(new BasicNameValuePair("mb_code", emailId));
                nameValuePairs.add(new BasicNameValuePair("pwd", passwrd));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                // Execute HTTP Post Request
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                responseBody = EntityUtils.toString(response.getEntity());

                Log.d("result", responseBody);
            } 
            catch (Throwable t ) {
                //Toast.makeText( getApplicationContext(),""+t,Toast.LENGTH_LONG).show();
                Log.d("Error Time of Login",t+"");
            } 
        }
           }
4

0 に答える 0