android开发软件工具类,获取软件的各种属性
来源:互联网 发布:真心和知真的意思 编辑:程序博客网 时间:2024/06/04 18:11
package com.jmheart.tools;import java.io.File;import com.jmheart.R;import android.app.Activity;import android.app.ActivityManager;import android.app.ActivityManager.RunningTaskInfo;import android.content.ComponentName;import android.content.Context;import android.content.Intent;import android.content.Intent.ShortcutIconResource;import android.content.pm.PackageInfo;import android.content.pm.PackageManager;import android.content.pm.PackageManager.NameNotFoundException;import android.net.Uri;/** * 软件工具类,获取软件的各种属性 * @author liujie */public class AppUtils {private Context context;public AppUtils(Context context) {this.context = context;}/** * 获取当前应用程序的版本号 * @return */public String getVersionName() {try {PackageManager packageManager = context.getPackageManager();PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);String version = packInfo.versionName;return version;} catch (NameNotFoundException e) {e.printStackTrace();}return null;}/** * 获取当前正在运行的Activity * @return * <uses-permission android:name="android.permission.GET_TASKS"/> */public String getActivityName() {ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);RunningTaskInfo info = manager.getRunningTasks(1).get(0);String shortClassName = info.topActivity.getShortClassName();System.out.println("shortClassName=" + shortClassName);return shortClassName;}/** * 安装指定文件路径的apk文件 * @param path */public void installApk(String path) {Intent intent = new Intent(Intent.ACTION_VIEW);intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);intent.setDataAndType(Uri.fromFile(new File(path)),"application/vnd.android.package-archive");context.startActivity(intent); // 安装新版本}/** * 安装指定文件路径的apk文件 * @param path */public void installApk(File path) {Intent intent = new Intent(Intent.ACTION_VIEW);intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);intent.setDataAndType(Uri.fromFile(path),"application/vnd.android.package-archive");context.startActivity(intent); // 安装新版本}/** * 创建桌面快捷方式 * @param resId 应用图标 * <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> */public void createShortcut(int resId) {Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,context.getString(R.string.app_name));shortcut.putExtra("duplicate", false);ComponentName comp = new ComponentName(context.getPackageName(), "."+ ((Activity) context).getLocalClassName());shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(context, resId);shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);context.sendBroadcast(shortcut);}}
0 0
- android开发软件工具类,获取软件的各种属性
- android各种属性获取
- Android工具类,获取各种参数
- Android获取本机常用属性的工具类
- 一个获取各种时间的工具类
- 获取各种随机数的代码工具类
- 获取Assets的各种属性
- 获取浏览器的各种属性
- 软件开发软件
- 获取屏幕属性的工具类
- android 使用到的各种工具类
- Android TextView的各种属性
- Android TextView的各种属性
- Android TextView的各种属性
- android界面的各种属性
- Android TextView的各种属性
- android的各种属性动画
- Android TextView的各种属性
- C语言将整形转化为对应的字符型
- 138 Your database instance is running. You are not able to access Oracle Enterprise Manager Database
- 为什么整个互联网行业都缺前端工程师?
- idea中maven项目部署tomcat
- C++学习笔记_对话框使用技巧
- android开发软件工具类,获取软件的各种属性
- java通过 JNA调用 so
- 35.c/c++程序员面试宝典-容器
- 文章五子棋项目总
- 当我们谈论开机的时候我们都在谈论什么(二)——保护模式
- Java自定义异常设计
- jna调用so例子
- jQuery相关注意事项
- 139 Which three statements must be true before transporting a tablespace from a database on one plat