It's been days now, trying to figure how this function works... I have searched for it in stack overflow too ofcourse, Downloading and setting a wallpaper tried that, but got doInBackground error. and many more "seems legit" answer that I have tried. but in the end, I still had no clue how to change my
final String url2 = "http://icons.iconarchive.com/icons/3xhumed/mega-games-pack-26/256/Call-of-Duty-World-at-War-5-icon.png";
displaynya.setImageUrl(url2);
to be used when i call it in my button
case R.id.BTsetWalp:
WallpaperManager myWallpaperManager
= WallpaperManager.getInstance(getApplicationContext());
try {
myWallpaperManager.setResource(// what should i do with this?);
So confusing.. the past days, I'm trying to use only an image that has been stored in the apps, using that case 2
case R.id.ivwall02:
displaynya.setImageResource(R.drawable.a2);
setWallp = R.drawable.a2;
break;
This code is working. but if I use that, my app's size will get huge, because all huge image for wallpaper is stored in the apps. so i want to use a method in case 1 (downloading the image first, then set it to wallpaper), but I'm stuck in there..
==================================================
EDIT 2, updated my code so far
Here is the full code
public class CopyOfGallery extends Activity implements View.OnClickListener {
private SmartImageView displaynya;
Button bWalp;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);
bWalp = (Button) findViewById(R.id.BTsetWalp);
displaynya = (SmartImageView)findViewById(R.id.iVDisplay);
ImageView image01 = (ImageView) findViewById(R.id.ivwall01);
ImageView image02 = (ImageView) findViewById(R.id.ivwall02);
image01.setOnClickListener(this);
image02.setOnClickListener(this);
bWalp.setOnClickListener(this);
}
@Override
public void onClick(View vImage) {
// TODO Auto-generated method stub
switch (vImage.getId()){
case R.id.ivwall01:
final String url1 ="http://i100.photobucket.com/albums/m21/keitaro3660/komari/Komari02/km_happy.jpg" ;
displaynya.setImageUrl(url1);
break;
case R.id.ivwall02:
final String url2 ="http://i100.photobucket.com/albums/m21/keitaro3660/komari/Komari02/km_awkward.jpg" ;
displaynya.setImageUrl(url2);
break;
case R.id.BTsetWalp:
// get the Image to as Bitmap
Bitmap bitmap = BitmapFactory.decodeStream(getResources().openRawResource(R.id.iVDisplay));
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
// get the height and width of screen
int height = metrics.heightPixels;
int width = metrics.widthPixels;
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
try {
wallpaperManager.setBitmap(bitmap);
wallpaperManager.suggestDesiredDimensions(width, height);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}}
as for
Bitmap bitmap = BitmapFactory.decodeStream(getResources().openRawResource(R.id.iVDisplay));
this function is for fetch whatever image that shown in my R.id.iVDisplay isn't?? exactly what i needed. but why it got crash? :'(
here's my log
01-08 23:39:51.529: E/AndroidRuntime(22803): FATAL EXCEPTION: main
01-08 23:39:51.529: E/AndroidRuntime(22803): java.lang.NullPointerException
01-08 23:39:51.529: E/AndroidRuntime(22803): at android.content.res.Resources.openRawResource(Resources.java:951)
01-08 23:39:51.529: E/AndroidRuntime(22803): at android.content.res.Resources.openRawResource(Resources.java:927)
01-08 23:39:51.529: E/AndroidRuntime(22803): at preff.Gallery.onClick(Gallery.java:355) 01-08 23:39:51.529: E/AndroidRuntime(22803): at android.view.View.performClick(View.java:3526)
01-08 23:39:51.529: E/AndroidRuntime(22803): at android.view.View$PerformClick.run(View.java:14133)
missplacement or do i missing something? :(