Guest User

Untitled

a guest
Nov 18th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. final String myUrlStr = newString;
  2. URL url;
  3. Uri uri=null;
  4. try {
  5. url = new URL(myUrlStr);
  6. uri = Uri.parse( url.toURI().toString() );
  7. } catch (MalformedURLException e1) {
  8. e1.printStackTrace();
  9. } catch (URISyntaxException e) {
  10. e.printStackTrace();
  11. }
  12.  
  13. try {
  14. image = MediaStore.Images.Media.getBitmap(this.getContentResolver(),uri);
  15. } catch (IOException e) {
  16. e.printStackTrace();
  17. }
  18. setButton.setOnClickListener(new View.OnClickListener() {
  19. @Override
  20. public void onClick(View view) {
  21. WallpaperManager wallpaperManager=WallpaperManager.getInstance(getApplicationContext());
  22.  
  23. try {
  24. // Set the image as wallpaper
  25. if(image!=null)
  26. wallpaperManager.setBitmap(image);
  27. else
  28. Toast.makeText(getApplicationContext(), "No image was chosen.", Toast.LENGTH_LONG).show();
  29. } catch (IOException e) {
  30. // TODO Auto-generated catch block
  31. e.printStackTrace();
  32. }
  33.  
  34. }
  35. });
Add Comment
Please, Sign In to add comment