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

  • 相关阅读:
    Java1.0-1.11各个版本的新特性
    Java在ServletContextListener、过滤器、拦截器解决对象无法注入问题
    实验七 Web应用测试
    第四次作业
    实验5
    实验4
    实验3
    把一个英语句子中的单词次序颠倒后输出。例如输入“how are you”,输出“you are how”;
    1. java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()Ljava/lang/Integer;报错问题
    在eclipse中新建maven项目 js,css路径失效问题
  • 原文地址:https://www.cnblogs.com/whatthehell/p/3444931.html
Copyright © 2011-2022 走看看