(unchecked) unchecked cast required: OnSuccessListener found: Uri2019 Community Moderator ElectionHow do I address unchecked cast warnings?Android AlarmManager for periodical sensor readingWhy don't Java's +=, -=, *=, /= compound assignment operators require casting?I am trying to set alarm on specific time using alarm manager but alarm initiated instantly?setText on button from another activity androidget around of error 'can not resolve symbol'Saving ToggleButton state in ListView by using SharedPreferencesAdding Social Media Share Logic From Firebase in Androidjava.lang.NullPointerException when invoking onLoadFinished()Search Firestore query don't show data in RecycleView

Infrastructure damage from sudden thickening of water

How to approximate rolls for potions of healing using only d6's?

Where is this triangular-shaped space station from?

Easy code troubleshooting in wordpress

Series pass transistor, LM7812

What's the difference between a cart and a wagon?

Reason why dimensional travelling would be restricted

How to deny access to SQL Server to certain login over SSMS, but allow over .Net SqlClient Data Provider

Is there a frame of reference in which I was born before I was conceived?

What is better: yes / no radio, or simple checkbox?

Has the Isbell–Freyd criterion ever been used to check that a category is concretisable?

What to do when being responsible for data protection in your lab, yet advice is ignored?

How to kill a localhost:8080

How can atoms be electrically neutral when there is a difference in the positions of the charges?

In the comics Did Thanos "kill" just sentient beings or all creatures with the snap?

Where is the fallacy here?

Hacker Rank: Array left rotation

chrony vs. systemd-timesyncd – What are the differences and use cases as NTP clients?

Replacement ford fiesta radiator has extra hose

Make me a metasequence

Called into a meeting and told we are being made redundant (laid off) and "not to share outside". Can I tell my partner?

Can we carry rice to Japan?

What is the wife of a henpecked husband called?

What does 'acting greedily' mean?



(unchecked) unchecked cast required: OnSuccessListener found: Uri



2019 Community Moderator ElectionHow do I address unchecked cast warnings?Android AlarmManager for periodical sensor readingWhy don't Java's +=, -=, *=, /= compound assignment operators require casting?I am trying to set alarm on specific time using alarm manager but alarm initiated instantly?setText on button from another activity androidget around of error 'can not resolve symbol'Saving ToggleButton state in ListView by using SharedPreferencesAdding Social Media Share Logic From Firebase in Androidjava.lang.NullPointerException when invoking onLoadFinished()Search Firestore query don't show data in RecycleView










0















I am developing an android application on Android Studio With Firebase and i am having the following error:



[unchecked] unchecked cast
required: OnSuccessListener
found: Uri



When I click to Show where is the problem it takes me to this code:



private void uploadImageToFirebaseStorage() 
final StorageReference profileImageRef =
FirebaseStorage.getInstance().getReference("profilepics/"+System.currentTimeMillis()+".jpg");
if(uriProfileImage!=null)
profileImageRef.putFile(uriProfileImage)

.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>()
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot)
profileImageRef.getDownloadUrl().addOnSuccessListener((OnSuccessListener<? super Uri>) uriProfileImage);

)
.addOnFailureListener(new OnFailureListener()
@Override
public void onFailure(@NonNull Exception e)
Toast.makeText(Profile.this,e.getMessage(),Toast.LENGTH_SHORT).show();


);




Down here is the whole class:



public class Profile extends AppCompatActivity 
private static final int CHOOSE_IMAGE = 101;
TextView textView;
EditText editText;
ImageView imageView;
String profileimageurl;
private StorageReference mStorageRef;

Uri uriProfileImage;

FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
mStorageRef = FirebaseStorage.getInstance().getReference();

mAuth = FirebaseAuth.getInstance();

Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

editText =(EditText)findViewById(R.id.nome);
imageView=(ImageView) findViewById(R.id.prefil);
textView=(TextView) findViewById(R.id.textViewVerified);

imageView.setOnClickListener(new View.OnClickListener()

@Override
public void onClick(View v)
showImageChooser();

);

loadUserInformation();



findViewById(R.id.login_bt).setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
saveUserInformation();

);


@Override
protected void onStart()
super.onStart();
if(mAuth.getCurrentUser()!=null)

finish();
startActivity(new Intent(this,Login.class));






private void loadUserInformation()

