Android TCP permission denied error

This is my code:

public void update(){
   try {
        Socket appSoc = new Socket( "XXX.XXX.XXX.X" ,XXXXX);
        BufferedReader in = new BufferedReader(new
        InputStreamReader(appSoc.getInputStream()));
        for (int i = 0; i < 100; i++) {
            String message = in.readLine();
            add(message);}

    }
    catch (Exception e) {
        add("ERROR" + e);
    }
}

Add (string text) adds text to textview so that I can be lazy

Anyway, I have been denied permission, but if I use the actual domain name instead of the IP address, it says it can't find the domain name. This is an Android problem because it works normally on Java on my computer

resolvent:

You may have missed the Internet delay in the manifest. Make sure it is outside the application tag, as follows:

<manifest>
    <application>
     .
     .
     .
    </application>
    <uses-permission android:name="android.permission.INTERNET" />
</manifest>

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>