How to use InputMethodService in wifi p2p service discovery? - android

I am new to android, please tell me if inputMethodService can work with wifi p2p service discovery? I want one phone to act as a keyboard for another phone. Please tell me if it is possible and which resources to refer in order to begin with it. Thank you.

I think what you need to do is not worry about the input-method in the first device, but create an application where you input text as normal from what ever you are using for input on the android device and then make that application responsible to transfer the acquired text to another device in which you want to input, in real time.
Given the restrictions on the IME in android, the other device should have the modified input-method that receives the data and enters for you in turn.
You have to be very careful for this kind of data transfer because the IME in android is essentially capable of monitoring anything the user enters, so the data transfer should be really really secure.

Related

How to connect two android devices and show text from A's clipboard on B's screen - all approaches?

Basically - the task:
On device one, text is copied to clipboard.
Device two must perform some actions with the text just copied on device one, for example invoke a browser with search engine page and query ?q=text-from-clipboard-just-copied-on-device-A.
First question: is it possible to do with out-of-the box applications?
Second question: if not, what are different approaches to do that?
Both devices are on the same local wi-fi network (connected via router). Connection via external ip server is not what I want, I would prefer a server running on device A or device B (android) if there's any, so there would be not need in working internet connection.
I see there's an option of Wi-fi direct (my devices are 4.0 and 4.2 Android versions, so it's possible). Is there a source code how to send a message with wifi direct and receive it on the other side?
First question: is it possible to do with out-of-the box applications?
No it is not possible with out of box applications. I would be surprised if there would be one!
Second question: if not, what are different approaches to do that?
One approach will be to implement Bluetooth Server and Client applications that can communicate between them and excange data. Ofcourse you will be able to implement different functionalities for example opening a webpage with the text as you mentioned in your question.
Or you can also have a look at NFC Communication explained here: (Remember the devices will have to be at very short distances to achieve such communication) http://developer.android.com/guide/topics/connectivity/nfc/index.html
I guess question 1 is not possible. I can't imagine that an out of the box app knows what action you want to perform with the received data.
Solution for question two could be working with tcp sockets. One device as server one as client, so that you can send your sting, link or whatever to the other device, which receives this and performs some action.
edit: Sorry, just read that you don't want to do it with internet permission, so data exchange via bluetooth, sms... could be possible

Android Beam - payload transfer from both devices when only one Touch To Beam?

