Android How to tell if Internet connection is being used? - android

My app download a lot of content (json and image) from the server as the user navigate through the app. For the sake of user experience, instead of downloading the content on the spot, I would like to precache them on memory and SD card so that they can be available without too much waiting.
Since I do not want the precacheing process take up too much network traffic so that the user operation is hindered by the network traffic jam, I would only let the app start precacheing these content when there are not any Internet activity from my app.
Therefore, I would like to ask if there are any way to determine whether there are any internet activity from my app.
Thank you.

The user's experience of not being about to use the app when it is first opened because there are other downloads sounds like it would hinder a user. Warning the user about the amount of data could be another solution. At the warning screen (On first open) the user could be directed into the settings where they could setup the network. This allows the user to customize if needed, otherwise they continue with a smooth transition into the app.
The network settings could be setup with ConnectivityManager. This would allow you to see if the user is on Wifi vs mobile data.
http://developer.android.com/training/monitoring-device-state/connectivity-monitoring.html
The DDMS tool includes a tool for monitoring network traffic. This could be an option.
http://developer.android.com/tools/debugging/ddms.html

Related

Change default activity after activation

I currently have three activities for my Android app, two of these are for logging in. The first is used for authorizing a device and requires the user to input more user information (FullLogin), the second is used once a device has been authorized (ReducedLogin).
The idea is to show the FullLogin activity all new users until their device has been authorized. The ReducedLogin activity will then show for all logins thereafter.
Is this possible and how would I go about doing this? I've seen some posts online for using/accessing values from a preferences.xml file but am not 100% sure if this is correct for my needs.
This scenario is formulated quite generally. There exist many possible solutions.
You could save the information whether a user is fully authorized on an external server and each time you start the app, you request the server and then show the corresponding activity.
You could store this information locally on the smartphone (e.g. in SharedPreferences), but for security reasons i would rather recommend the first way. One big advantage of local storage may be the avoidance of the additional internet permission as you don't have to request a server.
You could use cryptography to create a challenge that can only be solved by an authorized user.
You could combine these approaches.
You can't modify the manifest, and that's what's going to control what runs when the user presses your launcher icon.
What you can do is have a "router" Activity that inspects the state of the system and starts the real Activity you want. You do have to put in some extra effort here to ensure you don't get a screen flash between the router and real activity (starting with no animation, not setting a content view in the router, using a blank theme, and probably other things).
Another solution is to use fragments. The "main" activity just inspects the state and adds the correct fragment ... full or reduced.

Why does one app launch faster than the other?

I'm curious about this. I have an app called GoSMS PRO and an app called Contacts+ installed in my phone. They both popup an alert notification when a text message is received. However, GOSMS PRO always beats Contacts+'s popup. I was wondering how this was happening in a programming perspective? Is there a way to give a certain app more preference than the other.
From security and permission side every app from Google Play has similar privilege, if they are not signed by the certificate of device manufacturer. This also means that none of the app will get extra preference.
Some time app do many type of checking/initialization/loading before showing their UI and when this type of things happens apps take longer period to load or display UI.
Most common things people do
Creating and initializing database
Reading database.
User validation (reading file)
Device state scanning(network)
Most common case is database access. I wonder if the app reading Content Provider before showing UI it might take long time depending on your device hardware and number of contacts.
Key strategy would be showing the UI right way and load data in background. Android has lots of Asynchronous api, just to avoid this type of scenario.

Request for permission to access location trough SMS?

