2016-12-28 11 views
2

在這個應用程序中,我想要的是每當用戶從任何fotos應用程序中選擇和共享圖像時,我希望我的應用程序被列在共享應用程序列表中。 這是我處理這種隱含的行爲意圖。Xamarin Android處理隱含意圖的actionsend mimetype圖像

[IntentFilter(new string[] { Intent.ActionView }, 
Categories = new string[] { Intent.ActionDefault, Intent.CategoryBrowsable, 
Intent.ActionSend, Intent.ActionSendMultiple }, 
DataScheme = "mimetype", 
DataPathPattern = "*/*", 
DataHost = "*.*")] 

爲了處理這種圖像或圖像這是我發現的,

Intent intent = Intent; 

String action = intent.Action; 

String type = intent.Type; 

if (Intent.ActionSend.Equals(action) && type != null) 
{ 

    if (type.StartsWith("image/")) 
    { 
      tv.Text = "single image sharable"; 
      //handleSendImage(intent); // Handle single image being sent 

    } 

} 
else if (Intent.ActionSendMultiple.Equals(action) && type != null) 
{ 

    if (type.StartsWith("image/")) 
    { 
     tv.Text = "multiple images sharable"; 
     //handleSendMultipleImages(intent); // Handle multiple images being sent 
    } 
} 

這裏我現在嘗試從庫共享圖像,但我沒有看到我在列表中的應用程序。 因此,意圖過濾器中必須有錯誤。

+1

列出的意圖過濾器包含錯誤的類別。而不是「Categories = new string [] {Intent.ActionDefault}」,它應該是Intent.CategoryDe​​fault。 – kg743

回答

2

IntentFilter實例共享單個或多個圖片:

[IntentFilter(
    new string[] { Intent.ActionSend }, 
    Categories = new string[] { Intent.CategoryDefault }, 
    DataMimeType = "image/*" 
)] 
[IntentFilter(
    new string[] { Intent.ActionSendMultiple }, 
    Categories = new string[] { Intent.CategoryDefault }, 
    DataMimeType = "image/*" 
)] 
[Activity(Label = "Share data to this activity", MainLauncher = true, Icon = "@mipmap/icon")] 
public class MainActivity : Activity 
{ 
    protected override void OnCreate(Bundle savedInstanceState) 
    { 
     base.OnCreate(savedInstanceState); 

     if (Intent.Action == Intent.ActionSend) 
     { 
      Log.Debug("Share", Intent.Type); 
     } 
     else if (Intent.Action == Intent.ActionSendMultiple) 
     { 
      Log.Debug("Share", Intent.Type); 
     } 
    } 
} 

注意:當使用基於類的AndroidManifestAttributes,我強烈建議您查看在Debug|Release目錄中生成AndroidManifest.xml,以確保您的生成正確的條目。

YourAndroidProjectDirectory/Debug/android/manifest/AndroidManifest.xml