I am creating an Android app that communicates with a NFC Reader using HCE feature.
The scenario is, when app receives a command, the processCommandApdu method will be called and will start an activity. In that activity there is an EditText and a button. User can enter some text, then clicks the button and the text will be sent to the NFC Reader.
I can start activity from the service, but what I don't understand is how I can return back the entered text to HostApduService to send it to the NFC Reader.
Is there any good way to do this? for example, saving the entered text in an application variable (or database) in the activity, finishing activity, then read the variable in the service and return it to the NFC Reader. Do I need some waiting techniques in the service if using this way? Or is there any better solution?Thanks.
It seems like that you want to do something with publish and subscribe pattern.
EventBus is a library that can help you to post data between classes when it's ready for use.
You may also want to read about this tutorial first to see if that meet your needs.
Related
I am using GCM to send push notifications to my Android application and when the user clicks the notification, they should be taken to a specified view in the application (For context: It's an event log).
I understand that in the simplest case, I just add some parameters to the intent that is starting the app.
However, my app requires some remote data to be available when entering my MainActivity. When starting the application normally, it's pointing to another activity, let's call it AppStartActivity. It's showing a Splash screen while downloading the neccessary data and launches MainActivity when it's ready.
When starting the app from a notification, the neccessary data may or may not be ready, depending on whether the app is currently in background (and if it has not been garbage collected). Therefore, I think I have to launch AppStartActivity when clicking the notification, and then somehow forward the Intent parameters and I'm not sure it's the right way. I have formulated some questions about this:
Is it correct to lauch AppStartActivity with the parameters I will need in MainActivity later and then just forward them when switching to MainActivity?
Is there a simpler way to do this, such as finding out the state of the application when clicking the notification and then choose either AppStartActivity or MainActivity depending on if the neccessary data is available? The reason I'm asking is that when I create the notification, the data may or may not be available, but it may change during the time passing before the user to interact with the notification. I understand that I can launch a new activity that is just checking the state and then launch either MainActivity or AppStartAcitivty, but it seems like it could be a bit too complicated...
I'm thankful for any input on this matter. Please let me know if I have left out some details.
as I understand it, I had a similar situation, and this was my solution:
when I receive the GCM, my onReceive method starts a service
for getting the remote datas. Only when these datas are
avaiable in a local content provider, I throw the notification to the user.
[edit]
You have to manage any network error with some notice, otherwise you may lose the GCM notification
I want to make an android service that would let me simulate keypress to fill fields on a web page when receiving an intent. Is this possible in any way or maybe through a different process (Not by simulation keypress?).
For example an example of what I would want to be able to do.
The user is on his tablet and has selected a field on a web page. For any bluetooth device discovered, fill the field with that id.
IS there a way to do it by calling an intent of the web browser or something like that?
Thanks
EDIT : figured my example was pretty bad.
Here is what I really want to do
When a nfc tag is detected on the phone,
read the nfc tag ID,
simulate keypress events of the id tag on whatever the focus is at the moment on the phone
Example : I'm on google focused on the search field and I put a nfc tag on the phone, the phone types the Nfc tag id on the google search field and voila
if you really want to simulate keyevents, you can use system calls:
input keyevent <keycode>
I would advice you to use BroadCast receiver. You have to create a Custom intent class after that, register the receiver when the user select a field. For interaction with web page, its better to use javascript to call native android method.
When you detect a device send your broadcast, if you are registered, you will handle the event.
I am planning to write a service to enable Android users to listen to any text is currently displayed (be an email, an ebook, a web page, a note, an SMS, etc...), upon request.
Do you think it is feasible?
Do you know if it has been done, already?
How could I bind (a button? a gesture? something else?) a user input to the service activation?
I know these are quite generic questions, but I'm really on a pre-alpha stage for my project, I want to understand if it's feasible, to start with... :-)
For example you can use google translate service for doing your own tts, you need to do a httpConnection with the text that you need to listen
I've successfully being able to use the ACTION_SEND intent which displays my application in the list when the share button is pressed in the gallery. My app basically sends the selected picture to my computer and no further input form the user is required. Rather than starting my app when selected in the list which is an unnecessary step is it possible to pass the data to my own service which sends the picture and avoid starting my app?
If not what other options do I have? Start my app, sent the picture and close the activity?
Rather than starting my app when selected in the list which is an unnecessary step is it possible to pass the data to my own service which sends the picture and avoid starting my app?
ACTION_SEND is used for starting activities, not services -- sorry.
If not what other options do I have? Start my app, sent the picture and close the activity?
Sounds reasonable. If you do all of that in onCreate(), call finish(), and never call setContentView(), nothing will be shown to the user.
I have an app that creates a new data entry in a sqlite db with several columns. I would like to have a simple share button on the final activity so they can share the results (or even a simple text field) with apps that accept it (email, mms, twitter, etc..).
I did some reading on ContentProviders but the more I read, the more I'm thinking i'm heading down the wrong path. Any help is appreciated.
Thanks!
I think what you are looking for is an Intent. Android applications have two major components: Activities and Intents. Activities are processes that do a particular action, like a ListView, or a process that sets and listens in the background for something to happen. An Intent is a message between those actions. It's how processes communicate in Android. Intents can be specific, and tell a particular Activity to perform an action on some data, OR you it can attempt to perform some action (like open in browser) by any available "browser" application that can perform that action.
Here are some links to the documentation to get you started:
android.content.Intent
Intents and Intent Resolution
Hope that helps!
You have to tie the app to a web service and put the data up in the cloud.