Send file to another app from a list of apps in xamarin & android










0















I can't figure how send a file to shared in others apps, that I need to filter from a small list of it. I have read several tutorials and answers (like Share file to another app (whatsapp, telegram, gmail)) with no success:



override this.OnCreate (bundle) =

base.OnCreate (bundle)
this.SetContentView (Resources.Layout.Main)

let button = this.FindViewById<Button>(Resources.Id.myButton)
button.Click.Add (fun args ->
let fileName = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments)
let fileName = Path.Combine([|fileName; "AboutAssets.txt"|]) |> Path.GetFullPath
this.Launch(fileName)
)

member this.Launch(fileName:string) =

let context = Android.App.Application.Context
let getUri file =
Android.Support.V4.Content.FileProvider.GetUriForFile(context, Android.App.Application.Context.PackageName + ".provider", file)

let file = new Java.IO.File(fileName)
let path = getUri file
let extension = Android.Webkit.MimeTypeMap.GetFileExtensionFromUrl(path.ToString())
let fileMime = Android.Webkit.MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension)

let intent = new Android.Content.Intent(Android.Content.Intent.ActionSend)
intent.SetFlags(Android.Content.ActivityFlags.ClearTop) |> ignore
intent.SetFlags(Android.Content.ActivityFlags.NewTask) |> ignore
intent.SetType("*/*") |> ignore

let apps = [| "excel"; "mail"; "gmail"; "whatsapp"; "dropbox"; "drive" |]

let findApps() =
let packageManager = context.PackageManager
let resInfo = packageManager.QueryIntentActivities(intent, Android.Content.PM.PackageInfoFlags.Activities)

let targetedShareIntents = new ResizeArray<IParcelable>()

let pkgs = seq
for info in resInfo do
let namePkg = info.ActivityInfo.PackageName.ToLower()
let nameApp = info.ActivityInfo.Name.ToLower()

let label = info.LoadLabel(packageManager)
let icon = info.Icon;


for app in apps do
if nameApp.Contains(app)

for (app, info) in pkgs |> Seq.distinct do
let label = info.LoadLabel(packageManager)
let icon = info.Icon;

let targetedShare = new Android.Content.Intent(Android.Content.Intent.ActionSend)

if app.Contains("email") then
targetedShare.SetType("message/rfc822") |> ignore //not work
else
targetedShare.SetType(fileMime) |> ignore
targetedShare.SetType(fileMime) |> ignore

targetedShare.PutExtra(Android.Content.Intent.ExtraText, "My body of post/email") |> ignore
targetedShare.AddFlags(Android.Content.ActivityFlags.GrantReadUriPermission) |> ignore

targetedShare.PutExtra(Android.Content.Intent.ExtraStream, path) |> ignore
targetedShare.SetData(path)|> ignore
targetedShare.SetFlags(Android.Content.ActivityFlags.ClearTop) |> ignore
targetedShare.SetFlags(Android.Content.ActivityFlags.NewTask) |> ignore

//targetedShare.SetData(uri) |> ignore
let label = new Android.Content.PM.LabeledIntent(targetedShare, info.ActivityInfo.PackageName, label, icon)
targetedShareIntents.Add(label) |> ignore

targetedShareIntents

let apps = findApps()
printf "%A" apps


Android.Content.Intent(Android.Content.Intent.ExtraInitialIntents, apps)



 let chooser = Android.Content.Intent.CreateChooser(intent, "Choose App")
chooser.PutExtra(Android.Content.Intent.ExtraInitialIntents, apps.ToArray()) |> ignore

chooser.SetFlags(Android.Content.ActivityFlags.ClearTop)|> ignore
chooser.SetFlags(Android.Content.ActivityFlags.NewTask) |> ignore

context.StartActivity(chooser)


When I open gmail, the file not show, and not error is displayed. When open Google Drive it say "Upload was not sucessfull, request contained no data"



P.D: The config:



<provider android:name="android.support.v4.content.FileProvider" android:authorities="com.companyname.basura.provider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" />
</provider>


And provider_paths:



<?xml version="1.0" encoding="UTF-8" ?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="files" path="."/>
</paths>









share|improve this question
























  • What does your FileProvider in your manifest look like?

    – SushiHangover
    Nov 15 '18 at 17:12












  • Hard code the package name in the authorities and "assuming" your provider_paths is exporting the proper name/path.

    – SushiHangover
    Nov 15 '18 at 17:17











  • I do the changes, as edited, with the same results.

    – mamcx
    Nov 15 '18 at 18:32















0















I can't figure how send a file to shared in others apps, that I need to filter from a small list of it. I have read several tutorials and answers (like Share file to another app (whatsapp, telegram, gmail)) with no success:



override this.OnCreate (bundle) =

