20

ボタンをメールアプリにリンクしようとしています。メールを送信するのではなく、受信トレイを開くだけです。

でこれを行う必要がありIntent intent = new Intent(...)ますか?

もしそうなら、間に何があるべき( )ですか?

4

13 に答える 13

39

目標がデフォルトのメール アプリを開いて受信トレイを表示することである場合、キーはインテント カテゴリを追加し、次のように ACTION_MAIN インテントを使用することです。

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_APP_EMAIL);
getActivity().startActivity(intent);

https://developer.android.com/reference/android/content/Intent.html#CATEGORY_APP_EMAIL

于 2015-07-23T17:58:16.077 に答える
8

このコードは私のために働いた。デバイスに登録されたすべての電子メール アプリを含むピッカーが開き、受信トレイに直接送信されます。

Intent emailIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:"));
    PackageManager pm = getPackageManager();

    List<ResolveInfo> resInfo = pm.queryIntentActivities(emailIntent, 0);
    if (resInfo.size() > 0) {
        ResolveInfo ri = resInfo.get(0);
        // First create an intent with only the package name of the first registered email app
        // and build a picked based on it
        Intent intentChooser = pm.getLaunchIntentForPackage(ri.activityInfo.packageName);
        Intent openInChooser =
                Intent.createChooser(intentChooser,
                        getString(R.string.user_reg_email_client_chooser_title));

        // Then create a list of LabeledIntent for the rest of the registered email apps 
        List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
        for (int i = 1; i < resInfo.size(); i++) {
            // Extract the label and repackage it in a LabeledIntent
            ri = resInfo.get(i);
            String packageName = ri.activityInfo.packageName;
            Intent intent = pm.getLaunchIntentForPackage(packageName);
            intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
        }

        LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);
        // Add the rest of the email apps to the picker selection
        openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
        startActivity(openInChooser);
    }
于 2015-01-28T10:40:53.277 に答える
6

デバイスのデフォルトのメールが設定されていない場合にクラッシュを回避するための提案はありますか?

はい、Androidのデフォルトのメール受信ボックスを開くことは可能です。
このコードを使用します:

Intent intent = getPackageManager().getLaunchIntentForPackage("com.android.email");
startActivity(intent);


このコードは機能します。最初にAndroidデバイスのデフォルトのメールを設定する必要があります。すでにメールを設定している場合は、正常に機能します。それ以外の場合は、強制的に閉じますNullPointerException

于 2011-11-29T09:16:12.067 に答える
1
  You can use this but it is for gmail only

  Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);  
  emailIntent.setType("plain/text");
  startActivity(emailIntent); 
于 2011-11-12T05:39:59.907 に答える
0

残念ながら、有望には見えません。これは以前質問された

電子メール クライアントを直接起動して受信トレイ ビューを表示するにはどうすればよいですか?

電子メール クライアントを作成モードで開くことはできますが、すでにそれを知っているようです。

于 2011-11-11T19:41:23.050 に答える
-2

これを使用して、Android の既定の電子メール クライアントを開くことができます。

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.setClassName("com.android.email", "com.android.email.activity.Welcome");
emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(emailIntent);
于 2012-10-29T12:54:32.793 に答える