Blue-tooth file not sent error
Asked Answered
E

1

2

I am trying to send a file from my application on android phone to other devices (they may or may not be be android phones).

my whole code for sending the file is :

try{
            File dir = getCacheDir();
            File f;
            try {
                f = File.createTempFile("card", ".Xcard", dir);

                Intent i = new Intent();
                i.setAction(Intent.ACTION_SEND);
                i.setType("*/*");
                i.putExtra(i.EXTRA_STREAM, Uri.fromFile(f));
                startActivity(i);


            } catch (IOException e) {
                // TODO Auto-generated catch block
                Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();

                e.printStackTrace();
            }

            }catch(Exception e){

                Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
            }

But my file is not being sent to the phone?? What is wrong in the code? Is it because the receiving phone does not recognize my ".Xcard" file?

But I don't think that is the problem because i tried sending "apk" file to the other device and it received even though it doesn't understand the apk file. (i am trying with the non-android phone).

Then why not the file that I am sending being not-sent? is it because it is created in Cache directory?

Expostulation answered 7/5, 2013 at 7:27 Comment(11)
What happens? Does an activity appear that allows the user to choose where to send the file? Maybe the file is being ignored because it is empty -- have you tried writing content to it?Myrmidon
no I havent written any content to it , I will check if it is sent with some content.Expostulation
I added this code: OutputStream op = new FileOutputStream(f); int oneByte = 1; op.write(oneByte); op.close(); but it is not workingExpostulation
The code looks ok -- but what happens? Does an activity appear? A dialog? An error message? Nothing at all?Myrmidon
I am getting an error saying "file filename was not sent to bluetoothdevicename"Expostulation
A dialog appears for selection :whether i want to send file using bluetooth, gmail etc, then i select bluetooth, then the al the devices in the range are shown and then i select the required deviceExpostulation
after i select it , a toast appears "sending file to device name"Expostulation
and then again the toast with the error...... basically it is using the default bluetooth application provided by the systemExpostulation
Does it work if you choose "Send by email?"Myrmidon
right now i cant test it using e-mail , can you do it ?? thats the only code i am using on the onCLick method of my buttonExpostulation
let us continue this discussion in chatExpostulation
M
0

This worked for me:

String root = Environment.getExternalStorageDirectory().toString();
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/html");
File f = new File(root + "/bluetooth/test2.html");
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
startActivity(Intent.createChooser(i, "Send page"));

The difference is in create the file in the bluetooth directory.

Marley answered 28/7, 2013 at 21:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.