zoukankan      html  css  js  c++  java
  • [Xamarin] 取得所有已安裝軟體清單 (转帖)

    最近會用到,簡單記錄一下,抓取所有該手機已經安裝的軟體清單

    結果圖:

    shot_000007


    首先介紹一下Layout :  ResourcesLayoutMain.axml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <Button
            android:id="@+id/btnGetAllList"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="取得所有APPS" />
        <ScrollView
            android:minWidth="25px"
            android:minHeight="25px"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/scrollView1">
            <LinearLayout
                android:orientation="vertical"
                android:minWidth="25px"
                android:minHeight="25px"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/linearLayout1" />
        </ScrollView>
    </LinearLayout>

    預覽:
    2013-09-17_152410

    按下按鈕(btnGetAllList)後 會將所有安裝過的軟體名稱放入至按鈕下方的LinearLayout(linearLayout1)中,因為怕很多所以有用ScrollViewer包起來

    接下來就是 C# Code 部分:

    using Android.App;
    using Android.Content.PM;
    using Android.Graphics;
    using Android.Widget;
    using Android.OS;
     
    namespace GetAllAppList
    {
        [Activity(Label = "取得所有app清單", MainLauncher = true, Icon = "@drawable/icon")]
        public class Activity1 : Activity
        {
     
            protected override void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);
     
                // Set our view from the "main" layout resource
                SetContentView(Resource.Layout.Main);
     
                var btnGetAllList = FindViewById<Button>(Resource.Id.btnGetAllList);
                var appContainer = FindViewById<LinearLayout>(Resource.Id.linearLayout1);
     
     
                //取得所有APPS 按鈕事件
                btnGetAllList.Click += delegate
                    {
     
                        var appLists = PackageManager.GetInstalledPackages(PackageInfoFlags.Activities);
                        Toast.MakeText(this, "發現已安裝數量:" + appLists.Count + "", ToastLength.Long).Show();
     
                        //清空容器
                        appContainer.RemoveAllViews();
     
     
                        foreach (var resolveInfo in appLists)
                        {
                            var t = new TextView(this);
                            //設定顏色 看起來比較geek
                            t.SetTextColor(new Color(0, 255, 0));
                            t.Text = resolveInfo.PackageName;
                            appContainer.AddView(t);
                        }
                    };
            }
        }
    }
     

    重點在這一行:

    var appLists = PackageManager.GetInstalledPackages(PackageInfoFlags.Activities);

    結果預覽:
    shot_000006

    shot_000007

  • 相关阅读:
    Oracle 控制文件
    rm 删除文件
    FreeBSD 8.0候选版本RC3发布
    【非长篇大论】X3D Web3D标准的发展
    【短】又碰到CSDN服务器负载过重
    年终总结 等待
    项目管理软件InDefero
    X3D 与 HTML5
    对使用破解软件的一点想法
    Flash开发的基本概念
  • 原文地址:https://www.cnblogs.com/whatthehell/p/3444931.html
Copyright © 2011-2022 走看看