JLChen
2020-09-08 45d7c5536bd9b4516feb1401753e61717d7dd888
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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 System.Threading;
using Java.Lang;
//using JiaHang.OA.SHCGAPP.Class;
 
namespace com.hdl.on
{
    [Activity(Label = "ÏÂÔØ")]
    public class AppUpgradeActivity : Activity
    {
        private static int _Progress = 0;
        private static TextView _Text = null;
        private static ProgressBar _ProgressBar = null;
 
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.AppUpgrate);
 
            //ImageView icon = FindViewById<ImageView>(Resource.Id.app_upgrate_icon);
            //icon.SetImageResource(Resource.Drawable.Apps);
            if (_Text == null)
                _Text = FindViewById<TextView>(Resource.Id.app_upgrate_text);
            if (_ProgressBar == null)
                _ProgressBar = FindViewById<ProgressBar>(Resource.Id.app_upgrate_progressbar);
 
            //Ò첽ˢнø¶ÈÌõµÄÏÔʾÐÅÏ¢
            new MyAsync().Execute(this);
 
            //Common.InstallNewApk(this); 
 
        }
 
        private class MyAsync : AsyncTask
        {
            private Activity _Activity = null;
            protected override Java.Lang.Object DoInBackground(params Java.Lang.Object[] @params)
            {
                _Activity = (Activity)@params[0];
                while (_Progress != 100)
                {
                    _Progress = AppUpgradeService._CurrentProgress;
                    System.Threading.Thread.Sleep(500); //ÐÝÃß0.5Ãë ·ÀÖ¹ÄÚ´æ³Ô½ô
                    PublishProgress(_Progress);
                }
                return null;
            }
 
            protected override void OnProgressUpdate(params Java.Lang.Object[] values)
            {
                //base.OnProgressUpdate(values);
                _Text.Text = "ÕýÔÚÏÂÔØ¸üУ¬µ±Ç°½ø¶ÈΪ£º" + _Progress + "%";
                _ProgressBar.Progress = _Progress;
            }
 
            protected override void OnPostExecute(Java.Lang.Object result)
            {
                _Text.Text = "ÏÂÔØÍê±Ï£¬µã»÷°²×°£¡";
                _ProgressBar.Click += (sender, e) =>
                {
                    //Common.InstallNewApk(_Activity);
                    Intent ite = new Intent (Intent.ActionView);
                    string RootPath = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal) + "/";
                    string filePath = RootPath + "UpdateApk.apk";
                    var uriPath = Android.Net.Uri.Parse (@"file://" + filePath);
                    ite.SetDataAndType (uriPath, @"application/vnd.android.package-archive");
                    ite.SetFlags (ActivityFlags.NewTask);//Õâ¾äºÜ¹Ø¼ü£¬Ã»ÓÐÕâ¾ä°²×°Íê³Éºó²»»áµ¯³ö¡°Íê³É¡±ºÍ¡°´ò¿ª¡±µÄ¶Ô»°¿ò£»
                    _Activity.StartActivity (ite);
                };
            }
 
        }
    }
}