gpt4 book ai didi

android - 需要在代码 list 中声明的​​权限

转载 作者:行者123 更新时间:2023-11-29 01:43:50 25 4
gpt4 key购买 nike

我需要知道需要在 list 文件中进行的更改以及运行此应用程序需要哪些权限而且我的目的是从网页中获取字符串并将其显示在“onPostExecute()”中

package com.example.guru;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;

import android.os.AsyncTask;
import android.util.Log;

//new code


class RequestTask extends AsyncTask<String, String, String>{

@Override
// username, password, message, mobile
protected String doInBackground(String... url) {
// constants
int timeoutSocket = 5000;
int timeoutConnection = 5000;

HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
HttpClient client = new DefaultHttpClient(httpParameters);

HttpGet httpget = new HttpGet(url[0]);

try {
HttpResponse getResponse = client.execute(httpget);
final int statusCode = getResponse.getStatusLine().getStatusCode();

if(statusCode != HttpStatus.SC_OK) {
Log.w("MyApp", "Download Error: " + statusCode + "| for URL: " + url);
return null;
}

String line = "";
StringBuilder total = new StringBuilder();

HttpEntity getResponseEntity = getResponse.getEntity();

BufferedReader reader = new BufferedReader(new InputStreamReader(getResponseEntity.getContent()));

while((line = reader.readLine()) != null) {
total.append(line);
}

line = total.toString();
return line;
} catch (Exception e) {
Log.w("MyApp", "Download Exception : " + e.toString());
}
return null;
}

@Override
protected void onPostExecute(String result) {
// do something with result

System.out.println(result);


}
}


//new code end

最佳答案

你需要添加

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

对 list 文件的许可

之后

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.photon.filnobep"
android:installLocation="auto"
android:versionCode="400"
android:versionName="4.0.0" >

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

或者从 GUI 添加

enter image description here

更新:1

将此添加到您的布局 xml 文件中

<TextView
android:id="@+id/textViewLike"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:maxLines="1"
android:textColor="#FFF"
android:textSize="7pt" />

以及您的 Activity 类中的以下内容

创建全局变量

TextView textVw = null;

onCreateView 中执行此操作

textVw = (TextView) findViewById(R.id.textViewLike);

然后这个

@Override
protected void onPostExecute(String result) {
// do something with result


textVw.setText(result);

}

关于android - 需要在代码 list 中声明的​​权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22734818/

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