C#中,上传apk时,怎样获取apk的基本信息

C#中,上传apk时,怎样获取apk的基本信息,第1张

安卓的APK么?

安卓的APK是个压缩包格式,我给你个思路 具体代码你去写 还是比较简单的

分为两步:

上传按钮点击时解压APK压缩包

②获取压缩包内AndroidManifestxml(apk的包名,版本号,版本名称都在此XML文件内)

③解析这个XML

既然答了 我就完善一下:(在codeplex上面找到的)

 

using AndroidXml;

using IonicZip;

using System;

using SystemCollectionsGeneric;

using SystemIO;

using SystemLinq;

using SystemText;

using SystemThreadingTasks;

using SystemXml;

namespace APKRead

{

    class NamespaceInfo

    {

        public string Prefix { get; set; }

        public string Uri { get; set; }

    }

    class Program

    {

        static List<AndroidInfo> androidInfos = new List<AndroidInfo>();

        static void Main(string[] args)

        {

            //要分析的文件名称

            var manifest = "AndroidManifestxml";

            //读取apk,通过解压的方式读取

            using (var zip = ZipFileRead("Newsapk"))

            {

                using (Stream zipstream = zip[manifest]OpenReader())

                {

                    //将解压出来的文件保存到一个路径(必须这样)

                    using (var fileStream = FileCreate(manifest, (int)zipstreamLength))

                    {

                        // Initialize the bytes array with the stream length and then fill it with data

                        byte[] bytesInStream = new byte[zipstreamLength];

                        zipstreamRead(bytesInStream, 0, bytesInStreamLength);

                        // Use write method to write to the file specified above

                        fileStreamWrite(bytesInStream, 0, bytesInStreamLength);

                    }

                }

            }

            //读取解压文件的字节数

            byte[] data = FileReadAllBytes(manifest);

            if (dataLength == 0)

            {

                throw new IOException("Empty file");

            }

            #region 读取文件内容

            using (var stream = new MemoryStream(data))

            {

                var reader = new AndroidXmlReader(stream);

                while (readerRead())

                {

                    switch (readerNodeType)

                    {

                        case XmlNodeTypeElement:

                            {

                                AndroidInfo info = new AndroidInfo();

                                androidInfosAdd(info);

                                infoName = readerName;

                                infoSettings = new List<AndroidSetting>();

                                for (int i = 0; i < readerAttributeCount; i++)

                                {

                                    readerMoveToAttribute(i);

                                    AndroidSetting setting = new AndroidSetting() { Name = readerName, Value = readerValue };

                                    infoSettingsAdd(setting);

                                }

                                readerMoveToElement();

                                break;

                            }

                    }

                }

            }

            #endregion

            FileDelete(manifest);

            StringBuilder builder = new StringBuilder();

            foreach (var androidInfo in androidInfos)

            {

                builderAppend(stringFormat("{0}:",androidInfoName));

                foreach (var setting in androidInfoSettings)

                {

                    builderAppend("{");

                    builderAppend(stringFormat("'{0}':'{1}'",settingName,settingValue));

                    builderAppend("},");

                }

                builderAppend("\n\n");

            }

            ConsoleWriteLine(builderToString());

        }

    }

    /// <summary>

    /// android应用程序信息

    /// </summary>

    public class AndroidInfo

    {

        public string Name { get; set; }

        public List<AndroidSetting> Settings { get; set; }

    }

    /// <summary>

    /// 设置

    /// </summary>

    public class AndroidSetting

    {

        public string Name { get; set; }

        public string Value { get; set; }

    }

}

      

//引用的IonicZip库可以直接通过 nuget下载。

用intentfilter获取安装的apk 包名,在BroadcastReceiver里面就可以拿到安装的包名和APP,等基本信息,再利用packageManager的功能就可能放到listView里面

以上就是关于C#中,上传apk时,怎样获取apk的基本信息全部的内容,包括:C#中,上传apk时,怎样获取apk的基本信息、如何在Android7.0系统下通过Intent安装apk、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/9484975.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-28
下一篇 2023-04-28

发表评论

登录后才能评论

评论列表(0条)

保存