I'm currently building an application for Android using NFC-technology. The NFC-part is being used to log in to the app. So here's the deal: i want the app to respond differently when detecting the tag when it is already running. Here are the two situations:
1) When the user scans a tag with a specific URI, the app launches, loading the URI into the username-textfield. User then enters his password, presses login, and voila, magic. This part works fine.
2) Now, i also want the app to be launched from the app-list, showing a login form. No problem, i use a different activity for that. But now, how do i make some sort of custom Event Listener that makes the app wait for the tag to be scanned, and then puts the URI into the username-field without, and here it comes, launching the app again, as described in situation 1?
Hope you guys can help me out here, sorry for the long text.
Use foreground mode for your open activity and it will be able to receieve all NDEF messages (from tag or beam). Check boilerplate project in this project (shameless plug).
Your application itself simply needs to be aware of it's own current state and respond to the scanned tag accordingly
Related
Is it possible for an app to get launched from code even if user has not opened once after installing.
I have tried boot complete listener , package install/ uninstall receiver.
But even these receivers are not working when user has not opened the app at all. I am asking to just check if some one else in the community has tried this before.
The answer is: no.
If the user has never opened your application before, it is not possible to start the application.
On some devices though, it is possible that another second application under your control could possibly start your application, although it has never been opened before by the user.
If you do not have a second application on the device, the answer is no.
Context:
I have a Xamarin app (using Xamarin.Forms)
Issue is with Android version only.
There is a reset password form.
That form sends a request to a server, which issues an SMS with a code.
The app automatically displays the verification code form, by pushing a new view on the stack.
The user then checks code in the SMS app, switchesback to my app, and enters the code.
Problem:
Some times the flow above works fine.
Other times, when the user switches back to my app from the SMS, the app reverts back to the root navigation page.
Notes:
I am having trouble identifying the root cause. I suspect that it is due to page activity lifecycle, and that in the scenarios when it doesn't work, the OS has deallocated resources from my app, thus reloads it.
Please see diagram attached.
Questions:
Is anybody able to suggest a way to debug this so I know for sure
what is the root cause?
Is anybody able to suggest a way to handle app switching in Xamarin
Android so that state is maintained?
The issue I'm trying to solve is as follows:
An NFC tag will trigger my app, from which I'm launching another app. What sometimes will happen is that the NFC tag will move and will be "re discovered" by the phone and launch my app once again. The moving of the NFC tag is something I can't control.
This really ruins the experience.
What I would ideally like to do is once my app is launched, NFC triggering will be disabled or paused, and once app is closed (OnDestroy()) I will enable / un-pause NFC functionality.
I couldn't find how this could be done and your help would be really appreciated. If you have another (code related) approach on how this can be solved, this is just as good.
I noticed this post from a couple years back : NFC disable adapter
But I hope there is another solution, being a system application is not an option and prompting the user the disable NFC is just as bad...
Thanks in advance.
You can create an activity-alias that handles the intent, disable it while your activity is running and re-enable it when it is destroyed.
You're assuming that you can saftely turn off an important functionality of the phone, and disable any other service and/or app that is dependant on it.
This is of course wrong. You should only make assumptions regarding your own app.
So what you're really trying to do is to disable the re-launch. This can be done in many ways:
Control your main Activity's launch mode, and thus your entire app's.
Handle the NFC intent correctly, via a Service that monitors the NFC state as well as your app's. As per #Michael's remark - since you can only associate an NFC intent with an Activity - you would have to create a non-ui Activity (one that does not call setContentView) to act as a BroadcastListener for this Service.
Tag your app, as suggested by #Tristan.
I am makin an android application on Emergency communication.I want my application should run all the time and whenever it needs it should be able to run.I want that user should not be able to close it by any means.Like Google Maps application which is restarted again on killing its all activities and even we force close it,it will be restarted.
Seems you are learning app development ... but this is not the way you should pose question here... you should post what you have done and code issues and not ask for an entire class...
But i will try to answer your question are you trying to create an app which when started wont be able to be closed and come back to home screen ???!!!!!
See you are creating an app which will run on android operating system which is similar to linux so you must follow the Activity
LifeCycle
I remember i created an app where there were shortcuts on screen so using that i was directing the user to specific links but you can use for calling etc.. i donno if that is what you are searching for...
You might create a notification bar if you want which cannot be cancelled and you can place the code in the intent which will be called from this...
Also services are there which u can utilized what other users have suggested...
thx
You could use an extra service running in the foreground, but there will be always a notification of this service in the notification bar.
See here: http://developer.android.com/guide/components/services.html#Foreground
I'm writing a handful of NFC-capable apps for work.
I've got two of them on my tablet right now, and they are set to launch if an NFC tag is detected and they're not already open. So since I have two of them on the same device now I get an App Picker dialog. This is great.
What I would like is to make it so that if one of the apps is already open, that when the NFC tag is detected it doesn't show the app picker, but just uses the current activity to handle the NFC intent. How possible is this? Thanks
If the foreground activity is using enableForegroundDispatch(), it will take precedence over anything else registered in the manifest for the tag.
Here is a sample app that demonstrates the use of enableForegroundDispatch(), to write text shared from another app (e.g., URL from the Browser) to an NFC tag.