diff options
author | Jan Tattermusch <jtattermusch@google.com> | 2018-07-25 17:30:19 +0200 |
---|---|---|
committer | Jan Tattermusch <jtattermusch@google.com> | 2018-07-31 12:42:47 +0200 |
commit | 705843c041f24ce5b2737fc15dfd45c34f26cf82 (patch) | |
tree | f872c44545aeb3b0ebb0eff1cd2708304281bb24 /examples | |
parent | b335d58cb726d930a77e7756054e7b6c754d54c3 (diff) |
experimental helloworld client for android
Diffstat (limited to 'examples')
-rw-r--r-- | examples/csharp/HelloworldXamarin/Droid/MainActivity.cs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/examples/csharp/HelloworldXamarin/Droid/MainActivity.cs b/examples/csharp/HelloworldXamarin/Droid/MainActivity.cs index 20982422f2..2c158e9d7c 100644 --- a/examples/csharp/HelloworldXamarin/Droid/MainActivity.cs +++ b/examples/csharp/HelloworldXamarin/Droid/MainActivity.cs @@ -1,13 +1,15 @@ using Android.App; using Android.Widget; using Android.OS; +using Grpc.Core; +using Helloworld; namespace HelloworldXamarin.Droid { [Activity(Label = "HelloworldXamarin", MainLauncher = true, Icon = "@mipmap/icon")] public class MainActivity : Activity { - int count = 1; + //int count = 1; protected override void OnCreate(Bundle savedInstanceState) { @@ -20,8 +22,26 @@ namespace HelloworldXamarin.Droid // and attach an event to it Button button = FindViewById<Button>(Resource.Id.myButton); - button.Click += delegate { button.Text = $"{count++} clicks!"; }; + button.Click += delegate { SayHello(button); }; } + + private void SayHello(Button button) + { + + // use loopback on host machine: https://developer.android.com/studio/run/emulator-networking + Channel channel = new Channel("10.0.2.2:50051", ChannelCredentials.Insecure); + + var client = new Greeter.GreeterClient(channel); + string user = "Xamarin"; + + var reply = client.SayHello(new HelloRequest { Name = user }); + + button.Text = "Greeting: " + reply.Message; + + channel.ShutdownAsync().Wait(); + } } + + } |