Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add your application to the "Share" menu with monodroid

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

like image 525
Roosevelt Avatar asked Oct 03 '22 23:10

Roosevelt


1 Answers

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);
    }
}
like image 166
Roosevelt Avatar answered Oct 10 '22 02:10

Roosevelt