android - 我的 Android Takeaway 应用程序不会在 Gmail 中填充主题和正文,但可以与 Outlook 配合使用
问题描述
我在 Android Studio 中创建了一个 Android 外卖订购应用程序,它应该通过电子邮件发送订单并填写主题和正文字段。当我通过 Outlook 发送时它会这样做,但当我在模拟器、手机 (Android 10) 和平板电脑 (Android 7) 上使用 Android G 邮件客户端时拒绝填写这些字段 - 它只是发送一封空白电子邮件。
public void submitOrder(View view) {
submit_order_quantity = submit_order_quantity + 1;
EditText enterName = findViewById(R.id.nameBar);
String showName = enterName.getText().toString(); //gets you the contents of name edit text
EditText enterTelephone = findViewById(R.id.your_telephone);
String showPhone = enterTelephone.getText().toString(); //gets you the contents of telephone number edit text
EditText enterTime = findViewById(R.id.collect_time);
String showTime = enterTime.getText().toString(); //gets you the contents of telephone number edit text
double totalPrice = calculatePrice();
String priceMessage = createOrderSummary(showName, showPhone, showTime, totalPrice);
if(submit_order_quantity == 1 && totalPrice != 0){
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "emailaddress@email.com", null));
// only email apps should handle this
intent.putExtra(Intent.EXTRA_SUBJECT, Restaurant Order for: + showName);
intent.putExtra(Intent.EXTRA_TEXT, priceMessage);
startActivity(Intent.createChooser(intent, "Send email..."));
}
}
外卖订单应用程序。
showName 是 EditText enterName 的 toString 结果
showPhone 是 EditText enterTelephone 的 toString 结果
showTime 是 EditText enterTime 的 toString 结果
totalPrice 是项目价格乘以每个项目的数量的结果,作为一系列字符串创建 priceMessage
清单:-
<queries>
<!--
Specific intents you query for,
eg: for a custom share UI
-->
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="image/jpeg" />
</intent>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="*/*" />
</intent>
<intent>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
</intent>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:scheme="mailto" />
</intent>
<intent>
<action android:name="android.intent.action.SENDTO" />
<data android:mimeType="*/*" />
</intent>
<intent>
<action android:name="android.intent.action.SENDTO" />
<data android:mimeType="text/plain" />
</intent>
<intent>
<action android:name="android.intent.action.SEND"/>
<data android:mimeType="application/vnd.google.panorama360+jpg"/>
</intent>
<intent>
<action android:name="android.intent.action.SEND_MULTIPLE"/>
<data android:mimeType="image/*"/>
</intent>
<intent>
<action android:name="android.intent.action.SEND_MULTIPLE"/>
<data android:mimeType="video/*"/>
</intent>
</queries>
<application
android:allowBackup="true"
android:fullBackupContent="@xml/my_backup_rules"
android:icon="@mipmap/app_logo"
android:label="@string/app_name"
android:roundIcon="@mipmap/app_logo_round"
android:supportsRtl="true"
android:theme="@style/Theme.TakeawayFood">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="message/rfc822" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Starters"
android:label="@string/app_name"
android:parentActivityName=".MainActivity">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".Mains"
android:label="@string/app_name"
android:parentActivityName=".MainActivity">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".Desserts"
android:label="@string/app_name"
android:parentActivityName=".MainActivity">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
</application>
解决方案
像这样创建您的意图,这对我的应用程序共享到 Gmail 有用:
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"emailaddress@email.com"});
...