How to add your application to the “Share” menu with monodroid

孤人 提交于 2019-12-22 07:05:56

问题


My solution is based on this article: http://twigstechtips.blogspot.com/2011/10/android-sharing-images-or-files-through.html


回答1:


You have to add

[IntentFilter(new[]{Intent.ActionSend},Categories = new[]{Intent.CategoryDefault},DataMimeType = "image/*",Label = "Your application name")]

before your class declaration. Like this:

[Activity(Label = "Activity label", ScreenOrientation = ScreenOrientation.Portrait)]
[IntentFilter(new[]{Intent.ActionSend},Categories = new[]{Intent.CategoryDefault},DataMimeType = "image/*",Label = "Your application name")]
public class YourActivity: Activity
{

    protected override void OnCreate(Bundle savedInstanceState)
    {
        if (Intent.Action == Intent.ActionSend && Intent.Extras.ContainsKey(Intent.ExtraStream))
        {
            var fileUrl = GetFilePath((Android.Net.Uri)Intent.Extras.GetParcelable(Intent.ExtraStream));
        }
    }

    private string GetFilePath(Android.Net.Uri uri)
    {
        string[] proj = {MediaStore.Images.ImageColumns.Data};
        var cursor = ManagedQuery(uri, proj, null, null, null);
        var colIndex = cursor.GetColumnIndex(MediaStore.Images.ImageColumns.Data);
        cursor.MoveToFirst();
        return cursor.GetString(colIndex);
    }
}


来源:https://stackoverflow.com/questions/16858881/how-to-add-your-application-to-the-share-menu-with-monodroid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!