Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android 獲取手機所有應用包名以及權限

Android 獲取手機所有應用包名以及權限

編輯:關於Android編程

package gongzibai.co.cc;

import java.util.List;

import android.app.Activity;
import android.app.Application;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PermissionInfo;
import android.os.Bundle;
import android.widget.TextView;

public class Package1Activity extends
  Activity {
 TextView mTextView;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(
   Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  mTextView = (TextView) findViewById(R.id.textView1);
  PackageManager packageManager = getPackageManager();

  List<PackageInfo> list = packageManager
    .getInstalledPackages(PackageManager.GET_PERMISSIONS);
  StringBuilder stringBuilder = new StringBuilder();

  for (PackageInfo packageInfo : list) {

   stringBuilder
     .append("package name:"
       + packageInfo.packageName
       + "\n");
   ApplicationInfo applicationInfo = packageInfo.applicationInfo;
   stringBuilder
     .append("應用名稱:"
       + applicationInfo
         .loadLabel(packageManager)
       + "\n");

   if (packageInfo.permissions != null) {

    for (PermissionInfo p : packageInfo.permissions) {

     stringBuilder   www.2cto.com
       .append("權限包括:"
         + p.name
         + "\n");
    }

   }
   stringBuilder.append("\n");
  }

  mTextView.setText(stringBuilder
    .toString());

 }
}

 

作者:gongzibai
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved