安卓开发怎么获取第三方apk的包名

安卓开发怎么获取第三方apk的包名,第1张

应用场景:1、在界面中显示应用程序版本号;2、用户启动该应用,后台判断该应用是否是最新版本。上述情景都需要在程序中自动获取到应用的版本号。思路简介:在Android中,应用程序的版本号是在AndroidManifestxml文件中进行配置的

桌面的名字是第一个activity的android:label。

进程的名字是application的android:label。

getApplicationLabel获取的是application的android:label。

希望能帮到你。

安卓的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下载。

在framework中想添加这个功能,所以写了个appliction来实现一下获取正在运行的应用程序: 还是先看图吧: 这个app主要是简单的实现了获取非系统的应用程序和一些常用的系统应用程序,显示在一个listview中,并添加了点击(回复到你打开的界面)和长按事件(关闭应用程序)。 看看代码吧: 直接贴出来再加上注释吧(直接写在一个文件里): package andorid/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_width="40dip" android:layout_height="40dip" />  <LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" >  <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textStyle="bold" />  <TextView android:id="@+id/info" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout> main: <xml version="1/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:id="@+id/list_view" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" ></ListView> </LinearLayout> 在manifest文件中要加以个权限: <uses-permission android:name="androidpermissionRESTART_PACKAGES" /> 主要是前面的amkillBackgroundProcesses(packageName);方法要这个权限。

可以通过电脑端aaptexe这个程序获取相关信息

命令如下:

aapt dump badging fileapk

附上信息获取脚本工具(电脑上用的哦),把压缩包内的文件解压到APK文件目录下,然后双击运行“获取包名bat”

获取到的包名将会保存到“APK包名信息txt”文本中

找APK文件分为数据文件和缓存文件,数据文件一般存在根目录里、需要有root权限才能查看,缓存文件又分两种缓冲文件、存储文件,存储文件一般在Android/data里、文件名就是全称软件包名,而缓冲文件在主目录上文件名就是软件包名。用X-plore软件可以看。

以上就是关于安卓开发怎么获取第三方apk的包名全部的内容,包括:安卓开发怎么获取第三方apk的包名、如何获取《未》安装的apk包的应用名称、C#中,上传apk时,怎样获取apk的基本信息等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

原文地址:https://54852.com/web/9798346.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存