簡體   English   中英

如何在android中加載URL圖像?

[英]How to load URL image in android wear?

現在我使用Glide-library在Android Wear中加載圖像。 它大多數時間都不會加載圖像。 但是,它有時會加載圖像。 不知道我的代碼出了什么問題。

注意 Wear通過藍牙連接到設備,我通過移動Broadcast Receiver成功獲得Android Wear中Webservice的JSON響應。 除圖像外,所有數據均在磨損狀態下正確顯示。

Glide.with(mContext)
   .load("http://www.hanamoflorist.ca/images/uploads/Spring5InchesCubeVaseArrangement$45.00.jpg")
      .listener(new RequestListener<String, GlideDrawable>() {

        @Override
        public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
            Log.e("exception in image", "" + e);
            Toast.makeText(mContext, "" + e, Toast.LENGTH_LONG).show();
            return false;
        }

        @Override
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
            return false;
        }
    }).error(R.drawable.ic_placeholder_image)
        .into(((ItemViewHolder) holder).ivCardImage);

我認為你應該使用DaVinci在Wearable中加載圖像,

DaVinci.with(context).load("Your Url").into(imageView);

確保使用與庫相同的playservices版本,

您可以通過將其添加到您的gradle來集成相同的內容:

穿:

compile ('com.github.florent37:davinci:1.0.3@aar'){
    transitive = true
}

移動:

compile ('com.github.florent37:davincidaemon:1.0.3@aar'){
     transitive = true
}

希望你能得到你想要的東西。

問題是由於插座超時...

您可以使用Glide本身解決它。 你只需要在OKHttp3中使用Glide,並為OkHttpClient設置Timeout Limit。

在您的模塊依賴項中

compile 'com.github.bumptech.glide:glide:3.7.0'
compile ('com.github.bumptech.glide:okhttp3-integration:1.4.0'){
    exclude group: 'glide-parent'
}

自定義滑行設置

public class MyGlideModule implements GlideModule {
   @Override
   public void applyOptions(Context context, GlideBuilder builder) {

   }

   @Override
   public void registerComponents(Context context, Glide glide) {

       OkHttpClient.Builder builder = new OkHttpClient.Builder();

       // set your timeout here
       builder.readTimeout(30, TimeUnit.SECONDS);
       builder.writeTimeout(30, TimeUnit.SECONDS);
       builder.connectTimeout(30, TimeUnit.SECONDS);
       OkHttpUrlLoader.Factory factory = new    OkHttpUrlLoader.Factory(client);
       glide.register(GlideUrl.class, InputStream.class, factory);
   }
}

在清單下面的代碼

 <meta-data
        android:name="YourPath.MyGlideModule"
        android:value="GlideModule" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM