Androidアプリからメールを送信しようとしています。ボタンをクリックすると、Gmailが開き、以前に定義した受信者、件名、メール本文を含む新しいメールが表示されます。これまでのところ、Intent.ACTION_VIEWとIntent.ACTION_SENDTOを送信してみました。どちらも受信者にのみ下書きを表示します。件名とメッセージの両方が抑圧されています。奇妙なのは、エミュレーターを使用しているときにうまく機能することです。また、 Android errorlogでロックしようとしています。許可がないようです。それは本当に許可の問題なのでしょうか、それとも何か別の問題なのでしょうか?応援よろしくお願いします
これが私のコードです:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:" + to));
intent.putExtra(intent.EXTRA_SUBJECT, subject);
intent.putExtra(intent.EXTRA_TEXT, message);
mainActivity.startActivity(intent);
Intent email = new Intent(Intent.ACTION_SENDTO);
email.setType("message/rfc822");
email.putExtra(Intent.EXTRA_EMAIL, new String[]{to});
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, message);
mainActivity.startActivity(Intent.createChooser(email, "Choose an Email client :"));
2019-12-13 01:30:35.172 29268-29268/? E//system/bin/webview_zygote32: failed to make and chown /acct/uid_99044: Permission denied
2019-12-13 01:30:35.172 29268-29268/? E/Zygote: createProcessGroup(99044, 0) failed: Permission denied
2019-12-13 01:30:35.206 29289-29289/? E/asset: setgid: Operation not permitted
2019-12-13 01:30:35.226 29296-29296/? E/asset: setgid: Operation not permitted
2019-12-13 01:30:35.355 29268-29268/? E/Typeface: Error mapping font file /system/fonts/NotoSansKhmer-Regular.ttf
2019-12-13 01:30:35.356 29268-29268/? E/Typeface: Error mapping font file /system/fonts/NotoSansKhmer-Bold.ttf
2019-12-13 01:30:35.356 29268-29268/? E/Minikin: Could not get cmap table size!
2019-12-13 01:30:35.356 29268-29268/? E/Typeface: Unable to load Family: null:und-Khmr
2019-12-13 01:30:35.484 29268-29268/? E/Typeface: Error mapping font file /system/fonts/LGAka_Light.ttf
2019-12-13 01:30:35.484 29268-29268/? E/Minikin: Could not get cmap table size!
2019-12-13 01:30:35.484 29268-29268/? E/Typeface: Unable to load Family: lg-lgaka:null
2019-12-13 01:30:35.816 29342-29342/? E//system/bin/webview_zygote32: failed to make and chown /acct/uid_99045: Permission denied
2019-12-13 01:30:35.816 29342-29342/? E/Zygote: createProcessGroup(99045, 0) failed: Permission denied
2019-12-13 01:30:35.842 29354-29354/? E/asset: setgid: Operation not permitted
2019-12-13 01:30:35.864 29367-29367/? E/asset: setgid: Operation not permitted
2019-12-13 01:30:36.139 29342-29342/? E/Typeface: Error mapping font file /system/fonts/NotoSansKhmer-Regular.ttf
2019-12-13 01:30:36.139 29342-29342/? E/Typeface: Error mapping font file /system/fonts/NotoSansKhmer-Bold.ttf
2019-12-13 01:30:36.139 29342-29342/? E/Minikin: Could not get cmap table size!
2019-12-13 01:30:36.139 29342-29342/? E/Typeface: Unable to load Family: null:und-Khmr
2019-12-13 01:30:36.362 29342-29342/? E/Typeface: Error mapping font file /system/fonts/LGAka_Light.ttf
2019-12-13 01:30:36.362 29342-29342/? E/Minikin: Could not get cmap table size!
2019-12-13 01:30:36.362 29342-29342/? E/Typeface: Unable to load Family: lg-lgaka:null
2019-12-13 01:30:36.523 4349-4359/? E/GBMv2: FPS Scaler: EXP
2019-12-13 01:30:36.602 29342-29342/? E/WebViewFactory: can't load with relro file; address space not reserved
2019-12-13 01:30:37.058 29220-29220/? E/Gmail: Gmail:EditWebView JS Console: b/119949571:draft.editor.onLoad; source: file:///Android_asset/draft_editor_gmail_compiled.js at 89
2019-12-13 01:30:37.146 29220-29220/? E/Gmail: Gmail:EditWebView JS Console: b/119949571:draft.editor.onLoad is finished; source: file:///Android_asset/draft_editor_gmail_compiled.js at 90
メールの古いコードは数日前に機能しなくなりました。
それは次のとおりでした:
public static void shareTextToEmail(Context context, String[] email, String subject, String text)
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + TextUtils.join(",", email)));
emailIntent.putExtra(Intent.EXTRA_EMAIL, email);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, text);
try {
context.startActivity(Intent.createChooser(emailIntent, context.getString(R.string.share_email_title)));
} catch (Android.content.ActivityNotFoundException e) {
Toast.makeText(context, context.getString(R.string.share_no_intent_handler_found), Toast.LENGTH_SHORT).show();
}
}
Zak.Antonioの回答に従ってそれを採用しました:
public static void shareTextToEmail(Context context, String[] email, String subject, String text)
Intent selectorIntent = new Intent(Intent.ACTION_SENDTO);
selectorIntent.setData(Uri.parse("mailto:"));
final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, email);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, text);
emailIntent.setSelector(selectorIntent);
try {
context.startActivity(Intent.createChooser(emailIntent, context.getString(R.string.share_email_title)));
} catch (Android.content.ActivityNotFoundException e) {
Toast.makeText(context, context.getString(R.string.share_no_intent_handler_found), Toast.LENGTH_SHORT).show();
}
}
重要な点は次のとおりです。
Intent.ACTION_SENDTO
とIntent.ACTION_SEND
in emailIntent
Intent.ACTION_SENDTO
をselectorIntent
にIntent.EXTRA_EMAIL
このコードを試してください
val emailIntent = Intent(Intent.ACTION_SEND)
emailIntent.setType("text/plain")
emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf("[email protected]"))
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Email subject")
emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message text")
val packageManager = packageManager
val activities = packageManager.queryIntentActivities(emailIntent, 0)
val isIntentSafe = activities.size > 0
if (isIntentSafe) {
startActivity(emailIntent);
}else{
Log.d("MainActivty","Email App not installed");
}