I'm currently making an app that displays images from the web in a grid layout(recyclerView). When one image is selected another activity is opened and displays the same image in fullscreen(just like an image gallery). I'm using Glide library for this purpose. In this activity I have implemented a bottom toolbar which contains two items "set wallpaper" and "Download". I have written the code to set the wallpaper but it does not seem to work and the app never crashes too. I have attached the image of the grid view and the other activity(code and fullscreen image) I need helping in setting the full screen image as wallpaper and this applies for all the images in grid view. Images : https://i.stack.imgur.com/7D9au.jpg
Code :
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){
}
}
});
}
}
log :
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$1.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 manifest:
<?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 file :
<?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>