base.OnCreate (bundle)
this.SetContentView (Resources.Layout.Main)

let button = this.FindViewById<Button>(Resources.Id.myButton)
button.Click.Add (fun args ->
let fileName = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments)
let fileName = Path.Combine([|fileName; "AboutAssets.txt"|]) |> Path.GetFullPath
this.Launch(fileName)
)

member this.Launch(fileName:string) =

let context = Android.App.Application.Context
let getUri file =
Android.Support.V4.Content.FileProvider.GetUriForFile(context, Android.App.Application.Context.PackageName + ".provider", file)

let file = new Java.IO.File(fileName)
let path = getUri file
let extension = Android.Webkit.MimeTypeMap.GetFileExtensionFromUrl(path.ToString())
let fileMime = Android.Webkit.MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension)

let intent = new Android.Content.Intent(Android.Content.Intent.ActionSend)
intent.SetFlags(Android.Content.ActivityFlags.ClearTop) |> ignore
intent.SetFlags(Android.Content.ActivityFlags.NewTask) |> ignore
intent.SetType("*/*") |> ignore

let apps = [| "excel"; "mail"; "gmail"; "whatsapp"; "dropbox"; "drive" |]

let findApps() =
let packageManager = context.PackageManager
let resInfo = packageManager.QueryIntentActivities(intent, Android.Content.PM.PackageInfoFlags.Activities)

let targetedShareIntents = new ResizeArray<IParcelable>()

let pkgs = seq
for info in resInfo do
let namePkg = info.ActivityInfo.PackageName.ToLower()
let nameApp = info.ActivityInfo.Name.ToLower()

let label = info.LoadLabel(packageManager)
let icon = info.Icon;


for app in apps do
if nameApp.Contains(app)

for (app, info) in pkgs |> Seq.distinct do
let label = info.LoadLabel(packageManager)
let icon = info.Icon;

let targetedShare = new Android.Content.Intent(Android.Content.Intent.ActionSend)

if app.Contains("email") then
targetedShare.SetType("message/rfc822") |> ignore //not work
else
targetedShare.SetType(fileMime) |> ignore
targetedShare.SetType(fileMime) |> ignore

targetedShare.PutExtra(Android.Content.Intent.ExtraText, "My body of post/email") |> ignore
targetedShare.AddFlags(Android.Content.ActivityFlags.GrantReadUriPermission) |> ignore

targetedShare.PutExtra(Android.Content.Intent.ExtraStream, path) |> ignore
targetedShare.SetData(path)|> ignore
targetedShare.SetFlags(Android.Content.ActivityFlags.ClearTop) |> ignore
targetedShare.SetFlags(Android.Content.ActivityFlags.NewTask) |> ignore

//targetedShare.SetData(uri) |> ignore
let label = new Android.Content.PM.LabeledIntent(targetedShare, info.ActivityInfo.PackageName, label, icon)
targetedShareIntents.Add(label) |> ignore

targetedShareIntents

let apps = findApps()
printf "%A" apps


Android.Content.Intent(Android.Content.Intent.ExtraInitialIntents, apps)



 let chooser = Android.Content.Intent.CreateChooser(intent, "Choose App")
chooser.PutExtra(Android.Content.Intent.ExtraInitialIntents, apps.ToArray()) |> ignore

chooser.SetFlags(Android.Content.ActivityFlags.ClearTop)|> ignore
chooser.SetFlags(Android.Content.ActivityFlags.NewTask) |> ignore

context.StartActivity(chooser)


When I open gmail, the file not show, and not error is displayed. When open Google Drive it say "Upload was not sucessfull, request contained no data"



P.D: The config:



<provider android:name="android.support.v4.content.FileProvider" android:authorities="com.companyname.basura.provider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" />
</provider>


And provider_paths:



<?xml version="1.0" encoding="UTF-8" ?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="files" path="."/>
</paths>









share|improve this question
























  • What does your FileProvider in your manifest look like?

    – SushiHangover
    Nov 15 '18 at 17:12












  • Hard code the package name in the authorities and "assuming" your provider_paths is exporting the proper name/path.

    – SushiHangover
    Nov 15 '18 at 17:17











  • I do the changes, as edited, with the same results.

    – mamcx
    Nov 15 '18 at 18:32













0












0








0








I can't figure how send a file to shared in others apps, that I need to filter from a small list of it. I have read several tutorials and answers (like Share file to another app (whatsapp, telegram, gmail)) with no success:



override this.OnCreate (bundle) =

base.OnCreate (bundle)
this.SetContentView (Resources.Layout.Main)

let button = this.FindViewById<Button>(Resources.Id.myButton)
button.Click.Add (fun args ->
let fileName = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments)
let fileName = Path.Combine([|fileName; "AboutAssets.txt"|]) |> Path.GetFullPath
this.Launch(fileName)
)