final FirebaseUser user = mAuth.getCurrentUser();
if (user != null)


if (user.getPhotoUrl() != null)

String photoUrl = user.getPhotoUrl().toString();
Glide.with(this)
.load(user.getPhotoUrl().toString())
.into(imageView);

if (user.getDisplayName() != null)

String displayName = user.getDisplayName();
editText.setText(user.getDisplayName());



if (user.isEmailVerified())
textView.setText("Email verified");


else
textView.setText("Email not Verified(click to Verify");
textView.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
user.sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>()
@Override
public void onComplete(@NonNull Task<Void> task)
Toast.makeText(Profile.this,"Verification Email Sent",Toast.LENGTH_SHORT).show();

);


);




private void saveUserInformation()
String displayName = editText.getText().toString();
if(displayName.isEmpty())
editText.setError("Requer Nome");
editText.requestFocus();
return;


FirebaseUser user = mAuth.getCurrentUser();

if(user!=null && profileimageurl!=null)
UserProfileChangeRequest profile = new UserProfileChangeRequest.Builder()
.setDisplayName(displayName)
.setPhotoUri(Uri.parse(profileimageurl))
.build();
user.updateProfile(profile)
.addOnCompleteListener(new OnCompleteListener<Void>()
@Override
public void onComplete(@NonNull Task<Void> task)
if( task.isSuccessful())
Toast.makeText(Profile.this,"Profile Updated",Toast.LENGTH_SHORT).show();


);






@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data)
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==CHOOSE_IMAGE&& data !=null && data.getData()!=null)
uriProfileImage = data.getData();
try
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),uriProfileImage);
imageView.setImageBitmap(bitmap);

uploadImageToFirebaseStorage();

catch (IOException e)
e.printStackTrace();




private void uploadImageToFirebaseStorage()
final StorageReference profileImageRef =
FirebaseStorage.getInstance().getReference("profilepics/"+System.currentTimeMillis()+".jpg");
if(uriProfileImage!=null)
profileImageRef.putFile(uriProfileImage)

.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>()
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot)
profileImageRef.getDownloadUrl().addOnSuccessListener((OnSuccessListener<? super Uri>) uriProfileImage);

)
.addOnFailureListener(new OnFailureListener()
@Override
public void onFailure(@NonNull Exception e)
Toast.makeText(Profile.this,e.getMessage(),Toast.LENGTH_SHORT).show();


);



@Override
public boolean onCreateOptionsMenu(Menu menu)
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;



@Override
public boolean onOptionsItemSelected(MenuItem item)
switch (item.getItemId())
case R.id.menuLogout:

FirebaseAuth.getInstance().signOut();
finish();
startActivity(new Intent(this,Login.class));
break;

return true;


private void showImageChooser()
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Escohe a imagem de perfil"),CHOOSE_IMAGE);













share|improve this question
























  • @Michael done , i already changed

    – Gonçalo Oliveira Carvalho
    33 mins ago











  • Correct me if I'm wrong, but in the statement profileImageRef.getDownloadUrl().addOnSuccessListener((OnSuccessListener<? super Uri>) uriProfileImage), it seems like you're casting a Uri object to an instance of an OnSuccessListener. I suspect there seems to be a logical error here.

    – Karan Modi
    23 mins ago












  • @Michael thank you

    – Gonçalo Oliveira Carvalho
    19 mins ago











  • @KaranModi i am trying send a imagem to firebase storage

    – Gonçalo Oliveira Carvalho
    19 mins ago















0















I am developing an android application on Android Studio With Firebase and i am having the following error:



[unchecked] unchecked cast
required: OnSuccessListener
found: Uri



When I click to Show where is the problem it takes me to this code:



private void uploadImageToFirebaseStorage() 
final StorageReference profileImageRef =
FirebaseStorage.getInstance().getReference("profilepics/"+System.currentTimeMillis()+".jpg");
if(uriProfileImage!=null)
profileImageRef.putFile(uriProfileImage)

.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>()
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot)
profileImageRef.getDownloadUrl().addOnSuccessListener((OnSuccessListener<? super Uri>) uriProfileImage);

)
.addOnFailureListener(new OnFailureListener()
@Override
public void onFailure(@NonNull Exception e)
Toast.makeText(Profile.this,e.getMessage(),Toast.LENGTH_SHORT).show();


);




