android点滴3
到android设置中的卸载界面
Uri uri = Uri.fromParts("package", appInfo.packageName, null); Intent it=new Intent();it.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");it.setData(uri);startActivity(it);Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);intent.putExtra(SearchManager.QUERY,"searchString")startActivity(intent);
<intent-filter> <action android:name="chroya.foo"/> <category android:name="android.intent.category.DEFAULT"/></intent-filter>
Intent intent = new Intent("chroya.foo");startActivity(intent);ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);ComponentName cn = am.getRunningTasks(1).get(0).topActivity;Log.d("", "pkg:"+cn.getPackageName());Log.d("", "cls:"+cn.getClassName()); Intent intent = new Intent(); intent.setClassName("包名", "类名"); if(getPackageManager().resolveActivity(intent, 0) == null) { //说明系统中不存在这个activity }WindowManager.LayoutParams attrs = getWindow().getAttributes();attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;getWindow().setAttributes(attrs);getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
WindowManager.LayoutParams attrs = getWindow().getAttributes();attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);getWindow().setAttributes(attrs);getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
Rect frame = new Rect();getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);int statusBarHeight = frame.top;
int contentTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();//statusBarHeight是上面所求的状态栏的高度int titleBarHeight = contentTop - statusBarHeight;
private ImageView waitView;private final void showWaiting() { try {WindowManager.LayoutParams lp = null;lp = new WindowManager.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT,WindowManager.LayoutParams.TYPE_TOAST ,WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,PixelFormat.TRANSLUCENT| WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW) ;WindowManager mWindowManager = (WindowManager) G.appInstance.getSystemService(Context.WINDOW_SERVICE);if (waitView == null) {LayoutInflater inflate = (LayoutInflater) G.appInstance.getSystemService(Context.LAYOUT_INFLATER_SERVICE);waitView = (ImageView) inflate.inflate(R.layout.waiting_layout,null);}mWindowManager.addView(waitView, lp);} catch (Throwable e) {}}boolean isInstallShortcut = false ;final ContentResolver cr = context.getContentResolver();final String AUTHORITY = "com.android.launcher.settings";final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/favorites?notify=true");Cursor c = cr.query(CONTENT_URI,new String[] {"title","iconResource" },"title=?",new String[] {"XXX" }, null);//XXX表示应用名称。if(c!=null && c.getCount()>0){isInstallShortcut = true ;}/*try {while (c.moveToNext()) { String tmp = "";tmp = c.getString(0);}} catch (Exception e) {} finally {c.close();}*/return isInstallShortcut ;}Intent intent = new Intent();//第一个参数另一个应用的包名,第二个是需要启动的类intent.setComponent(new ComponentName("com.Ex03_03","com.Ex03_03.Ex03_03"));startActivity(intent);<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.yourcompany.yourapp" android:versionCode="109" android:versionName="0.1.6.109 dev"> ...</manifest> public static int getVersionCode(Context context) { PackageManager pm = context.getPackageManager(); try { PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); return pi.versionCode; } catch (NameNotFoundException ex) {} return 0;}Toast t = Toast.makeText(this, "Hello", Toast.LENGTH_SHORT);t.setGravity(Gravity.FILL_HORIZONTAL, 0, 0);
<View android:layout_width="fill_parent" android:layout_height="1px" android:background="?android:attr/listDivider" />
final Intent intent = new Intent(Intent.ACTION_MAIN, null);intent.addCategory(Intent.CATEGORY_LAUNCHER);final ComponentName cn = new ComponentName("com.android.settings","com.android.settings.fuelgauge.PowerUsageSummary");intent.setComponent(cn);intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);startActivity( intent);//ComponentName 两个参数一个是包名 一个是包下的主类Uri uri = Uri.fromParts("package",“Your Package name here”, null);Intent deleteIntent = new Intent(Intent.ACTION_DELETE, uri);startActivity(deleteIntent);AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE); switch (am.getRingerMode()) { case AudioManager.RINGER_MODE_SILENT: Log.i("MyApp","Silent mode"); break; case AudioManager.RINGER_MODE_VIBRATE: Log.i("MyApp","Vibrate mode"); break; case AudioManager.RINGER_MODE_NORMAL: Log.i("MyApp","Normal mode"); break; } RelativeLayout.LayoutParams parms=(RelativeLayout.LayoutParams)img.getLayoutParams();parms.leftMargin = (int) (Math.random() * 320);parms.topMargin = (int) (Math.random() * 480);img.setLayoutParams(parms); img.invalidate();
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); View view = getCurrentFocus(); if (view != null){ // imm.showSoftInput(view, 0); //显示软键盘 imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); // imm.hideSoftInputFromWindow(view.getWindowToken(), 0);//隐藏软键盘 // InputMethodManager.HIDE_NOT_ALWAYS); } @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); Window win = getWindow(); win.requestFeature(Window.FEATURE_LEFT_ICON); setContentView(R.layout.mylayout); win.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon); }protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);//先给Activity注册界面进度条功能setContentView(R.layout.main);setProgressBarIndeterminateVisibility(true);//在需要显示进度条的时候调用这个方法setProgressBarIndeterminateVisibility(false);//在不需要显示进度条的时候调用这个方法}很简单 简单的有时候是因为我们太浮躁<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_horizontal"> <TabHost android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" > ... ... ... </TabHost> </LinearLayout> 外面加一层LinearLayout
String locale = context.getResources().getConfiguration().locale.getCountry(); String locale = context.getResources().getConfiguration().locale.getDisplayCountry(); TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); String countryCode = tm.getSimCountryIso();
@Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); }TelephonyManager telMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); int simState = telMgr.getSimState(); switch (simState) { case TelephonyManager.SIM_STATE_ABSENT: // do something break; case TelephonyManager.SIM_STATE_NETWORK_LOCKED: // do something break; case TelephonyManager.SIM_STATE_PIN_REQUIRED: // do something break; case TelephonyManager.SIM_STATE_PUK_REQUIRED: // do something break; case TelephonyManager.SIM_STATE_READY: // do something break; case TelephonyManager.SIM_STATE_UNKNOWN: // do something break; }ContactItem getContactByAddr(Context context, final SMSItem sms) { Uri personUri = Uri.withAppendedPath( ContactsContract.PhoneLookup.CONTENT_FILTER_URI, sms.mAddress); Cursor cur = context.getContentResolver().query(personUri, new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null ); if( cur.moveToFirst() ) { int nameIdx = cur.getColumnIndex(PhoneLookup.DISPLAY_NAME); ContactItem item = new ContactItem(); item.mName = cur.getString(nameIdx); cur.close(); return item; } return null; }TabWidget tabWidget = mTabHost.getTabWidget();int count = tabWidget.getChildCount();for(int i = 0;i<count;i++){ View view = tabWidget.getChildTabViewAt(i);// tabWidget.getChildAt(i); view.getLayoutParams().height = 40;}

Bitmap bm = BitmapFactory.decodeResource(getResources(),R.drawable.cwj); Drawable[] array = new Drawable[3]; array[0] = new PaintDrawable(Color.BLACK); //黑色 array[1] = new PaintDrawable(Color.WHITE); //白色 array[2] = new BitmapDrawable(bm); //位图资源 LayerDrawable ld = new LayerDrawable(array); //参数为上面的Drawable数组 ld.setLayerInset(1, 1, 1, 1, 1); //第一个参数1代表数组的第二个元素,为白色 ld.setLayerInset(2, 2, 2, 2, 2); //第一个参数2代表数组的第三个元素,为位图资源 mImageView.setImageDrawable(ld);