I'm trying to figure out how to request another Android device for permission to access its location. Maybe through some link on a SMS to launch Google latitude?
The point is it should be instantaneous, like a Notification or an SMS.
What would be the closest strategy you can think of?
UPDATE:
Thanks guys for all your answers. After considering them all I am still a bit confused about what strategy to adopt.
Probably is better to tell you what I'm trying to implement:
Someone is going to pick you up. You send him a request, he accepts and the app shows you how far away he is and how long it will take him to get to you.
I didn't want the receiver to be forced to have the app cause it would lower its use. I guess that requisite could be dismissed.
Sorry for the confussion.
If you don't want the receiving user to have to install an app, you could send an SMS with a link to a website you control that uses web geolocation APIs to report position: http://dev.w3.org/geo/api/spec-source.html
The user will need to click the link in the SMS, then they will be prompted to allow the page to access their location. This will work not only on Android devices, but on any device with a browser that supports these APIs
It depends on how heavy duty your apps are.
If I were you I would write a system where the Apps would maintain a connection to a central server. That way your Apps can be notified the moment that anything happens. It could also be seamlessly integrated allowing your App (make sure you ask permission to allow it initially obviously) to send location data when requested without any interaction.
This is obviously more battery intensive for such a simple operation, but that is the best way to get instantaneous notifications.
Another way you could do it is to simply send an email to the recipient with a custom URL scheme.
Such as:
yourlocationapp://get.location/respond.to
You could parse that kind of URL in your App by setting:
<data android:scheme="yourlocationapp" />
In your intent-filter.
This requires more in the way of user interaction though.

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.

Is there any way to prevent an Android app from being removed?

Does anyone know if there's a way to either keep the user from uninstalling an app from an Android phone or reinstall it on removal? Before you flame me, please know that I have an app that's intended to be installed on the phone by a parent/employer/etc. and has a password-protected settings screen; the user would need to enter the password to remove the app.
What if you have it send an email alert to a registered email address on uninstall?
On the topic of email notification when your service is uninstalled--
A lot of security software runs multiple processes which monitor each other, so that it's more difficult to shut the system down. You could do something similar with two services installed, each monitoring to see if the other is installed. If something goes wrong, they can send off the e-mail.
Not without modifying the kernel, or reducing the user priviledges on the device. Think of it as a Linux computer, where the cell phone user has root.
Can you prevent them from removing your app? No.
But you can make it painful and difficult enough that it's not worth it, and include alerts that indicate it has been removed.
First, I would modify the software so it requests and successfully answers a cryptographic challenge/response periodically from a remote server - daily should be enough, and wouldn't impact battery use. This way your server knows when it has been disabled (could be sold as an additional $10/yr service charge) and you can alert the purchaser.
Second, I would tie the software into the system at the driver level so that removal also removes text services. There are drivers or services that the texting application uses that could be replaced with your custom versions, and on removal would render the texting app useless. Chances are good that you already tie into the system in a similar way to block the texting app (and other apps) while traveling too fast.
Third, I would consider installing a monitoring program that runs as a separate process (check out how the latest viruses operate for clues). It would check to make sure that not only is the app still running, but it's running the latest version, and there isn't a GPS simulator or other program that prevents your app from getting correct GPS data.
I'm curious how you differentiate between the driver texting and a friend in the passenger seat texting on the driver's cell, though.
-Adam
Well, solution would be to mount /system/apps/ to be writable and put your app there once.
When you restart the phone it would automaticly install it and prevent a user from uninstalling (as every app in that folder, list it to see it). That's how mobile providers force user to have they app.
However, user could always delete this app by rooting + mounting /system/app/ to writable and then to delete. But "normal parents" can't do that :)
Regards
P.S. This question is two years old, I've notice it just now... :S
I'd highly doubt that's possible. The permission structure of Android is going to give the user full control over what's happening on their phone (to some degree) and not being able to uninstall an app would be a pretty large security risk.
If you modified the Android core, it would probably be possible, but if you're trying to force something onto an end-user, that's a bad idea.
Maybe there's a better approach to what you're doing? If there's some required functionality in the app to keep the user from uninstalling it, that would be a small incentive to keep the app, but there's no way to keep a user from removing something they really don't want. You could have the app report uptime to a seperate server so you could be notified if the app was removed, but I think that's as far as you're going to get.

Categories

Resources