NOTE: I wrote this answer in June 2013, so it is a bit outdated. Since then, some changes in Android have changed from version 6 (Marshmallow) of the platform, which makes the whole problem more / less outdated. However, I think this post is still worth reading as an example of a general analysis of problems, so I hope you can still find it educational.
The exception you receive ( SecurityException: Permission denied (missing INTERNET permission?) ) Clearly indicates that you are prohibited from working on the network. This is a pretty indisputable fact. But how can this happen? Usually this happens either due to the lack of the <uses-permission android:name="android.permission.INTERNET"/> entry in the AndroidManifest.xml file or due to the fact that permission to access the Internet is granted during installation not at runtime due to a long missed error. in the Android platform, which leads to a successful installation of the application, but without the expected permission.
My manifest is correct, so how can this happen?
Theoretically, the presence of uses-permission in Manifest is fully consistent with the requirement, and from the point of view of the developer, this was all that had to be done to be able to create networks. Moreover, since permissions are displayed to the user during installation, the fact that your application was installed on the user device means that he / she provided what you requested (otherwise the installation is canceled), therefore it is assumed that if your code is executed, then all requested permissions granted are valid. And, having received permission, the user can’t withdraw permission in any other way than completely uninstalling the application, since the standard Android platform (from AOSP) does not offer this option at the moment.
But things get more complicated if you are also not opposed to having your application run on rooted devices. There are tools available on Google Play that users can set to manage permissions granted to installed applications at runtime, such as " Access Denied" and others. This can also be done using CyanogenMod , the manufacturer’s brand (for example, LG) or another custom ROM with various types of “privacy managers” or similar tools.
Thus, if the application is blocked in any case, it is mainly blocked intentionally by the user, and if so, then this is really a big problem for the user in this case (or he / she does not understand what certain options / tools actually do and what they will be consequences) than yours, because the standard SDK (and most applications are written with this SDK in mind) just doesn't behave like that. Therefore, I strongly doubt that this problem occurs on a "standard", non-root device with a standard ROM (or a manufacturer such as Samsung, HTC, Sony, etc.).
I don't want to crash ...
Properly implemented permission management and / or blocking the organizing committee should take into account the fact that most applications may not be prepared for a situation where access to certain functions is simultaneously provided and unavailable, since this is a kind of contradiction when the application uses a manifest to request access during installation. Proper access control should make everything work the same as before, but still limit usability using methods within the expected behavior of the function. For example, when a certain permission is provided (for example, GPS, Internet access), such a function can be made available from the point of view of the application / user (that is, you can turn on the GPS or try to connect), the modified implementation cannot provide real data - i.e. . GPS can always return coordinates, for example, when you are in a room or you don’t have a “fix” satellite. Internet access can be provided, as before, but you cannot establish a successful connection, as there is no data coverage or routing. Such scenarios should be expected in normal use, so they should be handled by applications. Since this can happen during normal daily use, any failure in this situation should most likely be due to application errors.
We lack too much information about the environment in which this problem occurs to diagnose the problem without speculation, but as a solution, you can consider using setDefaultUncaughtExceptionHandler () to catch such unexpected exceptions in the future and that is, just show the user detailed information about what permissions your application needs not only to crash. Note that using this will most likely conflict with tools like Crittercism, ACRA, and others, so be careful if you use any of them.
Notes
Remember that android.permission.INTERNET is not the only network-related permission that you may need to declare in a manifest in order to successfully create a network. Granting INTERNET permission simply allows applications to open network sockets (which is a basic requirement for any data transfer over the network). But in case your network stack / library also wants to get information about networks, you will also need android.permission.ACCESS_NETWORK_STATE in your manifest (which is required by the HttpUrlConnection client ( see the Guide ).
Application (2015-07-16)
Please note that Android 6 (aka Marshmallow) has a completely new permission management mechanism called Runtime Permissions . This gives the user more control over which permissions are granted (selective granting also allows) or allows you to revoke already granted permissions without having to uninstall the application:
This [...] introduces a new permissions model where users can now directly control application permissions at runtime. This model provides users with enhanced visibility and permission control, streamlining installation and automatic updates for application developers. Users can grant or revoke permissions separately for installed applications.
However, these changes do not affect the INTERNET or ACCESS_NETWORK_STATE , which are considered " ACCESS_NETWORK_STATE " permissions. The user should not explicitly grant these permissions.
See the Behavioral Change Description page for more information and make sure your application runs correctly on new systems as well. This is especially important when your project has targetSdk set to at least 23 as you must support the new permissions model ( detailed documentation ). If you are not ready, make sure that the value for targetSdk is no more than 22 because this ensures that even the new Android will use the old permission system when installing your application.