SDK 6.0及以上需要动态申请,找资料学习一下吧
这web和h5一样吗
我大大
public static Bitmap loadImage(String sendUrl) { try { URL url = new URL(sendUrl); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); conn.setReadTimeout(5000); conn.setRequestMethod("GET"); InputStream stream = conn.getInputStream(); String fileName = System.currentTimeMillis()+".jpg"; FileOutputStream outputStream = null; File fileDownload = null; if (Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED)) { File parent = Environment.getExternalStorageDirectory(); fileDownload = new File(parent, fileName); outputStream = new FileOutputStream(fileDownload); } byte[] bytes = new byte[2 * 1024]; int lens; if (outputStream != null) { while ((lens = stream.read(bytes)) != -1) { outputStream.write(bytes, 0, lens); } return BitmapFactory.decodeFile(fileDownload.getAbsolutePath()); } else { return null; } } catch (MalformedURLException e) { //这个URL能不能被解析成URL e.printStackTrace(); Log.e("aa", "异常 MalformedURLException=" + e); return null; } catch (IOException e) { e.printStackTrace(); Log.e("aa", "异常 IOException=" + e); return null; } }
看看图片地址是不是https的,是的话该用HttpsUrlConnection , 或者换个http的图片
https://github.com/nickgao1986/cardproject1
处理方式
在return的时候会有这样的错误:SkImageDecoder::Factory returned null
你这是编译报错了吧,返回值对吗
Android 5.0以上,除了在 AndroidManifest.xml 中加 读写权限外
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
还需要在代码中增加手动增加权限申请的代码:
public static void verifyStoragePerssion(Activity activity){ int writePerssion = ActivityCompat.checkSelfPermission(activity,Manifest.permission.WRITE_EXTERNAL_STORAGE); int readPerssion = ActivityCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE); if(writePerssion != PackageManager.PERMISSION_GRANTED || readPerssion != PackageManager.PERMISSION_GRANTED){ ActivityCompat.requestPermissions(activity, PERMISSIONS_STORGE, REQUEST_EXTERNAL_STORAGE); } }
其中 REQUEST_EXTERNAL_STORAGE 和 PERMISSIONS_STORGE 定义如下:
private static final int REQUEST_EXTERNAL_STORAGE = 1;
private static String[] PERMISSIONS_STORGE = { Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE };
把http改成https试试。
actual 0xd532e53b != expected 0xebc651df 实际的内存地址与预期的内存地址不一致,你代码应该写的有问题
调用这个API:void loadDataWithBaseURL (String baseUrl, String data, String mimeType, String encoding, String historyUrl) 即可, 视频中的public void loadData (String data, String mimeType, String encoding)这个API,根据官方文档说明,数据里如果带有"#","%","\","?"这四个特殊字符用 %23, %25, %27, %3f代替
你参考一下源码中的HttpUtil,https://github.com/nickgao1986/httpTest,应该是return的原因,如果函数声明有返回值,
https://github.com/nickgao1986/httpTest
对书本信息的 增删改查
需要单独去学习后端的知识
秀儿是你吗,你是真的秀啊老铁
可是我的换了之后,运行也还是显示不出来,这是什么原因???