Down here is the whole class:



public class Profile extends AppCompatActivity 
private static final int CHOOSE_IMAGE = 101;
TextView textView;
EditText editText;
ImageView imageView;
String profileimageurl;
private StorageReference mStorageRef;

Uri uriProfileImage;

FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
mStorageRef = FirebaseStorage.getInstance().getReference();

mAuth = FirebaseAuth.getInstance();

Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

editText =(EditText)findViewById(R.id.nome);
imageView=(ImageView) findViewById(R.id.prefil);
textView=(TextView) findViewById(R.id.textViewVerified);

imageView.setOnClickListener(new View.OnClickListener()

@Override
public void onClick(View v)
showImageChooser();

);

loadUserInformation();



findViewById(R.id.login_bt).setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
saveUserInformation();

);


@Override
protected void onStart()
super.onStart();
if(mAuth.getCurrentUser()!=null)

finish();
startActivity(new Intent(this,Login.class));






private void loadUserInformation()

final FirebaseUser user = mAuth.getCurrentUser();
if (user != null)


if (user.getPhotoUrl() != null)

String photoUrl = user.getPhotoUrl().toString();
Glide.with(this)
.load(user.getPhotoUrl().toString())
.into(imageView);

if (user.getDisplayName() != null)

String displayName = user.getDisplayName();
editText.setText(user.getDisplayName());



if (user.isEmailVerified())
textView.setText("Email verified");


else
textView.setText("Email not Verified(click to Verify");
textView.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
user.sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>()
@Override
public void onComplete(@NonNull Task<Void> task)
Toast.makeText(Profile.this,"Verification Email Sent",Toast.LENGTH_SHORT).show();

);


);




private void saveUserInformation()
String displayName = editText.getText().toString();
if(displayName.isEmpty())
editText.setError("Requer Nome");
editText.requestFocus();
return;


FirebaseUser user = mAuth.getCurrentUser();

if(user!=null && profileimageurl!=null)
UserProfileChangeRequest profile = new UserProfileChangeRequest.Builder()
.setDisplayName(displayName)
.setPhotoUri(Uri.parse(profileimageurl))
.build();
user.updateProfile(profile)
.addOnCompleteListener(new OnCompleteListener<Void>()
@Override
public void onComplete(@NonNull Task<Void> task)
if( task.isSuccessful())
Toast.makeText(Profile.this,"Profile Updated",Toast.LENGTH_SHORT).show();


);






@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data)
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==CHOOSE_IMAGE&& data !=null && data.getData()!=null)
uriProfileImage = data.getData();
try
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),uriProfileImage);
imageView.setImageBitmap(bitmap);

uploadImageToFirebaseStorage();

catch (IOException e)
e.printStackTrace();




private void uploadImageToFirebaseStorage()
final StorageReference profileImageRef =
FirebaseStorage.getInstance().getReference("profilepics/"+System.currentTimeMillis()+".jpg");
if(uriProfileImage!=null)
profileImageRef.putFile(uriProfileImage)

.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>()
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot)
profileImageRef.getDownloadUrl().addOnSuccessListener((OnSuccessListener<? super Uri>) uriProfileImage);

)
.addOnFailureListener(new OnFailureListener()
@Override
public void onFailure(@NonNull Exception e)
Toast.makeText(Profile.this,e.getMessage(),Toast.LENGTH_SHORT).show();


);



@Override
public boolean onCreateOptionsMenu(Menu menu)
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;



@Override
public boolean onOptionsItemSelected(MenuItem item)
switch (item.getItemId())
case R.id.menuLogout:

FirebaseAuth.getInstance().signOut();
finish();
startActivity(new Intent(this,Login.class));
break;

return true;


private void showImageChooser()
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Escohe a imagem de perfil"),CHOOSE_IMAGE);













share|improve this question
























  • @Michael done , i already changed

    – Gonçalo Oliveira Carvalho
    33 mins ago











  • Correct me if I'm wrong, but in the statement profileImageRef.getDownloadUrl().addOnSuccessListener((OnSuccessListener<? super Uri>) uriProfileImage), it seems like you're casting a Uri object to an instance of an OnSuccessListener. I suspect there seems to be a logical error here.

    – Karan Modi
    23 mins ago












  • @Michael thank you

    – Gonçalo Oliveira Carvalho
    19 mins ago











  • @KaranModi i am trying send a imagem to firebase storage

    – Gonçalo Oliveira Carvalho
    19 mins ago













