資源簡介
xamarin ,android的APP自動更新程序,檢測版本,然后下載安裝
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?Android.App;
using?Android.Content;
using?Android.Content.PM;
using?Android.OS;
using?Android.Runtime;
using?Android.Views;
using?Android.Widget;
namespace?App3
{
????[BroadcastReceiver]
????public?class?ApkInstallReceiver?:?BroadcastReceiver
????{
????????long?downloadApkId?=?0;
????????public?override?void?OnReceive(Context?context?Intent?intent)
????????{
????????????//ACTION_DOWNLOAD_COMPLETE
????????????if?(intent.Action.Equals(DownloadManager.ActionDownloadComplete))
????????????{
????????????????installApk(context?downloadApkId);
????????????}
????????????????Toast.MakeText(context?“Received?intent!“?ToastLength.Short).Show();
????????}
????????private?static?void?installApk(Context?context?long?downloadApkId)
????????{
????????????//File?file?=?new?File(fileUri);
????????????//if?(Build.VERSION.SdkInt?>=?Build.VERSION_CODES.N)
????????????//{
????????????//????Uri?apkUri?=?FileProvider.GetUriForFile(context?context.ApplicationContext.PackageName?+?“.provider“?toInstall);
????????????//????Intent?intentS?=?new?Intent(Intent.ActionInstallPackage);
????????????//????intentS.SetData(apkUri);
????????????//????intentS.SetFlags(ActivityFlags.GrantReadUriPermission);
????????????//????context.StartActivity(intentS);
????????????//}
????????????//else
????????????//{
????????????//????Uri?apkUri?=?Uri.FromFile(toInstall);
????????????//????Intent?intentS?=?new?Intent(Intent.ActionView);
????????????//????intentS.SetDataAndType(apkUri?“application/vnd.android.package-archive“);
????????????//????intentS.SetFlags(ActivityFlags.NewTask);
????????????//????context.StartActivity(intentS);
????????????//}
???????????
????????????
????????????DownloadManager?dManager?=?(DownloadManager)context.GetSystemService(Context.DownloadService);
????????????Intent?install?=?new?Intent(Intent.ActionView);
????????????//獲取保存文件的地址
????????????var?downloadFileUri?=?dManager.GetUriForDownloadedFile(downloadApkId);
????????????if?(downloadFileUri?!=?null)
????????????{
????????????????//intent.SetDataAndType(Uri.Parse(“file://“?+?filePath)?“application/vnd.android.package-archive“);
????????????????install.SetDataAndType(downloadFileUri?“application/vnd.android.package-archive“);
????????????????install.AddFlags(ActivityFlags.NewTask);
????????????????context.StartActivity(install);
????????????}??????????
????????}
????????//獲取APK包名、版本號
????????private?static?PackageInfo?getApkInfo(Context?context?String?path)
????????{
????????????//PackageInfo?packageInfo?=?context.getPackageManager().getPackageInfo(localPackage?0);
????????????PackageManager?pm?=?context.PackageManager;
????????????PackageInfo?info?=?pm.GetPackageArchiveInfo(path?PackageInfoFlags.Activities);
????????????
????????????if?(info?!=?null)
????????????{
????????????????string?packageName?=?info.PackageName;
????????????????s
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-03-23?08:56??App3\
?????目錄???????????0??2019-03-23?08:53??App3\.vs\
?????目錄???????????0??2019-03-23?08:53??App3\.vs\App3\
?????目錄???????????0??2019-03-23?08:53??App3\.vs\App3\v15\
?????文件??????150016??2019-03-18?16:50??App3\.vs\App3\v15\.suo
?????目錄???????????0??2019-03-23?08:53??App3\.vs\App3\v15\Server\
?????目錄???????????0??2019-03-23?08:53??App3\.vs\App3\v15\Server\sqlite3\
?????文件???????????0??2018-10-10?10:26??App3\.vs\App3\v15\Server\sqlite3\db.lock
?????文件?????1810432??2018-10-16?12:28??App3\.vs\App3\v15\Server\sqlite3\storage.ide
?????文件???????32768??2019-03-18?16:22??App3\.vs\App3\v15\Server\sqlite3\storage.ide-shm
?????文件?????2323712??2019-03-14?10:44??App3\.vs\App3\v15\Server\sqlite3\storage.ide-wal
?????目錄???????????0??2019-03-23?08:56??App3\App3\
?????文件????????1277??2018-10-10?10:25??App3\App3.sln
?????文件????????4351??2018-10-10?16:27??App3\App3\ApkInstallReceiver.cs
?????文件????????6809??2018-10-11?12:41??App3\App3\App3.csproj
?????文件?????????432??2018-10-10?11:06??App3\App3\App3.csproj.user
?????目錄???????????0??2019-03-23?08:53??App3\App3\Assets\
?????文件?????????641??2018-10-10?10:24??App3\App3\Assets\AboutAssets.txt
?????目錄???????????0??2019-03-23?08:53??App3\App3\bin\
?????目錄???????????0??2019-03-23?08:53??App3\App3\bin\Debug\
?????文件????10653898??2018-10-11?12:51??App3\App3\bin\Debug\App3.App3-Signed.apk
?????文件????10609024??2018-10-11?12:50??App3\App3\bin\Debug\App3.App3.apk
?????文件???????97280??2018-10-11?12:49??App3\App3\bin\Debug\App3.dll
?????文件????????5908??2018-10-11?12:49??App3\App3\bin\Debug\App3.pdb
?????文件???????29784??2018-10-10?10:56??App3\App3\bin\Debug\Mono.Android.Export.pdb
?????文件????10574860??2018-10-10?10:36??App3\App3\bin\Debug\Mono.Android.pdb
?????文件??????151852??2018-10-10?10:36??App3\App3\bin\Debug\Mono.Security.pdb
?????文件?????1429232??2018-10-10?10:36??App3\App3\bin\Debug\mscorlib.pdb
?????文件??????106108??2018-10-10?10:36??App3\App3\bin\Debug\System.ComponentModel.Composition.pdb
?????文件??????386248??2018-10-10?10:36??App3\App3\bin\Debug\System.Core.pdb
?????文件???????43116??2018-10-10?10:36??App3\App3\bin\Debug\System.Net.Http.pdb
............此處省略1611個文件信息
- 上一篇:core java第十版 pdf
- 下一篇:超市進銷存庫存倉庫管理系統 mysql
評論
共有 條評論