0

I am using NanoHttpd to create a WebServer on the device (I may want to use it only for my Application or allow other applications to use it).

But I am having to provide permission INTERNET.

I have created an application that does this and it works only when I provide android.permission.INTERNET in the manifest.

My code actually works, but when I don't provide INTERNET permission I am getting exception in logcat:

 Caused by: java.net.SocketException: socket failed: EACCES (Permission denied)
    at java.net.ServerSocket.createImpl(ServerSocket.java:308)
    at java.net.ServerSocket.getImpl(ServerSocket.java:258)
    at java.net.ServerSocket.setReuseAddress(ServerSocket.java:716)
    at fi.iki.elonen.NanoHTTPD.start(NanoHTTPD.java:2319)
    at cc.siara.android.NanoHttpServer.<init>(NanoHttpServer.kt:16)
    at cc.siara.android.App.onCreate(App.kt:23)

I don't want to provide Internet permission because I want to assure user about the privacy my application provides.

All I want to access is http://127.0.0.1:<port>. Is it possible?

Arundale Ramanathan
  • 1,781
  • 1
  • 18
  • 25

1 Answers1

1

No, you need the INTERNET permission to use network sockets, whether for a server or a client, and even for the localhost. As it is a normal permission you don't have to ask for it, and the user can not deny it.

If the server is an optional feature, you can declare the permission in another APK sharing a sharedUserId attribute with your application, so that only users interested in this feature install the second (empty) APK

bwt
  • 17,292
  • 1
  • 42
  • 60
  • Thanks for the answer and the tip about sharedUserId (https://stackoverflow.com/questions/9783765/what-is-shareduserid-in-android-and-how-is-it-used). – Arundale Ramanathan Jan 17 '19 at 12:09