Ok, I watched the Google I/O from 2011 presentation on NFC on peer to peer.
The demo was done on Gingerbread and using the application Sticky Notes found
Now in this demo, both device the onNewIntent() was called at the same time so both devices are trying to share information to one another.
On ICS and above, you have Android Beam..
With Android Beam, you have to touch to trigger the onNewIntent() event that will send the NDef message across.
Now the problem with this is that now to trigger the onNewIntent() on both devices, both user on each device has to "Touch To Beam" at the same time.
Is there a way that when you Touch To Beam on one device, both can have the onNewIntent() to be called?
I am trying to develop an app that will exchange data to each other but for it to work in a nice friendly fashion I need the devices to share the data at the same time once the Touch To Beam has been initiated on one device. I do hope this is possible.
Edit: It looks like this might not be possible to do :(
As far as I can tell, the feature you want is not available over NFC itself. The touch-to-beam/SNEP/NPP transfer is one direction only on Android. The user that clicks his screen will push an NDEF message to the other phone.
What I believe they've done in the video is set up a bluetooth connection with the NDEF message to make the transfer (as you saw in the stickynotes demo). Unfortunately there is no nice API for this.
However, the EasyNFC project promises to be able to allow you to create a bluetooth connection and socket between two phones/applications. Check it out here
I had a try and didn't really like the Touch-to-Beam UI that was still required in the set up of the bluetooth connection. It also didnt really suit my needs, as I wanted to transfer phone to computer and didn't really want to implement NFC P2P and a bluetooth connection.
Did you try this:
Use the Touch to Beam on phone-1 to "PUSH" the data, while on the other (phone-2), use the NDEF_DISCOVERED/TECH_DISCOVERED intent to trigger/start the data capture/reception. I vaguely remember one of the above intents were triggered when a PUSH is done. Although, every transmission requires a "Touch" to start the beaming.
When you think in general, Android should not allow the NFC data transfer in both direction at the same time. Lets think of a scenario where I want to send a thing to my friend with NFC. What is actively open on my friend's phone is not important. I should send this thing even the same app is not open on the receiver side. There may be another app in my friends phone that tries to send another thing to me. When we touch our phones, Android Beam (TM) appears and he data is sent from the phone that is touched.
In you case I think you should disable Android Beam (TM) by setting setNdefPushMessage(null) and do sending both ways using the old way.
https://developer.android.com/preview/api-overview.html
I think it will be available in L!!!
NFC enhancements
Your app can invoke the Android Beam on the user’s device to share data by calling android.nfc.NfcAdapter.invokeBeam(). This avoids the need for the user to manually tap the device against another NFC-capable device to complete the data transfer.

Is it possible to lock the bluetooth in android device for a specific time period

I am able to disable Bluetooth using Bluetooth API`s Disable method .but my requirement is also to prevent the user interaction for Bluetooth when my apps is running.Is there any way to prevent the user interaction i.e when the user try to enable Bluetooth the app will block it.
Thanks in advance.
This is a small piece of code that needs to be written to disable/block bluetooth access. However, if you want to modify the functionality lagely, rooting is the solution. However, this post is already having relevance to the one noted ast : How to enable/disable bluetooth programmatically in android

Is there a way for automatic/programatic pairing of 2 bluetooth devices in android?

I am developing an application which connects devices over bluetooth and exchanges messages. It works fine for paired devices, but I would also like it to automatically pair devices that are not paired. Like for example it could store and use the same PIN for pairing requests, I just dont know how to manage this request programatically in my applciation, how to automatically set and send the PIN when you get a pairing request and how to initiate such a request with the predefined PIN code.
Any snippets or thoughts would be highly appreciated! :)
EDIT:
I know its risky, I am developing this app for emergency situations only where no other means but bluetooth is available. Also is there maybe a way of premature pairing with devices without even connecting to them? Like lets say there is a list of MAC Addresses of those devices and I can use them to generate a bond with that devices so that they appear paired on my device?
You can't do this. To do what you want to do would create a huge security risk. Think about it, my device just comes anywhere in bluetooth range of yours and now I can send you anything I want without you knowing? You can't really do this and I highly recommend not trying to subvert it.
Reflecting the setPin method allowed me to send the pin automatically to the other device. I had to implement it in a broadcast receiver that is listening for pairing requests. Although I cant get rid of the dialog it just stucks there on the screen and I dont know how to close it (programatically) and continue the bonding procedure since this dialog is called from inside connect() which is a blocking method. I am not giving up on it yet though :)
With Bluetooth version 2.1 and above there is a method of pairing called the 'just works' association model. This is the lowest security method of pairing and has no protection against man-in-the-middle attacks.
However, this will provide a secure, encrypted link without the need to exchange pin numbers or verify device ID.
The API on different platforms may differ but the underlying HCI messages require that you indicate that your device (or one of the devices) has the following IO capabilities:
No Keyboard, No Display.
As you might have guessed, this is a mode for very
simple devices that use Bluetooth, such as a speaker or headphones.
If you can find the API to configure that, then the 'just works' association mode of Secure Simple Pairing will be used for pairing.
The next step is to store the link keys e.g. bonding. Many devices e.g. mobile phones, will still create a dialogue box to the user to ask if they want to 'remember this device', as user authorisation is specified by the BT specifications... but that's another problem.

Android Phone-to-Phone Communications

This is more about an explanation then it is about asking a question. What I am wondering is if its possible to write an Android application that can communicate with another Android phone, given the phone number of the phone I want to communicate with. By communicate, I mean I want to be able to send data to the phone and have my application on the other phone be able to recive it.
If its not possible to do this, then I guess my alternative is to have my application "sign" the phone into a server. Then I'm assuming the server can act a proxy to communicate with both phones.
Any clarification would be helpful!
Check out the BUMP api. It allows you to establish a connection between two (I think more are also possible) devices, and it gives you a channel over which to communicate. The devices need to be "bumped" first, but then it's all fair game.
Any reason why it has to be by phone number? That and i'm pretty sure you can only send data over WAN or local bluetooth/wifi.
Perhaps try something along the lines of a server that has phones sign into it and keeps track of the phones IP addresses allowing them to communicate almost directly to another (kind of like a dynamic DNS hah!).
Look into SMS. I haven't coded for mobile phones in years but I seem to recall that most phone operating systems let an app intercept SMS messages, react to their contents, and prevent the user from seeing them.
As long as you're not sending lots of data, SMS might do the trick.

Categories

Resources