/**
* 分享一个应用程序
*/
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();
}