Last active
August 19, 2017 14:05
-
-
Save donaldsteele/62fedda23c5cf8c26c4d8a0476d3741a to your computer and use it in GitHub Desktop.
Xamarin example to receive url or text from other applications. For example when you are on the youtube app and click share.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Android.App; | |
using Android.Widget; | |
using Android.OS; | |
using Android.Content; | |
using System.Text; | |
using System; | |
namespace AndroidDataReceiver | |
{ | |
[Activity(Label = "AndroidDataReceiver", MainLauncher = true, LaunchMode = Android.Content.PM.LaunchMode.SingleTop )] | |
[BroadcastReceiver] | |
[IntentFilter(new[] { Intent.ActionSend }, Categories = new[] { | |
Intent.CategoryDefault, | |
Intent.CategoryBrowsable | |
}, DataMimeType = "text/plain")] | |
public class MainActivity : Activity | |
{ | |
protected override void OnCreate(Bundle savedInstanceState) | |
{ | |
base.OnCreate(savedInstanceState); | |
// Set our view from the "main" layout resource | |
SetContentView(Resource.Layout.Main); | |
if (!String.IsNullOrEmpty(Intent.GetStringExtra(Intent.ExtraText))) | |
{ | |
string url = Intent.GetStringExtra(Intent.ExtraText) ?? "url not available"; | |
Toast.MakeText(this, url, ToastLength.Long).Show(); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment