Sending file using bluetooth in android [duplicate]
I am developing an Android application which uses Android's Bluetooth implementation. I want to know whether Bluetooth can be tested in an Android emulator. Can the user send files from the A开发者_如何学Pythonndroid emulator using Bluetooth?
I used this in my app....
try {
File myFile = new File("filepath");
MimeTypeMap mime = MimeTypeMap.getSingleton();
String ext=myFile.getName().substring(myFile.getName().lastIndexOf(".")+1);
String type = mime.getMimeTypeFromExtension(ext);
Intent sharingIntent = new Intent("android.intent.action.SEND");
sharingIntent.setType(type);
sharingIntent.putExtra("android.intent.extra.STREAM",Uri.fromFile(myFile));
startActivity(Intent.createChooser(sharingIntent,"Share using"));
}
catch(Exception e){
Toast.makeText(getBaseContext(), e.getMessage(),Toast.LENGTH_SHORT).show();
}
精彩评论