Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. Button player = (Button) setBg.findViewById(R.id.plBg);
  2.  
  3. player.setOnClickListener(new OnClickListener() {
  4. public void onClick(View v) {
  5.  
  6. Intent i = new Intent(Intent.ACTION_PICK,
  7. android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  8.  
  9. i.setDataAndType(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, "image/*");
  10. startActivityForResult(i, RESULT_LOAD_PLAYER);
  11.  
  12. setBg.dismiss();
  13. }
  14. });
  15.  
  16. @Override
  17. protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
  18. super.onActivityResult(requestCode, resultCode, data);
  19.  
  20. if (requestCode == RESULT_LOAD_PLAYER && resultCode == RESULT_OK && null != data) {
  21. Uri selectedImage = data.getData();
  22. String[] filePathColumn = {MediaStore.Images.Media.DATA};
  23.  
  24. Cursor cursor = getContentResolver().query(selectedImage,
  25. filePathColumn, null, null, null);
  26. cursor.moveToFirst();
  27.  
  28. int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
  29. String picturePath = cursor.getString(columnIndex);
  30. cursor.close();
  31.  
  32. playerBg = (ImageView) findViewById(R.id.playerBg);
  33. playerBg.setImageBitmap(BitmapFactory.decodeFile(picturePath));
  34. playerBg.setScaleType(ScaleType.CENTER_CROP);
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement