作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
迁移到 AndroidX 后,此代码已停止工作。在迁移到 AndroidX 之前,此代码可以正常工作。
错误:
2020-02-24 09:41:17.918 17888-17921/edmt.dev.androidgridlayout E/eglCodecCommon: GoldfishAddressSpaceHostMemoryAllocator: ioctl_ping 因 device_type=5 失败,ret=-1
BackgroundTask.java:
package edmt.dev.androidgridlayout;
import android.content.Context;
import android.os.AsyncTask;
import android.view.View;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import javax.net.ssl.HttpsURLConnection;
public class BackgroundTask extends AsyncTask<String,String,String> {
Context ctx;
BackgroundTask(Context ctx)
{
this.ctx=ctx;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(String result) {
Toast.makeText(ctx,result,Toast.LENGTH_LONG).show();
}
@Override
protected String doInBackground(String... params) {
// String url="http://192.168.42.159/kamakshi/addproduct.php?name="+name+"&quantity="+quantity;
String url="http://10.0.2.2/kamakshi/addproduct.php";
String method = params[0];
if (method.equals("addproduct"))
{
String name=params[1];
String quantity=params[2];
String cp=params[3];
String sp=params[4];
String etseller=params[5];
String seller=params[6];
String brand=params[7];
String colour=params[8];
String fabric=params[9];
String size=params[10];
String type=params[11];
// String gender=params[12];
System.out.println(method+"omkar"+name+"......"+quantity+" "+cp+" "+sp+" "+etseller+" "+seller+" "+brand+" "+colour+" "+fabric+" "+size);
try{
URL url1 = new URL(url);
HttpURLConnection httpsURLConnection = (HttpURLConnection)url1.openConnection();
if(httpsURLConnection!=null)
{
System.out.println("connn established");
}
else
{
System.out.println("connn failed");
}
System.out.println("connn established");
httpsURLConnection.setRequestMethod("POST");
httpsURLConnection.setDoOutput(true);
OutputStream os=httpsURLConnection.getOutputStream();
BufferedWriter bufferedWriter=new BufferedWriter(new OutputStreamWriter(os,"UTF-8"));
String data= URLEncoder.encode("name","UTF-8")+"="+URLEncoder.encode(name,"UTF-8")+"&"+
URLEncoder.encode("cp","UTF-8")+"="+URLEncoder.encode(cp,"UTF-8")+"&"+
URLEncoder.encode("sp","UTF-8")+"="+URLEncoder.encode(sp,"UTF-8")+"&"+
URLEncoder.encode("etseller","UTF-8")+"="+URLEncoder.encode(etseller,"UTF-8")+"&"+
URLEncoder.encode("seller","UTF-8")+"="+URLEncoder.encode(seller,"UTF-8")+"&"+
URLEncoder.encode("brand","UTF-8")+"="+URLEncoder.encode(brand,"UTF-8")+"&"+
URLEncoder.encode("colour","UTF-8")+"="+URLEncoder.encode(colour,"UTF-8")+"&"+
URLEncoder.encode("fabric","UTF-8")+"="+URLEncoder.encode(fabric,"UTF-8")+"&"+
URLEncoder.encode("size","UTF-8")+"="+URLEncoder.encode(size,"UTF-8")+"&"+
URLEncoder.encode("type","UTF-8")+"="+URLEncoder.encode(type,"UTF-8")+"&"+
// URLEncoder.encode("gender","UTF-8")+"="+URLEncoder.encode(gender,"UTF-8")+"&"+
URLEncoder.encode("quantity","UTF-8")+"="+URLEncoder.encode(quantity,"UTF-8");
bufferedWriter.write(data);
bufferedWriter.flush();
bufferedWriter.close();
os.close();
InputStream IS= httpsURLConnection.getInputStream();
BufferedReader br=new BufferedReader(new InputStreamReader(IS,"iso-8859-1"));
br.close();
IS.close();
httpsURLConnection.disconnect();
}catch (Exception e)
{
e.printStackTrace();
}
}
return url;
}
}
AndroidManifest.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edmt.dev.androidgridlayout">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".scandemo"></activity>
<activity android:name=".Scanner" />
<activity android:name=".ProductTable" />
<activity android:name=".ProductView" />
<activity android:name=".addproduct" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ActivityOne" />
</application>
</manifest>
最佳答案
在 list 文件的应用程序标记下添加此行 - android:usesCleartextTraffic="true"
。
我已使用所需的语句更新了您的 list 文件的代码。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edmt.dev.androidgridlayout">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/AppTheme">
<activity android:name=".scandemo"></activity>
<activity android:name=".Scanner" />
<activity android:name=".ProductTable" />
<activity android:name=".ProductView" />
<activity android:name=".addproduct" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ActivityOne" />
</application>
</manifest>
关于java - 金鱼地址空间主机内存分配器 : ioctl_ping failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60369614/
我是一名优秀的程序员,十分优秀!