What permission do I need to access Internet from an Android application?

前端 未结 13 1658
名媛妹妹
名媛妹妹 2020-11-22 03:50

I get the following Exception running my app:

java.net.SocketException: Permission denied (maybe missing INTERNET permission)

How do I solv

相关标签:
13条回答
  • 2020-11-22 04:17

    just put above line like below

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.avocats.activeavocats"
    android:versionCode="1"
    android:versionName="1.0" >
    
    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="16" />
    
     <uses-permission android:name="android.permission.INTERNET" />
    
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
    
    
        <activity
            android:name="com.example.exp.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    

    0 讨论(0)
  • 2020-11-22 04:17

    If you want using Internet in your app as well as check the network state i.e. Is app is connected to the internet then you have to use below code outside of the application tag.

    For Internet Permission:

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

    For Access network state:

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    

    Complete Code:

    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="16" />
    
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
    
    
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    
    0 讨论(0)
  • 2020-11-22 04:18

    In the latest release of Google Play, Google removed the need to ask permission for internet as "most apps need it anyways nowadays". However, for users who have older versions, it is still recommended to leave the code below in your manifest

    <uses-permission android:name="android.permission.INTERNET" /> 
    
    0 讨论(0)
  • 2020-11-22 04:21

    Just Add these 2 permissions

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

    in your app's AndroidManifest.xml

        <?xml version="1.0" encoding="utf-8"?>
        <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="com.example.android.networkusage"
            ...>
        
        
            <uses-permission android:name="android.permission.INTERNET" />
            <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        
            <application 
                ...>
                ...
            </application>
        </manifest>
    

    Happy Coding:)

    0 讨论(0)
  • 2020-11-22 04:22

    Just put below code in AndroidManifest :

    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    
    0 讨论(0)
  • 2020-11-22 04:28

    To request for internet permission in your code you must add these to your AndroidManifest.xml file

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

    For more detail explanation goto https://developer.android.com/training/basics/network-ops/connecting

    0 讨论(0)
提交回复
热议问题