| | |
| | | using Microsoft.AppCenter; |
| | | using Microsoft.AppCenter.Analytics; |
| | | using Microsoft.AppCenter.Crashes; |
| | | using Com.Tencent.MM.Sdk.Openapi; |
| | | |
| | | namespace com.hdl.home |
| | | { |
| | | /// <summary>
/// 设定为默认启动的Application
/// </summary>
[Android.App.Application]
public class Application : Android.App.Application
{
public Application(IntPtr handle, Android.Runtime.JniHandleOwnership ownerShip) : base(handle, ownerShip) { }
public override void OnCreate()
{
//安卓配网初始
//var result = Com.Mediatek.Elian.ElianNative.LoadLib();
//if (!result)
//{
// System.Console.WriteLine("Error,can't load elianjni lib");
//} |
| | | |
| | | initAll();
base.OnCreate();
} |
| | | [Activity(Name = "com.hdl.home.wxapi.WXEntryActivity", Exported = true, Theme = "@android:style/Theme.Translucent", LaunchMode = Android.Content.PM.LaunchMode.SingleTask)] |
| | | class WXEntryActivity : Android.App.Activity, IWXAPIEventHandler |
| | | { |
| | | public void OnReq(BaseReq p0) |
| | | { |
| | | |
| | | } |
| | | protected override void OnNewIntent(Intent intent) |
| | | { |
| | | base.OnNewIntent(intent); |
| | | Intent = intent; |
| | | com.hdl.home.Application.api.HandleIntent(intent, this); |
| | | //Finish(); |
| | | } |
| | | public static Action<string> RespAction; |
| | | public void OnResp(BaseResp p0) |
| | | { |
| | | |
| | | if (p0 is SendAuth.Resp) |
| | | { |
| | | var resp = p0 as SendAuth.Resp; |
| | | |
| | | switch (resp.ErrCode) |
| | | { |
| | | case SendAuth.Resp.InnerErrCode.ErrOk: |
| | | var result = new System.Net.WebClient { }.DownloadString($"https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx2ec8f53f6fa36e82&secret=a08585cd6ff2ce64570b9e7e6525dd8e&code={resp.Token}&grant_type=authorization_code"); |
| | | RespAction?.Invoke(result); |
| | | break; |
| | | default: |
| | | RespAction?.Invoke(null); |
| | | break; |
| | | |
| | | //case SendAuth.Resp.InnerErrCode.ErrUserCancel: |
| | | // break; |
| | | //case SendAuth.Resp.InnerErrCode.ErrAuthDenied: |
| | | // break; |
| | | |
| | | } |
| | | } |
| | | |
| | | this.Finish(); |
| | | } |
| | | //IWXAPI api; |
| | | protected override void OnCreate(Bundle savedInstanceState) |
| | | { |
| | | base.OnCreate(savedInstanceState); |
| | | // 通过WXAPIFactory工厂,获取IWXAPI的实例 |
| | | //api = WXAPIFactory.CreateWXAPI(this, "wx2ec8f53f6fa36e82", false); |
| | | |
| | | // 将应用的appId注册到微信 |
| | | //api.RegisterApp("wx2ec8f53f6fa36e82"); |
| | | |
| | | com.hdl.home.Application.api.HandleIntent(Intent, this); |
| | | } |
| | | } |
| | | /// <summary>
/// 设定为默认启动的Application
/// </summary>
[Android.App.Application]
public class Application : Android.App.Application
{
public Application(IntPtr handle, Android.Runtime.JniHandleOwnership ownerShip) : base(handle, ownerShip) { }
public override void OnCreate()
{ |
| | | //安卓配网初始 |
| | | //var result = Com.Mediatek.Elian.ElianNative.LoadLib(); |
| | | //if (!result) |
| | | //{ |
| | | // System.Console.WriteLine("Error,can't load elianjni lib"); |
| | | //} |
| | | initAll();
base.OnCreate(); |
| | | // 通过WXAPIFactory工厂,获取IWXAPI的实例 |
| | | api = WXAPIFactory.CreateWXAPI(this, "wx2ec8f53f6fa36e82", true); |
| | | |
| | | // 将应用的appId注册到微信 |
| | | api.RegisterApp("wx2ec8f53f6fa36e82"); |
| | | } |
| | | |
| | | internal static IWXAPI api; |
| | | |
| | | public static void WXLogin() { |
| | | var req = new SendAuth.Req { Scope = "snsapi_userinfo", State = "ZigbeeApp" }; |
| | | api.SendReq(req); |
| | | } |
| | | /// <summary>
/// 所有初始化全部在这个方法实现
/// </summary>
void initAll()
{
BaseActivity.IsEnnableGPS = false; |
| | | //设置极光调试模式,为false时只打印警告信息 |
| | | // System.Console.WriteLine($"AAA : {System.DateTime.Now.ToString()}"); |
| | |
| | | AppCenter.Start("4802834a-e7e9-4dd8-93f1-c2f88f0bd464", typeof(Analytics), typeof(Crashes));
#if Release
//保存获取的极光服务器上的注册ID到本地文件
var registrationId = JPushInterface.GetRegistrationID(activity); |
| | | System.Console.WriteLine("registrationId-极光id=" + registrationId); |
| | | if (!string.IsNullOrEmpty(registrationId))
{
Shared.Common.Config.Instance.RegistrationID = registrationId;
Shared.Common.Config.Instance.Save();
}
#endif
};
BaseActivity.RefreshUIAction += (activity) => {
Shared.Language.CurrentLanguage = "Chinese";
Shared.Common.CommonPage.Instance.Show();
};
BaseActivity.OnResumeAction += (activity) => {
};
BaseActivity.NetworkStateChanged += (v) =>
{
//网络状态变化处理事件 |
| | | Shared.Common.CommonPage.nowNetworkMode = v;
};
BaseActivity.OnDestroyAction += (activity) => {
//socket停止连接
//ZigBee.Device.ZbGateway.FindGateWaySocket.Stop();
};
}
public static bool IsShowTip = true;
JpushNotificationReceiver myReceiver = new JpushNotificationReceiver { };
/// <summary>
/// 项目启动时网络查询
/// </summary>
void checkSomeInfo()
{
var status = isNetworkAvailable(this);
string internetStatus = "Available";
if (!status)
{
internetStatus = "UnaVailable";
}
else
{
var isWifi = isWifiConnected(this);
if (isWifi)
{
internetStatus = "WiFiConnect";
}
else
{
internetStatus = "MobileConnect";
}
}
int connectState = 0;
if (internetStatus == "UnaVailable")
{
connectState = 0;
}
else if (internetStatus == "WiFiConnect")
{
connectState = 2;
}
else
{
connectState = 1;
}
//ZigBee.Device.ZbGateway.CheckConnection(connectState);
}
/// <summary>
/// 网络是否可用
/// </summary>
/// <returns><c>true</c>, if network available was ised, <c>false</c> otherwise.</returns>
/// <param name="context">Context.</param>
bool isNetworkAvailable(Context context)
{
var cm = (ConnectivityManager)context.GetSystemService(ConnectivityService);
if (cm == null || cm.ActiveNetworkInfo == null)
{
//当前网络不可用
return false;
}
else
{
return cm.ActiveNetworkInfo.IsAvailable;
}
}
/// <summary>
/// 网络是否连接
/// </summary>
/// <returns><c>true</c>, if wifi connected was ised, <c>false</c> otherwise.</returns>
/// <param name="context">Context.</param>
bool isWifiConnected(Context context)
{
if (context != null)
{
var cm = (ConnectivityManager)context.GetSystemService(ConnectivityService);
var mWiFiNetworkInfo = cm.GetNetworkInfo(ConnectivityType.Wifi);
if (Android.Net.NetworkInfo.State.Connected == mWiFiNetworkInfo.GetState())
{
//当前网络是Wi-Fi连接
return true;
}
var moWiFiNetworkInfo = cm.GetNetworkInfo(ConnectivityType.Mobile);
if (Android.Net.NetworkInfo.State.Connected == moWiFiNetworkInfo.GetState())
{
//当前网络是Mobile连接
return false;
}
}
return false;
} |
| | | Shared.Common.CommonPage.nowNetworkMode = v;
};
BaseActivity.OnDestroyAction += (activity) => {
//socket停止连接
//ZigBee.Device.ZbGateway.FindGateWaySocket.Stop();
};
HDLUtils.SetAuthoritiesName("com.hdl.home.fileProvider");
}
public static bool IsShowTip = true;
JpushNotificationReceiver myReceiver = new JpushNotificationReceiver { };
/// <summary>
/// 项目启动时网络查询
/// </summary>
void checkSomeInfo()
{
var status = isNetworkAvailable(this);
string internetStatus = "Available";
if (!status)
{
internetStatus = "UnaVailable";
}
else
{
var isWifi = isWifiConnected(this);
if (isWifi)
{
internetStatus = "WiFiConnect";
}
else
{
internetStatus = "MobileConnect";
}
}
int connectState = 0;
if (internetStatus == "UnaVailable")
{
connectState = 0;
}
else if (internetStatus == "WiFiConnect")
{
connectState = 2;
}
else
{
connectState = 1;
}
//ZigBee.Device.ZbGateway.CheckConnection(connectState);
}
/// <summary>
/// 网络是否可用
/// </summary>
/// <returns><c>true</c>, if network available was ised, <c>false</c> otherwise.</returns>
/// <param name="context">Context.</param>
bool isNetworkAvailable(Context context)
{
var cm = (ConnectivityManager)context.GetSystemService(ConnectivityService);
if (cm == null || cm.ActiveNetworkInfo == null)
{
//当前网络不可用
return false;
}
else
{
return cm.ActiveNetworkInfo.IsAvailable;
}
}
/// <summary>
/// 网络是否连接
/// </summary>
/// <returns><c>true</c>, if wifi connected was ised, <c>false</c> otherwise.</returns>
/// <param name="context">Context.</param>
bool isWifiConnected(Context context)
{
if (context != null)
{
var cm = (ConnectivityManager)context.GetSystemService(ConnectivityService);
var mWiFiNetworkInfo = cm.GetNetworkInfo(ConnectivityType.Wifi);
if (Android.Net.NetworkInfo.State.Connected == mWiFiNetworkInfo.GetState())
{
//当前网络是Wi-Fi连接
return true;
}
var moWiFiNetworkInfo = cm.GetNetworkInfo(ConnectivityType.Mobile);
if (Android.Net.NetworkInfo.State.Connected == moWiFiNetworkInfo.GetState())
{
//当前网络是Mobile连接
return false;
}
}
return false;
} |
| | | } |
| | | |
| | | public class JpushNotificationReceiver : BroadcastReceiver |