2016-09-20 23 views
-3

我簡單的andoroid應用程序可以是內部電子郵件發件人。我試圖設置一些意向過濾器對清單上的活動用於其他應用程序,我如何設置一些意向過濾器來擁有這種能力?我想讓用戶可以選擇我的應用程序來發送郵件,我發現這個代碼,但似乎它不正確。安卓設置意向過濾器清單發送郵件

<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> 

回答

-1

定義意圖過濾清單中

<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> 

手柄導致您的活動

@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 ... 
    } 
} 

欲瞭解更多信息請儘管Official Documentation

它工作正常&一切都在定義詳情。

+0

''可以用於電子郵件嗎? –

+0

沒有它發送短信的目的,實際上我用這個作爲共享的目的,因爲這個動作是爲了分享。您可以根據您的要求排除這部分。 –