Reputation: 1507
in the end I'm starting up a service that I will want to call to that class and change my phone's wallpaper.
in the mainActivity java file I can just write >
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int height = metrics.heightPixels;
int width = metrics.widthPixels;
Bitmap bmap2 = BitmapFactory.decodeResource(getResources(), R.drawable.superman);
Bitmap bitmap = Bitmap.createScaledBitmap(bmap2, width, height, true);
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
// Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.superman);
try {
wallpaperManager.setBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
and this works great... it uploads the wallpaper and starches it to fit screen
but I can't use it in another java class.,
how do I do this on another java class, and then later on call it from my myService Class ?
Upvotes: 2
Views: 82
Reputation: 47
maybe don't use getWindowManager, from outside your activity ? since you can't use it outside activity class
Upvotes: 1