当前位置: 首页 > 知识库问答 >
问题:

滑动不加载某些图像URL

轩辕翰
2023-03-14

图像加载:

   Glide.with(context)
            .load(bannerImageModel.getOutput().get(position).getBanner_img())
            .apply(new RequestOptions().
            diskCacheStrategy(DiskCacheStrategy.ALL))
            .into(view);

链接1:https://freshtocook.in/uploads/banner/47a16ffc2fc5935dccd37574083c6201.jpg

链接2:https://freshtocook.in/uploads/banner/7eecf823e008a0bb93f347d994b6e534.jpg

共有1个答案

晏卓君
2023-03-14

您需要从源域下载证书。只需打开SSL证书并将图像拖放到android项目的raw目录中。重命名并删除扩展名和‘。“句号。

我的依赖项如下所示

dependencies {
    implementation fileTree( dir: 'libs', include: ['*.jar'] )

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
     testImplementation 'junit:junit:4.12'
     androidTestImplementation 'androidx.test.ext:junit:1.1.1'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    // https://mvnrepository.com/artifact/com.koushikdutta.ion/ion
    implementation group: 'com.koushikdutta.ion', name: 'ion', version: '2.2.0'



}

我使用的是ION2.2.0,可以很好地处理不工作的图像。

import java.io.InputStream;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;


public class MainActivity extends AppCompatActivity {

private ImageView img;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    img = findViewById(R.id.ntImg);


    try {


        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        // cert file stored in \app\src\main\res\raw
        InputStream caInput = getResources().openRawResource(R.raw.freshtocook);

        Certificate ca = cf.generateCertificate(caInput);
        caInput.close();

        KeyStore keyStore = KeyStore.getInstance("BKS");
        keyStore.load(null, null);
        keyStore.setCertificateEntry("ca", ca);

        String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
        tmf.init(keyStore);

        TrustManager[] wrappedTrustManagers = getWrappedTrustManagers(tmf.getTrustManagers());

        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, wrappedTrustManagers, null);

        AsyncSSLSocketMiddleware sslMiddleWare = Ion.getDefault(MainActivity.this).getHttpClient().getSSLSocketMiddleware();
        sslMiddleWare.setTrustManagers(wrappedTrustManagers);
        sslMiddleWare.setHostnameVerifier(getHostnameVerifier());
        sslMiddleWare.setSSLContext(sslContext);

        Ion.with(MainActivity.this)
                .load("https://freshtocook.in/uploads/banner/47a16ffc2fc5935dccd37574083c6201.jpg")
                .asBitmap()
                .setCallback(new FutureCallback<Bitmap>() {
                    @Override
                    public void onCompleted(Exception e, Bitmap bitmap) {
                        img.setImageBitmap(bitmap);
                    }
                });

    } catch (Exception e) {

    }


}


private HostnameVerifier getHostnameVerifier() {
    return new HostnameVerifier() {
        @Override
        public boolean verify(String hostname, SSLSession session) {
            return true;
            // or the following:
            // HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();
            // return hv.verify("www.yourserver.com", session);
        }
    };
}

private TrustManager[] getWrappedTrustManagers(TrustManager[] trustManagers) {
    final X509TrustManager originalTrustManager = (X509TrustManager) trustManagers[0];
    return new TrustManager[]{
            new X509TrustManager() {
                public X509Certificate[] getAcceptedIssuers() {
                    return originalTrustManager.getAcceptedIssuers();
                }

                public void checkClientTrusted(X509Certificate[] certs, String authType) {
                    try {
                        if (certs != null && certs.length > 0) {
                            certs[0].checkValidity();
                        } else {
                            originalTrustManager.checkClientTrusted(certs, authType);
                        }
                    } catch (CertificateException e) {
                        Log.w("checkClientTrusted", e.toString());
                    }
                }

                public void checkServerTrusted(X509Certificate[] certs, String authType) {
                    try {
                        if (certs != null && certs.length > 0) {
                            certs[0].checkValidity();
                        } else {
                            originalTrustManager.checkServerTrusted(certs, authType);
                        }
                    } catch (CertificateException e) {
                        Log.w("checkServerTrusted", e.toString());
                    }
                }
            }
    };
}
}
    <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" 
    tools:ignore="GoogleAppIndexingWarning">
    <uses-library
        android:name="org.apache.http.legacy"
        android:required="false" />

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
 类似资料:
  • 我在使用Glide加载图像时有问题。当我试图使用Android默认的它起作用了,但我遇到了内存泄漏问题。 然后我尝试了Glide图像加载器来避免内存泄漏问题。但是我不能使用文件路径加载图像。 我也尝试加载Uri,但也不起作用。 然后我试着从URL Glide加载图像加载URL图像。效果很好。 有人能帮我找到解决这个问题的方法吗?

  • 当我在fxml的所有三个位置中引用一个文件时,它工作得很好。当我引用所有3个不同的图像与绝对路径,它的工作很好。但我不理解相对路径只针对少数文件的问题。有人能帮我做这个吗? 我也尝试用“file:”替换“@”,但没有帮助。

  • 我建立简单的画廊。我使用Glide加载我的照片。在glide加载的图像上,看起来像是某种条纹(像素似乎是可见的)。我试图加载格式已更改的照片,我使用了,但它看起来仍然比原始照片更糟糕。 我用来加载的代码:

  • import { Scroll } from 'feui'; components: { [Scroll.name]: Scroll, }, data() { return { items: [], infiniteCount: 0, hasHeader: true }; } methods: { onRefresh(done) {

  • 它已经开始工作了,但今天我很惊讶,当我尝试分享链接时,Facebook没有显示来自og:image meta-tag的图像。 从facebook调试器: 图像在哪里?

  • 我试图用Javaflow(http://commons.apache.org/sandbox/commons-javaflow/)和OW2 ASM库(http://ASM.OW2.org/)来测试java类。我设置了javaagent并使用instrumentation.addTransformer()在加载时将我的transformer注册到instrument类。在transformer内部,