0












0








0








I am developing an android application on Android Studio With Firebase and i am having the following error:



[unchecked] unchecked cast
required: OnSuccessListener
found: Uri



When I click to Show where is the problem it takes me to this code:



private void uploadImageToFirebaseStorage() 
final StorageReference profileImageRef =
FirebaseStorage.getInstance().getReference("profilepics/"+System.currentTimeMillis()+".jpg");
if(uriProfileImage!=null)
profileImageRef.putFile(uriProfileImage)

.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>()
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot)
profileImageRef.getDownloadUrl().addOnSuccessListener((OnSuccessListener<? super Uri>) uriProfileImage);

)
.addOnFailureListener(new OnFailureListener()
@Override
public void onFailure(@NonNull Exception e)
Toast.makeText(Profile.this,e.getMessage(),Toast.LENGTH_SHORT).show();


);




Down here is the whole class:



public class Profile extends AppCompatActivity 
private static final int CHOOSE_IMAGE = 101;
TextView textView;
EditText editText;
ImageView imageView;
String profileimageurl;
private StorageReference mStorageRef;

Uri uriProfileImage;

FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
mStorageRef = FirebaseStorage.getInstance().getReference();

mAuth = FirebaseAuth.getInstance();

Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

editText =(EditText)findViewById(R.id.nome);
imageView=(ImageView) findViewById(R.id.prefil);
textView=(TextView) findViewById(R.id.textViewVerified);

imageView.setOnClickListener(new View.OnClickListener()

@Override
public void onClick(View v)
showImageChooser();

);

loadUserInformation();



findViewById(R.id.login_bt).setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
saveUserInformation();

);


@Override
protected void onStart()
super.onStart();
if(mAuth.getCurrentUser()!=null)

finish();
startActivity(new Intent(this,Login.class));






private void loadUserInformation()

final FirebaseUser user = mAuth.getCurrentUser();
if (user != null)


if (user.getPhotoUrl() != null)

String photoUrl = user.getPhotoUrl().toString();
Glide.with(this)
.load(user.getPhotoUrl().toString())
.into(imageView);

if (user.getDisplayName() != null)

String displayName = user.getDisplayName();
editText.setText(user.getDisplayName());



if (user.isEmailVerified())
textView.setText("Email verified");


else
textView.setText("Email not Verified(click to Verify");
textView.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
user.sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>()
@Override
public void onComplete(@NonNull Task<Void> task)
Toast.makeText(Profile.this,"Verification Email Sent",Toast.LENGTH_SHORT).show();

);


);




private void saveUserInformation()
String displayName = editText.getText().toString();
if(displayName.isEmpty())
editText.setError("Requer Nome");
editText.requestFocus();
return;


FirebaseUser user = mAuth.getCurrentUser();

if(user!=null && profileimageurl!=null)
UserProfileChangeRequest profile = new UserProfileChangeRequest.Builder()
.setDisplayName(displayName)
.setPhotoUri(Uri.parse(profileimageurl))
.build();
user.updateProfile(profile)
.addOnCompleteListener(new OnCompleteListener<Void>()
@Override
public void onComplete(@NonNull Task<Void> task)
if( task.isSuccessful())
Toast.makeText(Profile.this,"Profile Updated",Toast.LENGTH_SHORT).show();


);






@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data)
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==CHOOSE_IMAGE&& data !=null && data.getData()!=null)
uriProfileImage = data.getData();
try
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),uriProfileImage);
imageView.setImageBitmap(bitmap);

uploadImageToFirebaseStorage();

catch (IOException e)
e.printStackTrace();




private void uploadImageToFirebaseStorage()
final StorageReference profileImageRef =
FirebaseStorage.getInstance().getReference("profilepics/"+System.currentTimeMillis()+".jpg");
if(uriProfileImage!=null)
profileImageRef.putFile(uriProfileImage)

.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>()
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot)
profileImageRef.getDownloadUrl().addOnSuccessListener((OnSuccessListener<? super Uri>) uriProfileImage);

)
.addOnFailureListener(new OnFailureListener()
@Override
public void onFailure(@NonNull Exception e)
Toast.makeText(Profile.this,e.getMessage(),Toast.LENGTH_SHORT).show();


);



