zoukankan      html  css  js  c++  java
  • 安卓代码块

    一,获取系统版本号:

    PackageInfo info = this.getPackageManager().getPackageInfo(this.getPackageName(), 0);

    int versionCode=nfo.versionCode

    string versionName=info.versionNam

    其实我们用的更多的是编译的版本号Build.VERSION.SDK_INT,范围从0到目前的24,也就是应用在哪个环境下运行,用法如下:

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){

    //就做自己的操作

    }

    二、获取系统信息:

    String archiveFilePath="sdcard/download/Law.apk";//安装包路径

    PackageManager pm = getPackageManager();

    PackageInfo info = pm.getPackageArchiveInfo(archiveFilePath, PackageManager.GET_ACTIVITIES);

    if(info != null){

    ApplicationInfo appInfo = info.applicationInfo;

    String appName = pm.getApplicationLabel(appInfo).toString();

    String packageName = appInfo.packageName; //得到安装包名称

    String version=info.versionName; //得到版本信息

    Toast.makeText(test4.this, "packageName:"+packageName+";version:"+version, Toast.LENGTH_LONG).show();

    Drawable icon = pm.getApplicationIcon(appInfo);//得到图标信息

    TextView tv = (TextView)findViewById(R.id.tv); //显示图标

    tv.setBackgroundDrawable(icon);

    三、获取安装路径和已安装程序列表

    (1)android中获取当前程序路径

    getApplicationContext().getFilesDir().getAbsolutePath()

    (2)android取已安装的程序列表

    List<PackageInfo> packageInfoList = getPackageManager().getInstalledPackages(0);

    四、获取图片、应用名、包名

    PackageManager pManager = MessageSendActivity.this.getPackageManager();

    List<PackageInfo> appList = Utils.getAllApps(MessageSendActivity.this);

    for(int i=0;i<appList.size();i++) {

    PackageInfo pinfo = appList.get(i);

    ShareItemInfo shareItem = new ShareItemInfo();

    //set Icon

    shareItem.setIcon(pManager.getApplicationIcon(pinfo.applicationInfo));

    五、解决listview上 Item上有按钮时 item本身不能点击的问题:

    1. 在item试图上面添加代码: android:descendantFocusability="blocksDescendants"

    2.在listview里 添加代码 android:focusable="true"

    六、不让文本框输入中文:

    android:digits="1234567890qwertyuiopasdfghjklzxcvbnm`-=[];,./~!@#$%^*()_+}{:?&<>"'" 这样就不会输入中文了。

    七,获取屏幕宽高

    DisplayMetrics displayMetrics = new DisplayMetrics();

    this.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

    int height = displayMetrics.heightPixels;

    int width = displayMetrics.widthPixels;

    八, 获取设备型号、SDK版本及系统版本

    String device_model = Build.MODEL; // 设备型号

    String version_sdk = Build.VERSION.SDK; // 设备SDK版本

    int version_int = Build.VERSION.SDK_INT //获取设备版本号

    String version_release = Build.VERSION.RELEASE; // 设备的系统版本

    九,获取应用程序下所有Activity

    public static ArrayList<String> getActivities(Context ctx) {

    ArrayList<String> result = new ArrayList<String>();

    Intent intent = new Intent(Intent.ACTION_MAIN, null);

    intent.setPackage(ctx.getPackageName());

    for (ResolveInfo info : ctx.getPackageManager().queryIntentActivities(intent, 0)) {

    result.add(info.activityInfo.name);

    }

    return result;

    }

    感谢分享  

    原文  http://www.toutiao.com/i6342990300763390465/

  • 相关阅读:
    利用 localStorage 储存css js
    实现图片延迟加载的一些 库
    less 应用
    vue 问题集合||
    一个简易的登录框
    python_协程方式操作数据库
    爬取知名社区技术文章_分析_1
    python_爬百度百科词条
    python_爬校花图片
    python_猜年龄
  • 原文地址:https://www.cnblogs.com/isItOk/p/6025644.html
Copyright © 2011-2022 走看看