member this.Launch(fileName:string) =

let context = Android.App.Application.Context
let getUri file =
Android.Support.V4.Content.FileProvider.GetUriForFile(context, Android.App.Application.Context.PackageName + ".provider", file)

let file = new Java.IO.File(fileName)
let path = getUri file
let extension = Android.Webkit.MimeTypeMap.GetFileExtensionFromUrl(path.ToString())
let fileMime = Android.Webkit.MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension)

let intent = new Android.Content.Intent(Android.Content.Intent.ActionSend)
intent.SetFlags(Android.Content.ActivityFlags.ClearTop) |> ignore
intent.SetFlags(Android.Content.ActivityFlags.NewTask) |> ignore
intent.SetType("*/*") |> ignore

let apps = [| "excel"; "mail"; "gmail"; "whatsapp"; "dropbox"; "drive" |]

let findApps() =
let packageManager = context.PackageManager
let resInfo = packageManager.QueryIntentActivities(intent, Android.Content.PM.PackageInfoFlags.Activities)

let targetedShareIntents = new ResizeArray<IParcelable>()

let pkgs = seq
for info in resInfo do
let namePkg = info.ActivityInfo.PackageName.ToLower()
let nameApp = info.ActivityInfo.Name.ToLower()

let label = info.LoadLabel(packageManager)
let icon = info.Icon;


for app in apps do
if nameApp.Contains(app)

for (app, info) in pkgs |> Seq.distinct do
let label = info.LoadLabel(packageManager)
let icon = info.Icon;

let targetedShare = new Android.Content.Intent(Android.Content.Intent.ActionSend)

if app.Contains("email") then
targetedShare.SetType("message/rfc822") |> ignore //not work
else
targetedShare.SetType(fileMime) |> ignore
targetedShare.SetType(fileMime) |> ignore

targetedShare.PutExtra(Android.Content.Intent.ExtraText, "My body of post/email") |> ignore
targetedShare.AddFlags(Android.Content.ActivityFlags.GrantReadUriPermission) |> ignore

targetedShare.PutExtra(Android.Content.Intent.ExtraStream, path) |> ignore
targetedShare.SetData(path)|> ignore
targetedShare.SetFlags(Android.Content.ActivityFlags.ClearTop) |> ignore
targetedShare.SetFlags(Android.Content.ActivityFlags.NewTask) |> ignore

//targetedShare.SetData(uri) |> ignore
let label = new Android.Content.PM.LabeledIntent(targetedShare, info.ActivityInfo.PackageName, label, icon)
targetedShareIntents.Add(label) |> ignore

targetedShareIntents

let apps = findApps()
printf "%A" apps


Android.Content.Intent(Android.Content.Intent.ExtraInitialIntents, apps)



 let chooser = Android.Content.Intent.CreateChooser(intent, "Choose App")
chooser.PutExtra(Android.Content.Intent.ExtraInitialIntents, apps.ToArray()) |> ignore

chooser.SetFlags(Android.Content.ActivityFlags.ClearTop)|> ignore
chooser.SetFlags(Android.Content.ActivityFlags.NewTask) |> ignore

context.StartActivity(chooser)


When I open gmail, the file not show, and not error is displayed. When open Google Drive it say "Upload was not sucessfull, request contained no data"



P.D: The config:



<provider android:name="android.support.v4.content.FileProvider" android:authorities="com.companyname.basura.provider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" />
</provider>


And provider_paths:



<?xml version="1.0" encoding="UTF-8" ?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="files" path="."/>
</paths>









share|improve this question
















I can't figure how send a file to shared in others apps, that I need to filter from a small list of it. I have read several tutorials and answers (like Share file to another app (whatsapp, telegram, gmail)) with no success:



override this.OnCreate (bundle) =

base.OnCreate (bundle)
this.SetContentView (Resources.Layout.Main)

let button = this.FindViewById<Button>(Resources.Id.myButton)
button.Click.Add (fun args ->
let fileName = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments)
let fileName = Path.Combine([|fileName; "AboutAssets.txt"|]) |> Path.GetFullPath
this.Launch(fileName)
)

member this.Launch(fileName:string) =

let context = Android.App.Application.Context
let getUri file =
Android.Support.V4.Content.FileProvider.GetUriForFile(context, Android.App.Application.Context.PackageName + ".provider", file)

let file = new Java.IO.File(fileName)
let path = getUri file
let extension = Android.Webkit.MimeTypeMap.GetFileExtensionFromUrl(path.ToString())
let fileMime = Android.Webkit.MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension)

