I want to develop application that sends image/txt or any file from one android device to another none android device using Bluetooth.
Please anyone can give help or source code for that?
While you can't share installed apps through Bluetooth, you can share links to app downloads in the Play Store via Bluetooth, as well as Android Beam. You can also share APK files, which are used to install apps on Android over Bluetooth.
Here is the code from which you can send file via bluetooth from android device to any device.
btnOk.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
txtContent = (EditText)findViewById(R.id.txtContent);
imageView = (ImageView)findViewById(R.id.imageView);
linearLayout = (LinearLayout)findViewById(R.id.linearLayout);
viewToBeConverted = (TextView) findViewById(R.id.hello);
linearLayout.setDrawingCacheEnabled(true);
//Toast.makeText(MainActivity.this, file.toString(), Toast.LENGTH_LONG).show();
try
{
if(file.exists())
{
file.delete();
}
out = new FileOutputStream(file);
}
catch (Exception e)
{
Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
viewToBeConverted.setText(txtContent.getText().toString());
viewToBeConverted.setDrawingCacheEnabled(true);
// Toast.makeText(MainActivity.this, " " + viewToBeConverted.getDrawingCache(), Toast.LENGTH_LONG).show();
txtContent.setText("");
Bitmap viewBitmap = linearLayout.getDrawingCache();
linearLayout.setVisibility(1);
imageView.setImageBitmap(viewBitmap);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
viewBitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();
try
{
out.write(b);
out.flush();
out.close();
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/png");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file) );
startActivity(intent);
}
catch (Exception e)
{
Toast.makeText(MainActivity.this, " " + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
});
Enjoy. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With