android 软件 安装 卸载 启动 分享 桌面快捷方式
2015-07-13 17:22
441 查看
/**
* 分享一个应用程序
*/
private void shareApk() {
Intent intent = new Intent();
intent.setAction("android.intent.action.SEND");
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT,
"推荐您使用一款软件,名称为: " + appInfo.getPackageName());
startActivity(intent);
}
/**
* 启动软件
*/
private void startupApk() {
// TODO Auto-generated method stub
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage(appInfo.getPackageName());
if (intent != null) {
startActivity(intent);
} else {
Toast.makeText(this, "不能开启当前应用!", 0).show();
}
}
/**
* 卸载软件
*/
private void uninstallApk() {
// <action android:name="android.intent.action.VIEW" />
// <action android:name="android.intent.action.DELETE" />
// <category android:name="android.intent.category.DEFAULT" />
// <data android:scheme="package" />
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
intent.setAction("android.intent.action.DELETE");
intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse("package:" + appInfo.getPackageName()));
if (appInfo.getFlags() == 0) {
Toast.makeText(AppManagerActivity.this, "卸载系统软件需要获取root权限", 1)
.show();
return;
}
startActivityForResult(intent, 0);
}
/**
*安装软件
*
*/
private void installApk(File t) {
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.setDataAndType(Uri.fromFile(t),
"application/vnd.android.package-archive");
startActivity(intent);
}
private void installShortCut() {
boolean b = sp.getBoolean("shortcuts", false);
if (b) {
return;
}
Intent intent = new Intent();
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "手机小卫士");
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory
.decodeResource(getResources(), R.drawable.ic_launcher));
Intent shortcutIntent = new Intent();
shortcutIntent.setAction("android.intent.action.MAIN");
shortcutIntent.addCategory("android.intent.category.LAUNCHER");
shortcutIntent.setClassName(getPackageName(),"com.itheima.mobiesafe.SplashActivity" );
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
sendBroadcast(intent);
Editor editor = sp.edit();
editor.putBoolean("shortcuts", true);
editor.commit();
}
* 分享一个应用程序
*/
private void shareApk() {
Intent intent = new Intent();
intent.setAction("android.intent.action.SEND");
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT,
"推荐您使用一款软件,名称为: " + appInfo.getPackageName());
startActivity(intent);
}
/**
* 启动软件
*/
private void startupApk() {
// TODO Auto-generated method stub
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage(appInfo.getPackageName());
if (intent != null) {
startActivity(intent);
} else {
Toast.makeText(this, "不能开启当前应用!", 0).show();
}
}
/**
* 卸载软件
*/
private void uninstallApk() {
// <action android:name="android.intent.action.VIEW" />
// <action android:name="android.intent.action.DELETE" />
// <category android:name="android.intent.category.DEFAULT" />
// <data android:scheme="package" />
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
intent.setAction("android.intent.action.DELETE");
intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse("package:" + appInfo.getPackageName()));
if (appInfo.getFlags() == 0) {
Toast.makeText(AppManagerActivity.this, "卸载系统软件需要获取root权限", 1)
.show();
return;
}
startActivityForResult(intent, 0);
}
/**
*安装软件
*
*/
private void installApk(File t) {
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.setDataAndType(Uri.fromFile(t),
"application/vnd.android.package-archive");
startActivity(intent);
}
private void installShortCut() {
boolean b = sp.getBoolean("shortcuts", false);
if (b) {
return;
}
Intent intent = new Intent();
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "手机小卫士");
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory
.decodeResource(getResources(), R.drawable.ic_launcher));
Intent shortcutIntent = new Intent();
shortcutIntent.setAction("android.intent.action.MAIN");
shortcutIntent.addCategory("android.intent.category.LAUNCHER");
shortcutIntent.setClassName(getPackageName(),"com.itheima.mobiesafe.SplashActivity" );
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
sendBroadcast(intent);
Editor editor = sp.edit();
editor.putBoolean("shortcuts", true);
editor.commit();
}
相关文章推荐
- Android 数据库SQLite Cursor数据遍历读取
- android悬浮窗应用
- 使用WIFI连接android进行调试和adb操作
- android各种资源的详细解释
- 手电筒的制作
- Androidの自定义对话框AlertDialog(一)
- android线程销毁
- android知识杂记(二)
- Android Fragment 真正的完全解析
- Android Fragment 真正的完全解析
- 基于Jenkins+git+gradle的android持续集成
- Tablayout(Android) 的几个重要属性
- android studio中出现的问题
- Android EditText输入最大值提示功能
- android知识杂记(一)
- 【Android】设置全屏和横屏
- android studio配置AndroidAnnotations
- android新组件RecyclerView使用介绍和进阶使用
- android raw与assets区别
- Android开发之如何监听让服务不被杀死(service+broadcast)