@Override
public boolean onCreateOptionsMenu(Menu menu)
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;



@Override
public boolean onOptionsItemSelected(MenuItem item)
switch (item.getItemId())
case R.id.menuLogout:

FirebaseAuth.getInstance().signOut();
finish();
startActivity(new Intent(this,Login.class));
break;

return true;


private void showImageChooser()
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Escohe a imagem de perfil"),CHOOSE_IMAGE);













share|improve this question
















I am developing an android application on Android Studio With Firebase and i am having the following error:



[unchecked] unchecked cast
required: OnSuccessListener
found: Uri



When I click to Show where is the problem it takes me to this code:



private void uploadImageToFirebaseStorage() 
final StorageReference profileImageRef =
FirebaseStorage.getInstance().getReference("profilepics/"+System.currentTimeMillis()+".jpg");
if(uriProfileImage!=null)
profileImageRef.putFile(uriProfileImage)

.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>()
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot)
profileImageRef.getDownloadUrl().addOnSuccessListener((OnSuccessListener<? super Uri>) uriProfileImage);

)
.addOnFailureListener(new OnFailureListener()
@Override
public void onFailure(@NonNull Exception e)
Toast.makeText(Profile.this,e.getMessage(),Toast.LENGTH_SHORT).show();


);




Down here is the whole class:



public class Profile extends AppCompatActivity 
private static final int CHOOSE_IMAGE = 101;
TextView textView;
EditText editText;
ImageView imageView;
String profileimageurl;
private StorageReference mStorageRef;

Uri uriProfileImage;

FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
mStorageRef = FirebaseStorage.getInstance().getReference();

mAuth = FirebaseAuth.getInstance();

Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

editText =(EditText)findViewById(R.id.nome);
imageView=(ImageView) findViewById(R.id.prefil);
textView=(TextView) findViewById(R.id.textViewVerified);

imageView.setOnClickListener(new View.OnClickListener()

@Override
public void onClick(View v)
showImageChooser();

);

loadUserInformation();



findViewById(R.id.login_bt).setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
saveUserInformation();

);


@Override
protected void onStart()
super.onStart();
if(mAuth.getCurrentUser()!=null)

finish();
startActivity(new Intent(this,Login.class));






private void loadUserInformation()

final FirebaseUser user = mAuth.getCurrentUser();
if (user != null)


if (user.getPhotoUrl() != null)

String photoUrl = user.getPhotoUrl().toString();
Glide.with(this)
.load(user.getPhotoUrl().toString())
.into(imageView);

if (user.getDisplayName() != null)

String displayName = user.getDisplayName();
editText.setText(user.getDisplayName());



if (user.isEmailVerified())
textView.setText("Email verified");


else
textView.setText("Email not Verified(click to Verify");
textView.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
user.sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>()
@Override
public void onComplete(@NonNull Task<Void> task)
Toast.makeText(Profile.this,"Verification Email Sent",Toast.LENGTH_SHORT).show();

);


);




private void saveUserInformation()
String displayName = editText.getText().toString();
if(displayName.isEmpty())
editText.setError("Requer Nome");
editText.requestFocus();
return;


FirebaseUser user = mAuth.getCurrentUser();

if(user!=null && profileimageurl!=null)
UserProfileChangeRequest profile = new UserProfileChangeRequest.Builder()
.setDisplayName(displayName)
.setPhotoUri(Uri.parse(profileimageurl))
.build();
user.updateProfile(profile)
.addOnCompleteListener(new OnCompleteListener<Void>()
@Override
public void onComplete(@NonNull Task<Void> task)
if( task.isSuccessful())
Toast.makeText(Profile.this,"Profile Updated",Toast.LENGTH_SHORT).show();


);






@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data)
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==CHOOSE_IMAGE&& data !=null && data.getData()!=null)
uriProfileImage = data.getData();
try
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),uriProfileImage);
imageView.setImageBitmap(bitmap);

uploadImageToFirebaseStorage();

catch (IOException e)
e.printStackTrace();




private void uploadImageToFirebaseStorage()
final StorageReference profileImageRef =
FirebaseStorage.getInstance().getReference("profilepics/"+System.currentTimeMillis()+".jpg");
if(uriProfileImage!=null)
profileImageRef.putFile(uriProfileImage)