let intent = new Android.Content.Intent(Android.Content.Intent.ActionSend)
intent.SetFlags(Android.Content.ActivityFlags.ClearTop) |> ignore
intent.SetFlags(Android.Content.ActivityFlags.NewTask) |> ignore
intent.SetType("*/*") |> ignore

let apps = [| "excel"; "mail"; "gmail"; "whatsapp"; "dropbox"; "drive" |]

let findApps() =
let packageManager = context.PackageManager
let resInfo = packageManager.QueryIntentActivities(intent, Android.Content.PM.PackageInfoFlags.Activities)

let targetedShareIntents = new ResizeArray<IParcelable>()

let pkgs = seq
for info in resInfo do
let namePkg = info.ActivityInfo.PackageName.ToLower()
let nameApp = info.ActivityInfo.Name.ToLower()

let label = info.LoadLabel(packageManager)
let icon = info.Icon;


for app in apps do
if nameApp.Contains(app)

for (app, info) in pkgs |> Seq.distinct do
let label = info.LoadLabel(packageManager)
let icon = info.Icon;

let targetedShare = new Android.Content.Intent(Android.Content.Intent.ActionSend)

if app.Contains("email") then
targetedShare.SetType("message/rfc822") |> ignore //not work
else
targetedShare.SetType(fileMime) |> ignore
targetedShare.SetType(fileMime) |> ignore

targetedShare.PutExtra(Android.Content.Intent.ExtraText, "My body of post/email") |> ignore
targetedShare.AddFlags(Android.Content.ActivityFlags.GrantReadUriPermission) |> ignore

targetedShare.PutExtra(Android.Content.Intent.ExtraStream, path) |> ignore
targetedShare.SetData(path)|> ignore
targetedShare.SetFlags(Android.Content.ActivityFlags.ClearTop) |> ignore
targetedShare.SetFlags(Android.Content.ActivityFlags.NewTask) |> ignore

//targetedShare.SetData(uri) |> ignore
let label = new Android.Content.PM.LabeledIntent(targetedShare, info.ActivityInfo.PackageName, label, icon)
targetedShareIntents.Add(label) |> ignore

targetedShareIntents

let apps = findApps()
printf "%A" apps


Android.Content.Intent(Android.Content.Intent.ExtraInitialIntents, apps)



 let chooser = Android.Content.Intent.CreateChooser(intent, "Choose App")
chooser.PutExtra(Android.Content.Intent.ExtraInitialIntents, apps.ToArray()) |> ignore

chooser.SetFlags(Android.Content.ActivityFlags.ClearTop)|> ignore
chooser.SetFlags(Android.Content.ActivityFlags.NewTask) |> ignore

context.StartActivity(chooser)


When I open gmail, the file not show, and not error is displayed. When open Google Drive it say "Upload was not sucessfull, request contained no data"



P.D: The config:



<provider android:name="android.support.v4.content.FileProvider" android:authorities="com.companyname.basura.provider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" />
</provider>


And provider_paths:



<?xml version="1.0" encoding="UTF-8" ?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="files" path="."/>
</paths>






android xamarin android-intent f# xamarin.android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 18:31







mamcx

















asked Nov 15 '18 at 16:59









mamcxmamcx

7,2102179150




7,2102179150












  • What does your FileProvider in your manifest look like?

    – SushiHangover
    Nov 15 '18 at 17:12












  • Hard code the package name in the authorities and "assuming" your provider_paths is exporting the proper name/path.

    – SushiHangover
    Nov 15 '18 at 17:17











  • I do the changes, as edited, with the same results.

    – mamcx
    Nov 15 '18 at 18:32

















  • What does your FileProvider in your manifest look like?

    – SushiHangover
    Nov 15 '18 at 17:12












  • Hard code the package name in the authorities and "assuming" your provider_paths is exporting the proper name/path.

    – SushiHangover
    Nov 15 '18 at 17:17











  • I do the changes, as edited, with the same results.

    – mamcx
    Nov 15 '18 at 18:32
















What does your FileProvider in your manifest look like?

– SushiHangover
Nov 15 '18 at 17:12






What does your FileProvider in your manifest look like?

– SushiHangover
Nov 15 '18 at 17:12














Hard code the package name in the authorities and "assuming" your provider_paths is exporting the proper name/path.

– SushiHangover
Nov 15 '18 at 17:17





Hard code the package name in the authorities and "assuming" your provider_paths is exporting the proper name/path.

– SushiHangover
Nov 15 '18 at 17:17













I do the changes, as edited, with the same results.

– mamcx
Nov 15 '18 at 18:32





I do the changes, as edited, with the same results.

– mamcx
Nov 15 '18 at 18:32












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53324460%2fsend-file-to-another-app-from-a-list-of-apps-in-xamarin-android%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53324460%2fsend-file-to-another-app-from-a-list-of-apps-in-xamarin-android%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto