gpt4 book ai didi

android - 如何解决权限被拒绝可能缺少互联网权限?

转载 作者:太空狗 更新时间:2023-10-29 16:21:42 25 4
gpt4 key购买 nike

我正在使用 Netbeans7.2 并输入了 uses-permission 但我有这个错误 Java.net.Socket Exception Internet denied(Maybe missing internet permission)`我的 AndroidManifest 文件是这样的

  <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="importacao.dados"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name" >
<activity android:name="importacao"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<uses-permission android:name="android.permission.INTERNET" />
</intent-filter>
</activity>
</application>
</manifest>

//按钮

cliente.setOnClickListener(new  Button.OnClickListener(){
public void onClick(View view){
InputStream is = null;
ArrayList namevaluePairs = new ArrayList();
List r = new ArrayList();
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost;
httppost = new HttpPost("http://localhost/cliente.php");
httppost.setEntity(new UrlEncodedFormEntity(namevaluePairs));
HttpResponse response;
response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}
catch(Exception e)
{
Toast.makeText(getBaseContext(),e.toString(),Toast.LENGTH_LONG).show();
}
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"));
StringBuilder sb = new StringBuilder();
String line = null;
while((line=reader.readLine()) != null)
{
//
}}
catch(Exception e)
{
Log.e("Erro",e.toString());
}}});

最佳答案

将您的 uses-permission 标签移到 application 标签之外。您可能还需要为 android.permission.ACCESS_NETWORK_STATE 添加一个使用权限,不确定 netbeans 是如何工作的。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="importacao.dados"
android:versionCode="1"
android:versionName="1.0">

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

<application android:label="@string/app_name" >

关于android - 如何解决权限被拒绝可能缺少互联网权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12922365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com