.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>()
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot)
profileImageRef.getDownloadUrl().addOnSuccessListener((OnSuccessListener<? super Uri>) uriProfileImage);

)
.addOnFailureListener(new OnFailureListener()
@Override
public void onFailure(@NonNull Exception e)
Toast.makeText(Profile.this,e.getMessage(),Toast.LENGTH_SHORT).show();


);



@Override
public boolean onCreateOptionsMenu(Menu menu)
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;



@Override
public boolean onOptionsItemSelected(MenuItem item)
switch (item.getItemId())
case R.id.menuLogout:

FirebaseAuth.getInstance().signOut();
finish();
startActivity(new Intent(this,Login.class));
break;

return true;


private void showImageChooser()
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Escohe a imagem de perfil"),CHOOSE_IMAGE);










java android firebase-storage






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 32 mins ago









Michael

20.8k83472




20.8k83472










asked 38 mins ago









Gonçalo Oliveira CarvalhoGonçalo Oliveira Carvalho

24




24












  • @Michael done , i already changed

    – Gonçalo Oliveira Carvalho
    33 mins ago











  • Correct me if I'm wrong, but in the statement profileImageRef.getDownloadUrl().addOnSuccessListener((OnSuccessListener<? super Uri>) uriProfileImage), it seems like you're casting a Uri object to an instance of an OnSuccessListener. I suspect there seems to be a logical error here.

    – Karan Modi
    23 mins ago












  • @Michael thank you

    – Gonçalo Oliveira Carvalho
    19 mins ago











  • @KaranModi i am trying send a imagem to firebase storage

    – Gonçalo Oliveira Carvalho
    19 mins ago

















  • @Michael done , i already changed

    – Gonçalo Oliveira Carvalho
    33 mins ago











  • Correct me if I'm wrong, but in the statement profileImageRef.getDownloadUrl().addOnSuccessListener((OnSuccessListener<? super Uri>) uriProfileImage), it seems like you're casting a Uri object to an instance of an OnSuccessListener. I suspect there seems to be a logical error here.

    – Karan Modi
    23 mins ago












  • @Michael thank you

    – Gonçalo Oliveira Carvalho
    19 mins ago











  • @KaranModi i am trying send a imagem to firebase storage

    – Gonçalo Oliveira Carvalho
    19 mins ago
















@Michael done , i already changed

– Gonçalo Oliveira Carvalho
33 mins ago





@Michael done , i already changed

– Gonçalo Oliveira Carvalho
33 mins ago













Correct me if I'm wrong, but in the statement profileImageRef.getDownloadUrl().addOnSuccessListener((OnSuccessListener<? super Uri>) uriProfileImage), it seems like you're casting a Uri object to an instance of an OnSuccessListener. I suspect there seems to be a logical error here.

– Karan Modi
23 mins ago






Correct me if I'm wrong, but in the statement profileImageRef.getDownloadUrl().addOnSuccessListener((OnSuccessListener<? super Uri>) uriProfileImage), it seems like you're casting a Uri object to an instance of an OnSuccessListener. I suspect there seems to be a logical error here.

– Karan Modi
23 mins ago














@Michael thank you

– Gonçalo Oliveira Carvalho
19 mins ago





@Michael thank you

– Gonçalo Oliveira Carvalho
19 mins ago













@KaranModi i am trying send a imagem to firebase storage

– Gonçalo Oliveira Carvalho
19 mins ago





@KaranModi i am trying send a imagem to firebase storage

– Gonçalo Oliveira Carvalho
19 mins ago












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55001950%2funchecked-unchecked-cast-required-onsuccesslistener-found-uri%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55001950%2funchecked-unchecked-cast-required-onsuccesslistener-found-uri%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Runtime problems in TestNG asserts2019 Community Moderator ElectionHow do you assert that a certain exception is thrown in JUnit 4 tests?differences between 2 JUnit Assert classesHow do I use Assert to verify that an exception has been thrown?Best practice for Python assertWhat is the “assert” function?What does the Java assert keyword do, and when should it be used?What is the use of “assert” in Python?PHPUnit assert that an exception was thrown?What is “assert” in JavaScript?Asserting in testng using containing

1