LoginSignup
7
10

More than 5 years have passed since last update.

DeployGate を Xamarin.Android で使う

Last updated at Posted at 2013-03-18

mixi社が開発する DeployGate を Xamarin.Android で利用する方法を解説します。

予めDeployGateSDKをダウンロードしてzipを展開しておいてください。
https://deploygate.com/docs/sdk


■ソリューションの作成

今回は「DeployGateTest」としました。
プロジェクトを「Android Application」として作成します。
同時にプロジェクト「DeployGateTest」も作成します(自動で作成されます)。

作成したソリューションにDeployGateSDKをラップするプロジェクトを追加します。
「DeployGate」という名前で「Android Java Bindings Library」として作成します。

DeployGate に DeployGateSDK の deploygatesdk.jar を Jars に追加します。

[プロジェクトオプション]-[ビルド]-[Android Build]
[Fast deployment(deubg mode only] をオフに設定する。

DeployGateTest に DeployGate を参照させます。

Xamarin.Android でオレオレ Application クラスを使う
を参考にApplicationクラスを追加します。

OnCreate内の
DeployGate.Install(this);
でDeployGateの初期化を行います。

App.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

using Com.Deploygate.Sdk;

namespace DeployGateTest
{
    [Application]
    class App : Application
    {
        public App(IntPtr javaReference, JniHandleOwnership transfer)
            : base(javaReference, transfer)
        {
        }

        public override void OnCreate()
        {
            base.OnCreate();

            DeployGate.Install(this);
        }
    }
}

■確認

ビルドして、出来上がったapkファイルをDeployGateのサイトにアップロード。そして端末にインストール。
反応しているのが確認できると思います。すごい!

メッセージ文字列を送ってみます。
MainActivity.cs を以下のように編集して、ビルド&サイトに転送&実行。

MainActivity.cs
using System;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

using Com.Deploygate.Sdk;

namespace DeployGateTest
{
    [Activity (Label = "DeployGateTest", MainLauncher = true)]
    public class Activity1 : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            var button = FindViewById<Button>(Resource.Id.myButton);

            button.Click += (s, e) => DeployGate.LogDebug("log message from DeployGateTest");    
        }
    }
}

Android上のボタンをタップすると、メッセージを転送してサイトがリアルタイムに受信しているのが確認できると思います。すごい!すごい!

■まとめ

この方法を使えば、Xamarin.Android から jarも問題なく動作させることができます。
DeployGateも問題ないですね。
DeployGateすごい。
Xamarin.Androidもすごい。

■参照

Binding a Java Library (.jar) http://docs.xamarin.com/guides/android/advanced_topics/java_integration_overview/binding_a_java_library_(.jar)

7
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
10