无法通过一堆 URL(字符串数组)设置墙纸。如何解决这个问题?

Can't set wallpaper from a bunch of URLs (string array). How to solve this?

我目前正在制作一个以网格布局 (recyclerView) 显示来自网络的图像的应用程序。选择一张图片后,将打开另一张 activity 并全屏显示相同的图片(就像图片库一样)。为此,我正在使用 Glide 库。在这个 activity 中,我实现了一个底部工具栏,其中包含两个项目 "set wallpaper" 和 "Download"。我已经编写了设置壁纸的代码,但它似乎不起作用,而且该应用程序也从未崩溃过。我附上了网格视图的图像和另一个 activity(代码和全屏图像) 我需要帮助将全屏图像设置为墙纸,这适用于网格视图中的所有图像。 图片:http://imgur.com/a/LSbX0

代码:

public class SecondActivity extends Activity {

    BottomBar bottomBar;

    public static final String image = "SecondActivity.LIST_ITEMS";
    ImageView selectedImage;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);


        bottomBar = (BottomBar)findViewById(R.id.bottom_navbar);

        selectedImage = (ImageView) findViewById(R.id.selectedImage); // init a ImageView

        final ListItem listItem = getIntent().getParcelableExtra(image);

        Glide.with(this).asBitmap().load(listItem.getImgurl()).into((ImageView)findViewById(R.id.selectedImage));



        bottomBar.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
           public void onTabSelected(@IdRes int tabId) {
               if(tabId == R.id.setwallpaper){


                   Glide.with(getApplicationContext()).asBitmap().load(selectedImage).into(new SimpleTarget<Bitmap>(){

                        @Override
                        public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
                            try {
                                WallpaperManager.getInstance(getApplicationContext()).setBitmap(resource);
                                Toast.makeText(getApplicationContext(), "Success",Toast.LENGTH_LONG).show();


                            } catch (IOException e) {
                                e.printStackTrace();
                                Toast.makeText(getApplicationContext(), "Failed",Toast.LENGTH_LONG).show();
                            }
                        }



                   });
               }

               if(tabId == R.id.download){





               }

            }
        });



    }
}

日志:

08-27 23:28:08.881 1309-1329/? D/AudioFlinger: mixer(0xa8083940) throttle end: throttle time(22)
08-27 23:28:08.884 5247-5403/quote.quotemania E/GlideExecutor: Request threw uncaught throwable
    com.bumptech.glide.Registry$NoModelLoaderAvailableException: Failed to find any ModelLoaders for model: android.widget.ImageView{b8534d9 V.ED..... ......I. 0,0-0,0 #7f0f00a7 app:id/selectedImage}
      at com.bumptech.glide.Registry.getModelLoaders(Registry.java:227)
      at com.bumptech.glide.load.engine.DecodeHelper.getLoadData(DecodeHelper.java:179)
      at com.bumptech.glide.load.engine.DecodeHelper.getCacheKeys(DecodeHelper.java:197)
      at com.bumptech.glide.load.engine.ResourceCacheGenerator.startNext(ResourceCacheGenerator.java:41)
      at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:282)
      at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:249)
      at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:222)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
      at java.lang.Thread.run(Thread.java:761)
      at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory.run(GlideExecutor.java:347)
08-27 23:28:08.888 5247-5273/quote.quotemania V/FA: Using measurement service
08-27 23:28:08.888 5247-5273/quote.quotemania V/FA: Connection attempt already in progress
08-27 23:28:08.889 5247-5273/quote.quotemania V/FA: Using measurement service
08-27 23:28:08.889 5247-5273/quote.quotemania V/FA: Connection attempt already in progress
08-27 23:28:08.889 5247-5273/quote.quotemania V/FA: Activity resumed, time: 3119251
08-27 23:28:08.890 5247-5273/quote.quotemania D/FA: Connected to remote service
08-27 23:28:08.890 5247-5273/quote.quotemania V/FA: Processing queued up service tasks: 3
08-27 23:28:08.891 5247-5247/quote.quotemania W/Glide: Load failed for android.widget.ImageView{b8534d9 V.ED..... ......I. 0,0-0,0 #7f0f00a7 app:id/selectedImage} with size [-2147483648x-2147483648]
                                                       class com.bumptech.glide.load.engine.GlideException: Failed to load resource
08-27 23:28:08.891 5247-5247/quote.quotemania E/Glide: class com.bumptech.glide.load.engine.GlideException: Failed to load resource
08-27 23:28:08.900 2431-5278/com.google.android.gms V/FA-SVC: Logging event: origin=auto,name=_e,params=Bundle[mParcelledData.dataSize=132]
08-27 23:28:08.906 2431-5278/com.google.android.gms V/FA-SVC: Saving event, name, data size: _e, 68
08-27 23:28:08.906 2431-5278/com.google.android.gms V/FA-SVC: Event recorded: Event{appId='quote.quotemania', name='_e', params=Bundle[{_o=auto, _et=8878, _sc=BrowseQuotes, _si=-5888889340355970828}]}
08-27 23:28:08.909 2431-5278/com.google.android.gms V/FA-SVC: Background event processing time, ms: 9
08-27 23:28:08.938 1298-1340/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
08-27 23:28:08.955 1298-1340/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
08-27 23:28:08.967 1298-1340/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
08-27 23:28:08.984 5247-5247/quote.quotemania W/View: requestLayout() improperly called by android.widget.TextView{8a7a611 V.ED..... ......ID 294,133-294,196 #7f0f00ae app:id/bb_bottom_bar_title} during layout: running second layout pass
08-27 23:28:08.984 5247-5247/quote.quotemania W/View: requestLayout() improperly called by android.widget.TextView{6211376 V.ED..... ......ID 294,140-294,196 #7f0f00ae app:id/bb_bottom_bar_title} during layout: running second layout pass
08-27 23:28:09.127 1577-1600/system_process I/ActivityManager: Displayed quote.quotemania/.SecondActivity: +279ms
08-27 23:28:13.903 5247-5273/quote.quotemania V/FA: Inactivity, disconnecting from the service
08-27 23:28:19.770 1309-1329/? D/AudioFlinger: mixer(0xa8083940) throttle end: throttle time(11)
08-27 23:28:21.668 1309-1329/? D/AudioFlinger: mixer(0xa8083940) throttle end: throttle time(43)
08-27 23:28:21.732 1309-1329/? D/AudioFlinger: mixer(0xa8083940) throttle end: throttle time(1)
08-27 23:28:24.034 1309-1329/? D/AudioFlinger: mixer(0xa8083940) throttle end: throttle time(1)

Android 清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="quote.quotemania">

<uses-permission android:name="android.permission.SET_WALLPAPER"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<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=".MainActivity"></activity>
    <activity android:name=".BrowseQuotes"></activity>
    <activity android:name=".splash_screen">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".SecondActivity"></activity>
</application>

xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:design="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/framelayout"
    android:layout_above="@+id/bottom_navbar" >


<ImageView
    android:id="@+id/selectedImage"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitXY" />

</FrameLayout>

<com.roughike.bottombar.BottomBar
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:id="@+id/bottom_navbar"
    android:layout_alignParentBottom="true"
    app:bb_tabXmlResource="@xml/bottombar_tabs"
    android:background="#263f40"
    app:bb_inActiveTabColor="#fff"
    app:bb_activeTabColor="#fff"
    >

</com.roughike.bottombar.BottomBar>

</RelativeLayout>

找到的解决方案:

使用按钮代替工具栏!