个人android笔记(二)
1、卸载某一应用,首先应该知道该应用的包名
public static void uninstallApk(Context context, String packageName) {Uri packageURI = Uri.parse("package:" + packageName);Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);context.startActivity(uninstallIntent);}CharSequence text = getString(R.string.app_name); textview.setText(text);
public String getResolution(){//获得屏幕分辨率 DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); return dm.widthPixels + "*" + dm.heightPixels; }<?xml version="1.0" encoding="utf-8"?><resources> <style name="mystyle"> <item name="android:textSize">18sp</item> <item name="android:textColor">#EC9237</item> <item name="android:fromAlpha">0.0</item> <item name="android:toAlpha">0.0</item> </style></resources>
<TextView style="@style/mystyle" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="hello world!!" />
private void doAtFirstRun() { SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences.Editor editor = settings.edit(); if (!settings.getBoolean(FIRST_RUN_TAG, false)) {//只有第一次安装才创建icon editor.putBoolean(FIRST_RUN_TAG, true); createShortcut(); } editor.commit(); }private void createShortcut() { Intent shortcutIntent = null; shortcutIntent = new Intent(Intent.ACTION_MAIN); shortcutIntent.setClassName(this, this.getClass().getName()); shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); final Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getResources().getString(R.string.app_name)); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.icon)); intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); sendBroadcast(intent); }<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />