android - Bluetooth not sending file to other device -


it asked didn't find solution. bluetooth application using bluetoothshare.class .

my source code sending file target device

mainactvity.class:

set<bluetoothdevice> devices = btadapter                             .getbondeddevices();                     final string btdevicename = selected_devicename;                     bluetoothdevice device = null;                      (bluetoothdevice itdevice : devices) {                         if (btdevicename.equals(itdevice.getname())) {                             device = itdevice;                         }                     }                      if (device != null) {                          contentvalues values = new contentvalues();                         values.put(bluetoothshare.uri, uri.tostring());                         values.put(bluetoothshare.mimetype, "image/jpeg");                         values.put(bluetoothshare.destination,                                 device.getaddress());                         values.put(bluetoothshare.direction,                                 bluetoothshare.direction_outbound);                         long ts = system.currenttimemillis();                         values.put(bluetoothshare.timestamp, ts);                         final uri contenturi = getapplicationcontext()                                 .getcontentresolver().insert(                                         bluetoothshare.content_uri, values);                         log.v(tag, "insert contenturi: " + contenturi                                 + "  device: " + device.getname());                         toast.maketext(getapplicationcontext(), "success",                                 toast.length_long).show();                     } else {                         textstatus                                 .settext("bluetooth remote device not found");                     }                 } else {                     textstatus.settext("bluetooth not activated");                 }             }              else {                 toast.maketext(getapplicationcontext(), "no devices found",                         toast.length_long).show();             } 

and bluetoothshare.class:

package process.bluetooth.sendfile.opp;  import android.net.uri; import android.provider.basecolumns;   public final class bluetoothshare implements basecolumns { private bluetoothshare() { }  public static final string permission_access = "android.permission.access_bluetooth_share";  public static final uri content_uri = uri         .parse("content://com.android.bluetooth.opp/btopp");  public static final string transfer_completed_action = "android.btopp.intent.action.transfer_complete";  public static final string incoming_file_confirmation_request_action = "android.btopp.intent.action.incoming_file_notification";  public static final string user_confirmation_timeout_action = "android.btopp.intent.action.user_confirmation_timeout";  public static final string uri = "uri";  public static final string filename_hint = "hint";  public static final string _data = "_data";  public static final string mimetype = "mimetype";  public static final string direction = "direction";  public static final string destination = "destination";  public static final string visibility = "visibility";  public static final string user_confirmation = "confirm";  public static final string status = "status";  public static final string total_bytes = "total_bytes";  public static final string current_bytes = "current_bytes";  public static final string timestamp = "timestamp";  public static final int direction_outbound = 0;  public static final int direction_inbound = 1;  public static final int user_confirmation_pending = 0;  public static final int user_confirmation_confirmed = 1;  public static final int user_confirmation_auto_confirmed = 2;  public static final int user_confirmation_denied = 3;  public static final int user_confirmation_timeout = 4;  public static final int visibility_visible = 0;  public static final int visibility_hidden = 1;  public static boolean isstatusinformational(int status) {     return (status >= 100 && status < 200); }  public static boolean isstatussuspended(int status) {     return (status == status_pending); }  public static boolean isstatussuccess(int status) {     return (status >= 200 && status < 300); }  public static boolean isstatuserror(int status) {     return (status >= 400 && status < 600); }  public static boolean isstatusclienterror(int status) {     return (status >= 400 && status < 500); }  public static boolean isstatusservererror(int status) {     return (status >= 500 && status < 600); }  public static boolean isstatuscompleted(int status) {     return (status >= 200 && status < 300)             || (status >= 400 && status < 600); }  public static final int status_pending = 190;  public static final int status_running = 192;  public static final int status_success = 200;  public static final int status_bad_request = 400;  public static final int status_forbidden = 403;  public static final int status_not_acceptable = 406;  public static final int status_length_required = 411;  public static final int status_precondition_failed = 412;  public static final int status_canceled = 490;  public static final int status_unknown_error = 491;  public static final int status_file_error = 492;  public static final int status_error_no_sdcard = 493;  public static final int status_error_sdcard_full = 494;  public static final int status_unhandled_obex_code = 495;  public static final int status_obex_data_error = 496;  public static final int status_connection_error = 497;  } 

bluetoothshare class not supported android 4.1 , above. can use following intent coding send file in android version 4.1 , above

intent intent = new intent();     intent.setaction(intent.action_send);     intent.setcomponent(new componentname(         "com.android.bluetooth",         "com.android.bluetooth.opp.bluetoothopplauncheractivity"));     intent.settype("image/jpeg");     file = new file(filepath);     intent.putextra(intent.extra_stream, uri.fromfile(file));     startactivity(intent); 

and devices in android v 2.2/2.3 not send file via bluetoothshare class.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -