Skip to content

Instantly share code, notes, and snippets.

@ifaisal24
Created June 16, 2016 06:48
Show Gist options
  • Save ifaisal24/c7e3849646f4b2ff828cfdecccd4cd4b to your computer and use it in GitHub Desktop.
Save ifaisal24/c7e3849646f4b2ff828cfdecccd4cd4b to your computer and use it in GitHub Desktop.
final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
final Drawable wal = wallpaperManager.getDrawable();
Bitmap bitmap = ((BitmapDrawable)wal).getBitmap();
// Toast.makeText(Main2Activity.this, bitmap+"", Toast.LENGTH_LONG).show();
ImageView imagePreview = (ImageView)findViewById(R.id.imageView);
imagePreview.setImageBitmap(bitmap);
// TODO Auto-generated method stub
WallpaperManager myWallpaperManager
= WallpaperManager.getInstance(getApplicationContext());
try {
context.setWallpaper(bit);
Toast.makeText(Main2Activity.this,"wallpaper set", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
// bitmap = BitmapFactory.decodeStream(stream);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
String encodedImage = Base64.encodeToString(b, Base64.DEFAULT);
// textEncode.setText(encodedImage);
SharedPreferences shre = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor edit=shre.edit();
edit.putString("image_data",encodedImage);
edit.commit();
String previouslyEncodedImage = shre.getString("image_data", "");
if( !previouslyEncodedImage.equalsIgnoreCase("") ){
b = Base64.decode(previouslyEncodedImage, Base64.DEFAULT);
Bitmap bit = BitmapFactory.decodeByteArray(b, 0, b.length);
// imagePreview.setImageBitmap(bit);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment