android实用代码块
来源:互联网 发布:朴素贝叶斯算法python 编辑:程序博客网 时间:2024/06/11 17:25
一、获取系统版本号:
PackageInfo info = this.getPackageManager().getPackageInfo(this.getPackageName(), 0);
int versionCode=info.versionCode
string versionName=info.versionNam
二、获取系统信息:
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版本
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;
}
- android实用代码块
- android超实用代码块
- Shell 实用代码块
- 实用代码块
- Android开发最实用的功能代码块总结
- 块代码实用入门指南
- 数组实用代码块简记
- 实用代码块记录1
- 实用代码块记录2
- 实用代码块记录3
- 实用代码块记录4
- 实用代码块记录5
- 实用代码块记录6
- 实用代码块记录7
- 实用代码块记录8
- 实用代码块记录9
- 实用代码块记录10
- Android 常用代码块
- android 游戏引擎简介
- 在.net中读写config文件的各种方法
- 向蓝牙设备发送命令
- 暴雪高效哈希算法
- CListCtrl控件
- android实用代码块
- POJ 1562 Oil Deposits (简单深搜)
- 谷歌Gmail诞生记:十年回首
- 细说 ASP.NET Cache 及其高级用法
- 关于int *a; int &a; int & *a; int * &a
- [LeetCode]Linked List Cycle
- 取出对象中的字符串
- 类加载器---类加载器简介
- 堆排序