我使用以下示例发送一封简单的电子邮件。
https://docs.microsoft.com/en-us/xamarin/essentials/email?tabs=android
当我第一次运行xamarin表单应用程序并调用发送的方法时,出现了用于选择的应用程序弹出窗口。
我选择了Viber进行测试,什么都没发生,但是现在我无法撤消此选择。每次我打电话给发送邮件时,viber都会打开。
我尝试从设置中清除应用程序数据,然后再次取消安装该应用程序,但是我遇到了同样的问题。
我该如何解决?我可以仅使用电子邮件客户端打开一个对话框吗?
谢谢!!
答案 0 :(得分:0)
我替换了Xamarin.Essential电子邮件实施
private void takePictureAndUpload() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
}
// Continue only if the File was successfully created
if (photoFile != null) {
photoURI = FileProvider.getUriForFile(this,
"com.example.android.provider",
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
}
protected void onActivityResult(int requestCode, int resultCode, final Intent data){
super.onActivityResult(requestCode, resultCode, data);
if ((requestCode == REQUEST_IMAGE_CAPTURE) && (resultCode == Activity.RESULT_OK)){
count++;
Bitmap imageBitmap = null;
try {
imageBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(),photoURI);
} catch (IOException e) {
e.printStackTrace();
}
ByteArrayOutputStream stream = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
final byte[] imageData = stream.toByteArray();
setuId(user);
final String path = "posts/" + UUID.randomUUID() + ".jpg";
FirebaseStorage storage = FirebaseStorage.getInstance();
final StorageReference storageRef = storage.getReference();
final StorageReference imageRef = storageRef.child(path);
UploadTask uploadTask = imageRef.putBytes(imageData);
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
String ex = e.getLocalizedMessage();
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
imageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>()
{
@Override
public void onSuccess(Uri downloadUrl)
{
final String url = downloadUrl.toString();//do something with downloadurl
addPhotoUrlToDatabase(post.getImageUrl_1(), post.getImageUrl_2(), path);
}
});
}
});
}
}
与
var message = new EmailMessage
{
Subject = subject,
Body = body,
To = recipients
};
await Email.ComposeAsync(message);
现在对话框中只有可用的邮件客户端。