The following happens. I have a share button, when I try to share an image from within my drawable, it will beauty, now when I try to share the image that came from the firebase, there it will not "it closes the app" PS: I'm a beginner, I know it's because of the image, because with the local image it goes, I just do not know how to solve it. Thanks in advance, for the people who try to help me
HERE I MAKE THE FIREBASE IMAGE LOADING INSIDE AN IMAGEVIEW:
btnFrase = (Button) findViewById(R.id.idBtnLoadPhoto);
btnFrase.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("IMAGEM", "Aqui carrega imagem");
Glide.with(getApplicationContext()).load("https://firebasestorage.googleapis.com/caminho da imagem").into(img);
}
});
HERE IS THE SHARE METHOD:
private void sharedImage(){
// Vamos carregar a imagem em um bitmap
Bitmap b = BitmapFactory.decodeResource(getResources(), R.id.idPhoto); //idPhoto é o ID da minha imageView
Intent share = new Intent(Intent.ACTION_SEND);
//setamos o tipo da imagem
share.setType("image/png");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
// comprimomos a imagem
b.compress(Bitmap.CompressFormat.PNG, 100, bytes);
// Gravamos a imagem
String path = MediaStore.Images.Media.insertImage(getContentResolver(), b, "testetituloimagem", null);
// criamos uam Uri com o endereço que a imagem foi salva
Uri imageUri = Uri.parse(path);
// Setmaos a Uri da imagem
share.putExtra(Intent.EXTRA_STREAM, imageUri);
// chama o compartilhamento
startActivity(Intent.createChooser(share, "Selecione"));
}
ANDROID MONITOR ERROR
10-20 17:10:47.906 3652-3652/br.com.quanticoapps.frases E/AndroidRuntime: FATAL EXCEPTION: main
Process: br.com.quanticoapps.frases, PID: 3652
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.compress(android.graphics.Bitmap$CompressFormat, int, java.io.OutputStream)' on a null object reference
at br.com.quanticoapps.frases.MainActivity.sharedImage(MainActivity.java:152)
at br.com.quanticoapps.frases.MainActivity.checarPermissao(MainActivity.java:176)
at br.com.quanticoapps.frases.MainActivity.access$000(MainActivity.java:34)
at br.com.quanticoapps.frases.MainActivity$2.onClick(MainActivity.java:72)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22265)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)