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!
Related
I am using Tizen SDK for Wearable from samsung-gear site in order to communicate a provider android application with Samsung Gear 2 device. I am able to send notifications to gear and once I run the consumer application on gear 2, I am able to transfer data between the watch and my Android phone as well.
What I am trying to do is to check within the Android application if the phone is paired with Gear 2. Something as simple as creating a communication object using the accessory service and calling a method like isPaired()?:
CommunicationObject commObject = new CommunicationObject(Communication parameters);
// I am assuming some connection call like commObject.connect() should be invoked first
// where I can check for it's result afterwards such as
if(commObject.isPaired())
{
// do something
}
I think SDK examples such as consumer/provider application they provide on their site already assume that the device is paired, hence they show how to transfer data between phone and the gear watch. Yet I am seeking something as simple as asking the phone if it's paired with a gear device, which should be the prerequisite for transferring the data, which is done automatically by Samsung Gear Manager I believe right now.
Note: For the case of example provider/consumer applications, one can just check if any connection is available using the code in them. But the data transfer connection enabled only when I manually start the consumer app from the gear device, otherwise it acts like gear device is not paired even though it is.
I believe this is not the most popular topic these days so I will post what I came up with as an answer although I doubt anyone will need it, without being perfect, it's the closest way I could get to my goal using the available documentation.
I should also mention that this slide helped me stay on track as well.
In my solution, there must be an active 2-way connection between the gear widget(consumer/.wgt) and the host side application(provider/.apk) as in the example application provided by Samsung(Hello Accessory) at all times, at least during the time where I wanted to check for the pairing condition. The documentation refers to it as:
Hello Gear is a simple application that consists of:
Host-side application(provider) : HelloAccessoryProvider.apk
Wearable-side Application(consumer) : HelloAccessoryConsumer.wgt (Web app)
See that both sides have some xml configuration and Android requires specific permissions which are explained in detail in Hello Gear documentation.
This 2 way communication is provided by the Samsung Accessory Framework on the network layer(through Samsung Accessory Protocol, SAP) given that both sides implement the same Accessory Service Profile, again, configured via the xml files on both ends(service name, channel id etc.).
Android side implements the protocol as a service, extending the SAAgent abstract class. Then the widget on gear side application(.wgt) can invoke the SAAgent callbacks and provider/consumer communication is handled through SASocket objects claimed on both ends over the predefined channel in the xml configuration files.
Please note that this communication has to be initialized on both ends, in my case I had to open the widget application once on Gear(I believe there should be a way to start the gear widget via an intent or notification, somehow, but I could not find yet) after the Android application has started, here started means that SAAgent service is up and bound to an Activity, being eligible to receive callbacks and send state messages to the rest of the application via broadcasts. Such as the number of active connections, or any data transmission between the gear socket and Android application can be done this way.
Note that if you don't have to transfer data between the gear widget and the Android application, you may just be OK with the notifications. The only requirement to send notifications to the Gear from Android applications seems to be that the Gear is paired with your phone and connected via Bluetooth. Then you can just send an intent as explained in more detail here in Section 6. All you need should be the permission:
com.samsung.wmanager.ENABLE_NOTIFICATION
and some metadata definition in your ApplicationManifest.xml file explained in the same section.
<meta-data
android:name="master_app_packagename"
android:value="com.example.gearMasterApp"/>
<meta-data
android:name="app_notification_maxbyte"
android:value="300 "/>
And here is the sample code for intent, in order to send notifications to the Gear:
public static final String ALERT_NOTIFICATION =
“com.samsung.accessory.intent.action.ALERT_NOTIFICATION_ITEM”;
public static final int NOTIFICATION_SOURCE_API_SECOND = 3;
Bitmap bitmapImg;
// Put data to Intent
Intent myIntent = new Intent(ALERT_NOTIFICATION);
myIntent.putExtra("NOTIFICATION_PACKAGE_NAME", “com.example.gearApp”);
myIntent.putExtra("NOTIFICATION_VERSION", NOTIFICATION_SOURCE_API_SECOND);
myIntent.putExtra("NOTIFICATION_TIME", System.currentTimeMillis(););
myIntent.putExtra("NOTIFICATION_MAIN_TEXT", “Title Text”);
myIntent.putExtra("NOTIFICATION_TEXT_MESSAGE", ”Body text);
byte [] byteArray = convertResizeBitmapToByte(bitmapImg);
myIntent.putExtra("NOTIFICATION_APP_ICON", byteArray);
myIntent.putExtra("NOTIFICATION_LAUNCH_INTENT", “com.example.gearMasterApp”);
myIntent.putExtra("NOTIFICATION_LAUNCH_TOACC_INTENT", “com.example.gearSideApp”);
sendBroadcast(myIntent);
public byte[] convertResizeBitmapToByte(Bitmap bitmap){
Bitmap scBitmap = Bitmap.createScaledBitmap(bitmap, 75, 75, false);
ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
scBitmap.compress(Bitmap.CompressFormat.PNG, 50, byteArrayStream);
return byteArrayStream.toByteArray();
}
Once the notification is read on the gear side, you can receive the intent action along with some optional parameters:
Intent Action :
"com.samsung.accessory.intent.action.UPDATE_NOTIFICATION_ITEM"
This could be another approach to check active communication with the Gear and your phone, but there is no guarantee that the notification will be read and my case did require to keep the Gear communication optional in order to allow the Android application continue it's tasks even though there is no active connection with the Gear.
About the original question, where I asked for a way to detect if the Gear is paired or not, I tried listing paired Bluetooth devices using getBondedDevices() method of Android's BluetoothAdapter but it shows that your Gear is paired even when your Gear is turned off, which was not enough for my needs and I did not find it logical. It's true though once your device is turned back on.
I'm happy with the above solution since it was enough for my needs, therefore I will accept my own answer.
Does anyone know if there is an equivalent to MPVolumeView available in Android?
Basically, it's a a built in component in iOS that can present users with a system volume slider, and / or (what I'm really after in Android) a list of available bluetooth / Airplay audio output options (i.e. bluetooth speakers). The image below shows it in action:
Is there any easy option for listing bluetooth etc. audio routing options in Android, or do you have to write all the scanning, connecting, audio routing code yourself?
From the lack of response, and the endless googling around the subject of connecting to A2DP Bluetooth sinks, that I've been doing lately, the sad answer to this question seems to be no, there is nothing quite like the MPVolumeView in Android.
The nearest thing would be to either write it all yourself, as I feared, or, to simply pop open the system Bluetooth options windows from your app (ensuring you've got BLUETOOTH_ADMIN permissions set up in your manifest first):
Intent intentOpenBluetoothSettings = new Intent();
intentOpenBluetoothSettings.setAction(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
startActivity(intentOpenBluetoothSettings);
I am looking for some advice regarding NFC data.
I have a device, lets say a printer or speaker. I want to put a NFC tag on this device. The data I want to put in NFC tag is DeviceName/MacAddress/Password.
Now the requirement is when ever user touches my tag with Android or Windows phone
My app should be launched.
If my app is not already installed it should take me to Play Store or Windows store
I shoul be able to get data from NFC tag in my application (DeviceName/MacAddress/Password)
As of now I could get it done in Android using 2 NDEF records
Custom MIME type record with my data (application/vnd.pakage.name )
Android Application record.
The issue is how can I launch app in Windows Phone?
As I understand with custom Mime application/vnd.pakage.name Windows application could not be launched. Pls. let me know if I am wrong.
Windows LaunchApp record should be the first record and if I make that as first record then in Android I don't get my data.
The Only soluction which looks probable is the NDEF records in following formats.
Custom URI with my data (myscheme://my.package.com?DeviceName/MacAddress/Password)
Android application record.
But using this format also I am not able to get data in Android. Pls. let me know if there is any better solution? How I can get data in Android?
Thanks
Your last proposal for a solution should work. Make sure your intent filter declares at least the scheme and the hostname. This article may be of interest, too: How to Create Cross-Platform LaunchApp NFC Tags.
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.
I'm working on a project that requires my app to be able to send DTMF tones on the voice's uplink frequency during an active call.
My 2 conditions are:
We don't use a customized Android platform
We don't need to root the phone
I've spent several days doing my homework and am aware that in-call DTMF sending is not supported by the current SDK/standard APIs. However, by using the relevant classes in com.android.internal.telephony I am hoping to mimic how the native Phone app does this. I followed this site on how to use internal APIs for standard 3rd party apps.
I've also set myself up with the Android OS dev environment and am able to run the Phone app in debug mode on an emulator to figure its inner workings.
I tried various ways on a stock standard emulator but the errors I got were:
After trying to install a renamed app based on Phone.apk's source using the sharedUserId of android.uid.phone, I got:
Installation error: INSTALL_FAILED_SHARED_USER_INCOMPATIBLE
No doubt due to the fact I don't have the system cert to sign it.
After trying to write a custom app based on the relevant DTMF tone sending code from Phone.apk's source, I get the following error at setting up the PhoneFactory;
java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.provider.Telephony.SPN_STRINGS_UPDATED.
No doubt due to the fact my app doesn't have the right permissions, although AndroidManifest.xml is setup with the same permissions as Phone.apk.
I'm at a loss as to what else I could try. Does anyone have any suggestions?
Thanks in advance,
Simon.
You've taken an interesting approach, and I commend your efforts. Unfortunately, there are some reserved internal privileges (evidently, such as SPN_STRINGS_UPDATED) that you aren't allowed to use as an app developer, which more or less breaks this approach. You could try removing the area of code causing this, but I'm fairly certain you will run into a blocking problem.
Hence, I'm afraid this is not possible at the moment. There's an open feature request on Android for sending DTMF tones over an existing phone call, but it has been dormant there for almost two years.
I understand that this doesn't resolve your problem, but take note that you can send DTMF tones directly after dialing a number:
Intent i = new Intent("android.intent.action.CALL",
Uri.parse("tel://" + number + "," + dtmfTones));
Simply put, you won't be able to do it without customizing at least the Phone app, which has to run as a system user in order to access the modem. In order to do this, you have to root your phone.
To meet your requirements the only possible solution is to enhance the android platform. We did just that, and already sent in our patches to the AOSP project:
https://android-review.googlesource.com/32820
https://android-review.googlesource.com/32821
We are currently waiting for the Google developers to review and accept our contribution. If you are interested, please let Google know on the various AOSP lists (android-contrib, android-platform). It will hopefully expedite the review.
Best Regards,
Gergely
You can't send DTMF tones during an active call, but you can send them when you "program" them when you initiate the call.
see the following post: https://stackoverflow.com/a/12986066/475472