getWindow().setFormat(PixelFormat.TRANSLUCENT);
* Activity.runOnUiThread( Runnable ) * View.post( Runnable ) * View.postDelayed( Runnable, long ) * Hanlder
requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
方法A: WindowManager windowManager = getWindowManager(); Display display = windowManager.getDefaultDisplay(); hAndW[0] = display.getWidth(); hAndW[1] = display.getHeight(); 方法B: DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); hAndW[0] = dm.widthPixels; hAndW[1] = dm.heightPixels;
Uri uri = Uri.parse("http://www.google.com"); Intent it = new Intent(Intent.ACTION_VIEW, uri); startActivity(it);
ActivityManager.MemoryInfo outInfo = new ActivityManager.MemoryInfo(); activityManager.getMemoryInfo(outInfo); //可用内存 outInfo.availMem //是否在低内存状态 outInfo.lowMemory 取得ScrollView的实际高度 scrollview.getHeight() scrollview.getMeasuredHeight() scrollview.compute() scrollview.getLayoutParams().height
A.Define a class derived from class BroadcastReceiver; B.Register broadcast receiver; MyBroadcastReceiver myReceiver = new MyBroadcastReceiver(); IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_INSTALL); filter.addAction(Intent.ACTION_PACKAGE_REMOVED); filter.addAction(Intent.ACTION_PACKAGE_ADDED); filter.addAction(Intent.ACTION_PACKAGE_CHANGED); filter.addAction(Intent.ACTION_PACKAGE_RESTARTED); ... filter.addDataScheme("package"); //This line is very important. Otherwise, broadcast can't be received. registerReceiver(myReceiver, filter); Notes: The package name is Intent.mData. Intent.mData is not available in SDK 1.0, but it can be retrieved by calling Intent.getDataString();
A. //Connect via WIFI 通过wifi WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); int ipAddress = wifiInfo.getIpAddress(); B. //Connect via GPRS通过gprs public String getLocalIpAddress(){ try{ for(Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();){ NetworkInterface intf = en.nextElement(); for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();){ InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()){ return inetAddress.getHostAddress().toString(); } } } }catch (SocketException ex){ Log.e(S.TAG, ex.toString()); } return null; }
Intent i=new Intent(Intent.ACTION_MAIN); i.addCategory(Intent.CATEGORY_HOME); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i);
editText.setFocusable(true); editText.requestFocus(); editText.setFocusableInTouchMode(true);
12、MediaPalyer和SurfaceView播放视频设置surfaceview
//设置SurfaceView自己不管理的缓冲区 surfaceView.getHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); //设置播放时打开屏幕 surfaceView.getHolder.setKeepScreenOn(true)
13、判断SD卡是否存在
if(!Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)){ }