How to turn off/disable NFC programmataically? - android

How to write an application that turn off/disable NFC programmatically when I close my application or when my application is idle?

If you really have to turn NFC off, use NfcAdapter.disable();.
However, you won't be able to use disable() API if your app is not system application which is build together with the platform.
Alternatively, you may show a notice (a dialog?) to the user and ask her if she wants to turn off the NFC. If user agrees, you can redirect her to global Settings UI using following Intent:
startActivity(new Intent("android.settings.NFC_SETTINGS"));

Related

Android Device Owner Mode by App Signed with platform key (or use signed App for custom device policy)

I have application signed by platform key and I need to move device to kiosk mode.
What kiosk mode mean in my case:
Set user restrictions (change default activities, set VPN etc...)
Prevent user access to third party apps, some system apps etc...
Set custom Activity as Home activity without user interaction
Move application to lock task mode
I know that DevicePolicyManager could do that. But device doesn't have any google's provisioning system (like NFC or QR). Is exist any way to set device owner using application signed by platform key or use such application with benefits of device owner App?
I find out that application with system privileges could do al lot of thing that could be done with DevicePolicyManager. But some of functionality provided as hide API:
Set user restrictions - could be done with UserManager
Prevent user access to third party apps - could be done be disabling such apps with package manager
Set custom Activity as Home activity without user interaction - could be done with PackageManager
Move application to lock task mode - could be done by disabling UI components in status bar and system navigation bar with StatusBarService
The platform key only gives you certain permissions to take a certain role or to make some system settings, but for your task you are mainly right with the DevicePolicyManager. I do not see why you need NFC or QR for that, you could implement a simple code to unlock the kiosk mode.
There are of course finished applications to do that and you would not need to re-invent the wheel as this kind of application is not trivial.

Is it possible to have an app block other apps even if you restart device?

Is it possible to have an app block other apps even if you restart the device?
Android provides the ability to draw over other apps (Tutorial here). In combination with an accessibility service, you should be able to detect when a user attempts to interact with a particular application and draw over that app.
The user needs to enable the permission though, so you can't really "block" the app permanently.
Source: I wrote an application that uses an accessibility service to detect Japanese Kanji in tapped areas in other apps. The app then uses the "draw over other apps" permission to show an info panel about the parsed Kanji.

Detect when application is started via NFC in ICS

ICS introduces the possibility to share an application via Android Beam using NFC, and as far as I understood if an app is opened on deviceA it will automatically be started on deviceB (if it's already installed on it, otherwise the Market app will open) when the devices are close enough and a user "touches to beam" it. Is there a way, inside the launcher Activity, to detect if it has been started because of a NFC message or because of a user interaction?
Only NFC Intents are started when a beam occurs. These are ACTION_NDEF_DISCOVERED, ACTION_TECH_DISCOVERED, or ACTION_TAG_DISCOVERED. Check out the beaming section of the dev guide for how to handle beams: http://developer.android.com/guide/topics/nfc/nfc.html#p2p
In case the Android Beam (or NDEF) message contains an Android Application Record, http://developer.android.com/guide/topics/nfc/nfc.html#aar, the resulting Intent to start the app will not be of the action ACTION_NDEF_DISCOVERED, but ACTION_MAIN. This method can be used to launch any app, including apps that do not filter for NFC intents.

Android phone as a dedicated device

We want to use Android mobile for dedicated application. Can somebody suggest how can we make it happen.
Here are the requirement:
The phone when started, should launch our application., so the user cannot launch any other application. The application will be a 1D barcode reader.
The application should be live as long as the phone is up and running, user cannot close the application at all.
Thanks for your help.
Regards,
Manish
Android after boot is complete sends a bradcast intent:
android.intent.action.BOOT_COMPLETED
if you listen for this intent, you can launch a service that in turn launch your activity.
In the Activity you have to take care of the user's interactions that explicitly close the activity, like home button, back button and camera button press.
Setting your activity to be full-screen also should prevent the user to use the notification bar to interact with notification like those from market-app that can close your activity.
Finally, your activity can be killed by the system by various and uncatchable reasons: in those cases, the service that first launched your Activity comes in handy, as it can periodically monitor the general state of the application and relaunch components as needed.
Check out the new Android Enterprise solutions for your use case.
https://developers.google.com/android/work/overview
Its well documented. You can either use
Android Management API to provision the devices and apply policies to the device which will be applied to the device using Android's Device Policy Controller (DPC) or,
Use Google Play EMM API and develop your custom DPC
It depends upon your use-case really, but the first solution set should serve your purpose
I'm afraid there's no single answer to this, but you need to work on multiple fronts.
One of these fronts is preventing user from running other applications: for this there are applications sold on Android Market that can put other apps of your choosing behind passcode.
You need to combine this with automatic launch, but I don't yet know how to do that.

Want to add a startup notification Droid app

I am looking to add a Notification when the app is started. That will ask the user if they have a WiFi or unlimited connection. If they pick yes then they can go into the app, if no then the app closes with a message 'Try again later...'
To find out if wifi is available, you don't need to ask the user, you can ask the OS to give you that information using this method:
http://developer.android.com/reference/android/net/NetworkInfo.html#getTypeName%28%29
If you wish, you can also check if there is a connection using isConnected() and if you want to test if the connection is working, you could make a network call to confirm.
If you want to have the user confirm (I don't think you need to) then create an activity that runs when the app starts, it asks them to confirm, and then depending on their selection either starts the app's main activity, or shows a message and exits.
I don't know the details of your app, but if it were me I would probably:
- Automate the network detection
- If there's no network, run the app as usual, but just grey out and disable the main UI, and show a message like "Please connect to a Wifi network".
- Consider including a user interface within the app that the user can use to turn on wifi.
I think that's much tidier than just exiting the app, as that means if they get the "no wifi" warning the app assists them by providing an option to enable it.

Categories

Resources