android蓝牙传输文件到mysql_使用Android将图像发送到MySQL数据库

我有当前的应用程序从MySQL数据库发送和检索数据,但到目前为止我传输的信息是字符串.如何更新以下代码以便能够发送图像.

public class NewProductActivity extends Activity {

// Progress Dialog

private ProgressDialog pDialog;

JSONParser jsonParser = new JSONParser();

EditText inputName;

EditText inputPrice;

EditText inputDesc;

EditText inputImg;

Button btnTakePhoto;

ImageView imgTakenPhoto;

private static final int CAM_REQUREST = 1313;

// url to create new product

private static String url_create_product = "http://buiud.com/android_connect/create_product.php";

// JSON Node names

private static final String TAG_SUCCESS = "success";

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.add_product);

// Edit Text

inputName = (EditText) findViewById(R.id.inputName);

inputPrice = (EditText) findViewById(R.id.inputPrice);

inputDesc = (EditText) findViewById(R.id.inputDesc);

inputImg = (EditText) findViewById(R.id.imageView1);

// Create button

Button btnCreateProduct = (Button) findViewById(R.id.btnCreateProduct);

// button click event

btnCreateProduct.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

// creating new product in background thread

new CreateNewProduct().execute();

}

});

btnTakePhoto = (Button) findViewById(R.id.button1);

imgTakenPhoto = (ImageView) findViewById(R.id.imageView1);

btnTakePhoto.setOnClickListener(new btnTakePhotoClicker());

}

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

// TODO Auto-generated method stub

super.onActivityResult(requestCode, resultCode, data);

if (requestCode == CAM_REQUREST) {

Bitmap thumbnail = (Bitmap) data.getExtras().get("data");

imgTakenPhoto.setImageBitmap(thumbnail);

}

}

class btnTakePhotoClicker implements Button.OnClickListener

{

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

startActivityForResult(cameraIntent, CAM_REQUREST);

}

}

/**

* Background Async Task to Create new product

* */

class CreateNewProduct extends AsyncTask {

/**

* Before starting background thread Show Progress Dialog

* */

@Override

protected void onPreExecute() {

super.onPreExecute();

pDialog = new ProgressDialog(NewProductActivity.this);

pDialog.setMessage("Creating Product..");

pDialog.setIndeterminate(false);

pDialog.setCancelable(true);

pDialog.show();

}

/**

* Creating product

* */

protected String doInBackground(String... args) {

String name = inputName.getText().toString();

String price = inputPrice.getText().toString();

String description = inputDesc.getText().toString();

String image = inputImg.getText().toString();

// Building Parameters

List params = new ArrayList();

params.add(new BasicNameValuePair("name", name));

params.add(new BasicNameValuePair("price", price));

params.add(new BasicNameValuePair("description", description));

params.add(new BasicNameValuePair("image", image));

// getting JSON Object

// Note that create product url accepts POST method

JSONObject json = jsonParser.makeHttpRequest(url_create_product,

"POST", params);

// check log cat fro response

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

// check for success tag

try {

int success = json.getInt(TAG_SUCCESS);

if (success == 1) {

// successfully created product

Intent i = new Intent(getApplicationContext(), AllProductsActivity.class);

startActivity(i);

// closing this screen

finish();

} else {

// failed to create product

}

} catch (JSONException e) {

e.printStackTrace();

}

return null;

}

/**

* After completing background task Dismiss the progress dialog

* **/

protected void onPostExecute(String file_url) {

// dismiss the dialog once done

pDialog.dismiss();

}

}

}

注意:我添加了图像字段,因为我做了其他字符串字段,但应用程序现在停止,它无法将图片转换为文本显然.让我知道你的想法,或任何类型的铸造.我只是拍了一张照片,那张照片将被发送到MySQL.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值