I am developing an app which transfers files to and from Android Wear watch by using FTP server running on watch. Right now I connect devices to same network by creating hotspot on smartphone. Then FTP server is started on watch and smartphone can connect to it. The problem is that I want to create som simple and universal app to connect from smartphone. However hotspot uses DHCP and I cant asign static IP to watch so I want to create only small app for smartphone which creates something like FTP intent and then some file explorer should open this intent. For example I prepare intent lik:
String url="ftp://user:pass#192.168.43.5:21"
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
but I am getting no activity to handle intent found exception with es file explorer and also solid file explorer installed. I have tried using AndFTP which provides very good intent documentation but it wasn't very stable. Do you have any idea if ES file explorer or something similar can accept intent to open ftp connection?
I don't know about ES File Explorer or any other app but I found it could be done using chrome with a little hack. By using google chrome's navigator.
String url = "ftp://user:pass#192.168.43.5:21";
String uri = "googlechrome://navigate?url=" + url;
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(uri));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setPackage("com.android.chrome");
The last 2 lines are to open intent specifically in chrome.
I hope this solves your problem.
Related
I´m trying to develop an App which can send an .APK file via Bluetooth to another device with an Insecure Rfcomm connection. I´m running self-coded apps on both devices. The apps are not the same but I can still set the UUID, Rfcomm Listener and so on, so the connection should work fine and because of the insecure rfcomm without any alert to accept the transfer. I´ve tried the BluetoothChat example from the Android developer page, but I´ve got problems with changing the code for my purposes. Can anyone give me some snippets of code or any link to an tutorial how to setup Apps for Bluetooth File transfer? Every useful stuff is welcome.
EDIT:
You could say I´m trying to develop an app, which can "update" another app on another phone by Bluetooth.
Thanks
This worked for me:
public void shareApk(Context context) {
try {
PackageManager pm = context.getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo(context.getPackageName(), 0);//context.getPackageName() is used for send my app's apk, you can give package name which you want to share
File srcFile = new File(ai.sourceDir);
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.setType("application/vnd.android.package-archive");
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(srcFile));
share.setPackage("com.android.bluetooth");
context.startActivity(share);
//context.startActivity(Intent.createChooser(share, context.getString(R.string.share_using)));
} catch (Exception e) {
Log.e("ShareApp", e.getMessage());
}
}
I am looking for viable ways to send a file from my android app to another android device that doesnt have my app installed.
Option 1. Via share intent: https://stackoverflow.com/a/16755810/1865583
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(picURI);
sharingIntent.setType("image/*");
sharingIntent.setPackage("com.android.bluetooth");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image"));
Issue regarding option 1:
I would love if i could specify the device i want to send this file to, in the intent parameters? I've searched online but cant find this option.
I've stumbled across this multiple times but it only works on particular devices as far people claim. https://evilzone.org/java/%28android%29-three-ways-to-send-data-over-bluetooth/
ContentValues values = new ContentValues();
String address = device.getAddress();
values.put(BluetoothShare.URI, Uri.fromFile(new File("somefile.mp3")).toString());
values.put(BluetoothShare.DESTINATION, address);
values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);
Long ts = System.currentTimeMillis();
values.put(BluetoothShare.TIMESTAMP, ts);
Uri contentUri = getContentResolver().insert(BluetoothShare.CONTENT_URI, values);
Is there a working/tested way to specify the device the bluetooth will try to send the file too? (and pair by default if necessary)?
Option 2. Using Bluetooth sockets to control the file transfer :
I am actually quite interested in developing this options, but all the examples online go about sending files from client to server where both code bases are developed by me.
What i need is to connect via bluetooth to the other android bluetooth enabled device and initiate the file transfer? But i am unsure how to initiate this transfer or which protocols are used if any etc? How would you connect to the default bluetooth app to send it a file?
I've found some information that i thought using as starting point https://stackoverflow.com/a/17237945/1865583
The user talks about using 00001106-0000-1000-8000-00805F9B34FB (File transfer service) and starting a RfcommSocket for communication. Would this be the right way to go to communicate with bluetooth android apps for file transfer?
I tried some solutions,for that first I need to install hp printer plugin,I want to do like first my phone wifi scan that printer name,then install its plugin automatically so that user can easily connect to that printer.
Can Anybody help?
You can do this by using print share application:
Intent i = new Intent(Intent.ACTION_VIEW); i.setPackage("com.dynamixsoftware.printershare");
i.setDataAndType(printFileUri,"text/plain"); startActivity(i);
where 'printFileUri' is as follows:
static final Uri printFileUri = Uri.parse("file:///sdcard/Calci_print.txt");
I'd like to share information between my own app running on 2 different phones via a bluetooth intent.
Lets say i have some data on phone a, then i will tap synch and it will start the same app at phone b (if it's not already open) with a bundle containing that "data".
My app on phone b acts acordingly.
Is that possible?
I am not really sure if this is what you're looking for.
Intent i = new Intent(Intent.ACTION_SEND); i.setType("image/jpeg");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse(fileLocation));
startActivity(Intent.createChooser(i, "Send Image"));
This intent shows all available options for file send such as Email and Bluetooth. Choose Bluetooth and the device initiates bluetooth discovery.
Thanks!
From my understanding, it is not possible.
Use BluetoothSocket and BluetoothServerSocket instead
I recently saw this interesting video about NFC, and i know you are talking about bluetooth.
but watch this video http://www.youtube.com/watch?feature=player_detailpage&v=49L7z3rxz4Q#t=768s
Timestamp added, starts at: 12:48.
What they did is starting the app trough nfc but probably they send the data trough bluetooth. Its really user-friendly.
In this way you do not need to push the button sync but just bump eachother phones together!
I hope this helps you maybe further,
Daniel
I think you must make use of BluetoothServerSocket to accept incoming connections. Exchange data with server once connected. To get started check out this doc.
Start-up
You could find the source code in your SDK. Download samples from Android SDK manager. Select 'Samples for SDK' from the required SDK version.
Go to
<location of android-sdk>/samples/<version>/
Open 'Bluetooth Chat' application. It has almost everything you need.
Thanks!
By the way, don't forget to accept the answer!
I am sending file using following code in my android application :
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/png");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file) );
startActivity(intent);
But it shows me list like email , bluetooth , and many other. I dont want this list and should be sent directly without user interaction to perticular paired device .
Is it possible in android ?
Thanks in advance.
Nope, current API's will not allow you to bypass user confirmation, but you can do this programmatically using the Bluetooth API's after the pairing stage. Establish a RFCOMM and then use InputStream/OutputStream to receive/send files. A great place to start is looking at the BluetoothChat example by google.