|
//Classe do projeto android |
|
[assembly: Xamarin.Forms.Dependency(typeof(Share))] |
|
namespace FindenApp.Droid.Helpers |
|
{ |
|
public class Share : FindenApp.Helpers.IShare |
|
{ |
|
private readonly Context _context; |
|
public Share() |
|
{ |
|
//_context = Android.App.Application.Context; |
|
_context = Application.Context; |
|
} |
|
|
|
public Task Show(string title, string message, string filePath) |
|
{ |
|
var extension = filePath.Substring(filePath.LastIndexOf(".") + 1).ToLower(); |
|
var contentType = string.Empty; |
|
|
|
// verifica a extensão do arquivo |
|
switch (extension) |
|
{ |
|
case "pdf": |
|
contentType = "application/pdf"; |
|
break; |
|
case "png": |
|
contentType = "image/png"; |
|
break; |
|
default: |
|
contentType = "text/plain"; |
|
break; |
|
} |
|
|
|
var intent = new Intent(Intent.ActionSend); |
|
intent.SetType(contentType); |
|
//FILE |
|
//intent.PutExtra(Intent.ExtraStream, Uri.Parse("file://" + filePath)); |
|
//URL |
|
intent.AddFlags(ActivityFlags.ClearWhenTaskReset); |
|
//intent.PutExtra(Intent.ExtraText, string.Empty); |
|
intent.PutExtra(Intent.ExtraText, filePath); |
|
intent.PutExtra(Intent.ExtraSubject, message); |
|
|
|
var chooserIntent = Intent.CreateChooser(intent, title ?? string.Empty); |
|
chooserIntent.SetFlags(ActivityFlags.ClearTop); |
|
chooserIntent.SetFlags(ActivityFlags.NewTask); |
|
_context.StartActivity(chooserIntent); |
|
|
|
return Task.FromResult(true); |
|
} |
|
} |
|
} |