Android アプリに問題があります。別のインテントが終了したときにインテントを開始する必要があります。問題は、両方のインテントが同時に起動されることです (理由はわかりません)。これが私のコードです:
このダイアログでは、ユーザーがメールを送信する前に写真を撮りたいかどうかを尋ねます (もちろん、写真付きのメールを送信したいです)。Ok?
private Dialog comprobarFoto() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("¿Desea adjuntar una foto con este mensaje de su posición actual?");
builder.setPositiveButton("Si", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
hacerFoto();
enviarMail(true);
dialog.cancel();
}
});
builder.setNegativeButton("No", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
enviarMail(false);
dialog.cancel();
}
});
return builder.create();
}
これが私がメールを作成する方法です
private void enviarMail(boolean foto) {
if(locMail!=null) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_SUBJECT,"Quiero que sepas donde estoy!");
if(foto && fotoPath != null && fotoPath.length()>0) {
i.putExtra(Intent.EXTRA_STREAM, Uri.parse(fotoPath));
}
i.putExtra(Intent.EXTRA_TEXT,"Hola!\n Estoy en la dirección:" +
"\n" + localizarDireccion() +
"\n\n(lat= " + dfmail.format(locMail.getLatitude()) + ")" +
"\n(long=" + dfmail.format(locMail.getLongitude()) + ") " +
"\n \n[Enviado desde GeoLocation]" );
startActivity(i);
}else{
dialogError("No se puede encontrar una localización").show();
}
}
そして、これは私が写真を撮る方法です:
private void hacerFoto() {
//El gran quebradero de cabeza aquí fue que no le daba permisos a la aplicación para escribir en la tarjeta. En el manifest se puede comprobar esta directiva
File carpeta = new File(Environment.getExternalStorageDirectory () + "/GeoLocation/images");
if(!carpeta.exists()){
carpeta.mkdirs();
}
fotoPath = Environment.getExternalStorageDirectory() + "/GeoLocation/images/GLPict"+cogerFecha()+".jpg";
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri output = Uri.fromFile(new File(fotoPath));
intent.putExtra(MediaStore.EXTRA_OUTPUT, output);
startActivityForResult(intent, 1);
}
問題は、sendMail (enviarMail) の意図が、最初のメソッド takePhoto (hacerFoto) が終了するのを待たないことです。メソッド takePhoto が終了するまで待つように sendMail の意図を伝えるメソッドはありますか?
すべてに感謝し、私の英語で申し訳ありません!!!