简体   繁体   English

Android 在清单上设置意图过滤器以发送邮件

[英]Android set intent filter on manifest to send mail

My simple andoroid application can be internal email sender.我的简单安卓应用程序可以是内部电子邮件发件人。 I'm trying to set some intent filter on activity on manifest to used for other application, how can i set some intent filter to have this ability?我正在尝试为清单上的活动设置一些意图过滤器以用于其他应用程序,我如何设置一些意图过滤器以具有此功能? i want to users can select my application to sending mail, I found this code, but seems it doesn't correct.我想让用户可以选择我的应用程序来发送邮件,我找到了这个代码,但似乎不正确。

<intent-filter android:label="Send Mail" android:icon="@drawable/pig">
    <data android:mimeType="text/plain"/>
    <action android:name="android.intent.action.SEND"/>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

Define intent filter in manifest在清单中定义意图过滤器

 <activity android:name="ShareActivity">
    <!-- filter for sending text; accepts SENDTO action with sms URI schemes -->
    <intent-filter>
        <action android:name="android.intent.action.SENDTO"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:scheme="sms" />
        <data android:scheme="smsto" />
    </intent-filter>
    <!-- filter for sending text or images; accepts SEND action and text or image data -->
    <intent-filter>
        <action android:name="android.intent.action.SEND"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:mimeType="image/*"/>
        <data android:mimeType="text/plain"/>
    </intent-filter>
</activity>

Handle Result in your Activity在您的活动中处理结果

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    // Get the intent that started this activity
    Intent intent = getIntent();
    Uri data = intent.getData();

    // Figure out what to do based on the intent type
    if (intent.getType().indexOf("image/") != -1) {
        // Handle intents with image data ...
    } else if (intent.getType().equals("text/plain")) {
        // Handle intents with text ...
    }
}

For more info go though the Official Documentation有关更多信息,请参阅官方文档

It works fine & everything is defined in detail.它工作正常,一切都被详细定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM