using System;
|
using Android.Content;
|
using Android.OS;
|
using Shared;
|
|
namespace SharedMethod
|
{
|
public static class SharedMethod
|
{
|
public static bool IsBackground;
|
//public static UIApplication sharedApp;
|
public static void ChangeSkin ()
|
{
|
//if (UserConfig.Instance.SkinCode == 0) {
|
// sharedApp.StatusBarStyle = UIStatusBarStyle.LightContent;
|
// Shared.Application.Skin = UserConfig.Instance.CurrentSkinName;
|
//} else if (UserConfig.Instance.SkinCode == 1) {
|
// sharedApp.StatusBarStyle = UIStatusBarStyle.Default;
|
// Shared.Application.Skin = UserConfig.Instance.CurrentSkinName;
|
//}
|
}
|
|
|
|
/// <summary>
|
/// c#,.net 下载文件
|
/// </summary>
|
public static void DownloadFile (Action<string> action)
|
{
|
float percent = 0;
|
try {
|
#if wallon
|
System.Net.HttpWebRequest Myrq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create ("http://intercom.hdlcontrol.com/AppDownload/apk/teston.apk");
|
#else
|
System.Net.HttpWebRequest Myrq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create ("http://intercom.hdlcontrol.com/AppDownload/apk/hdlon.apk");
|
#endif
|
System.Net.HttpWebResponse myrp = (System.Net.HttpWebResponse)Myrq.GetResponse ();
|
long totalBytes = myrp.ContentLength;
|
|
System.IO.Stream st = myrp.GetResponseStream ();
|
System.IO.Stream so = new System.IO.FileStream (new Java.IO.File (Android.OS.Environment.GetExternalStoragePublicDirectory (Android.OS.Environment.DirectoryDownloads), "on.apk").Path, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite);
|
long totalDownloadedByte = 0;
|
byte [] by = new byte [1024];
|
int osize = st.Read (by, 0, (int)by.Length);
|
while (osize > 0) {
|
totalDownloadedByte = osize + totalDownloadedByte;
|
so.Write (by, 0, osize);
|
|
osize = st.Read (by, 0, (int)by.Length);
|
|
percent = (float)totalDownloadedByte / (float)totalBytes * 100;
|
System.Console.WriteLine (percent);
|
action (((int)percent).ToString ());
|
}
|
so.Close ();
|
st.Close ();
|
|
install (Shared.Application.Activity);
|
} catch (System.Exception ex) {
|
System.Console.WriteLine (ex.Message);
|
}
|
}
|
|
static void install (Context context)
|
{
|
var file = new Java.IO.File (Android.OS.Environment.GetExternalStoragePublicDirectory (Android.OS.Environment.DirectoryDownloads), "on.apk");
|
|
var intent = new Intent (Intent.ActionView);
|
// 由于没有在Activity环境下启动Activity,设置下面的标签
|
intent.SetFlags (ActivityFlags.NewTask);
|
|
if (BuildVersionCodes.M < Android.OS.Build.VERSION.SdkInt) {
|
//参数1 上下文, 参数2 Provider主机地址 和配置文件中保持一致 参数3 共享的文件
|
var apkUri = Android.Support.V4.Content.FileProvider.GetUriForFile (context, "com.hdl.in.fileProvider", file);
|
//添加这一句表示对目标应用临时授权该Uri所代表的文件
|
intent.AddFlags (ActivityFlags.GrantReadUriPermission);
|
intent.SetDataAndType (apkUri, "application/vnd.android.package-archive");
|
} else {
|
intent.SetDataAndType (Android.Net.Uri.FromFile (file), "application/vnd.android.package-archive");
|
}
|
context.StartActivity (intent);
|
}
|
|
public static PageLayout CurPageLayout = null;
|
}
|
}
|