1.在代码中改控件的高度
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)holder.imageRv.getLayoutParams();
layoutParams.height = 150;
holder.imageLyt.setLayoutParams(layoutParams);
2.查看应用程序最高可用内存
int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);Log.d("TAG", "Max memory is " + maxMemory + "KB");3.判断是Pad或者手机
public boolean isTabletDevice() {TelephonyManager telephony = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);int type = telephony.getPhoneType();if (type == TelephonyManager.PHONE_TYPE_NONE) {return true;} else {return false;}}4.不让文本框输入中文5.静默卸载系统软件和第三方软件
- <span style="font-size: 16px; ">android:digits="1234567890qwertyuiopasdfghjklzxcvbnm`-=[]\;,./~!@#$%^*()_+}{:?&<>"'"
- 这样就不会输入中文
- 一个个卸载软件,弹出卸载软件提示好麻烦,现在特作出下列方法,可以静默卸载
- 静默安装敬请期待。。。。
- //下面3句是静默卸载系统软件命令
- String busybox="mount -o remount rw /system";
- String chmod="chmod 777 /system/app/HtcTwitter.apk";
- uninstallapk="rm -r /system/app/HtcTwitter.apk";
- //下面3句是静默卸载第三方软件命令
- String busybox1="mount -o remount rw /data";
- String chmod1="chmod 777 /data/app/com.yingyonghui.market-2.apk";
- uninstallapk1="pm uninstall com.yingyonghui.market";
- chmodApk(busybox1,chmod1);
- /*
- * 对要卸载的apk赋予权限
- */
- public void chmodApk(String busybox ,String chmod)
- {
- try {
- Process process = null;
- DataOutputStream os = null;
- process = Runtime.getRuntime().exec("su");
- os = new DataOutputStream(process.getOutputStream());
- os.writeBytes(busybox);
- os.flush();
- os.writeBytes(chmod);
- os.flush();
- os.close();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- /*
- * 卸载apk
- */
- public void uninstallApk(String uninstallapk)
- {
- try {
- Process process = null;
- DataOutputStream os = null;
- process = Runtime.getRuntime().exec("su");
- os = new DataOutputStream(process.getOutputStream());
- os.writeBytes(uninstallapk);
- os.flush();
- os.close();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- 6.给图片加水印
try {ImageView img=(ImageView) findViewById(R.id.test_img_file);//获取从本地获取的文件路径,用FileInputstream读入文件,并将图片文件转换成位图Bundle bundle=getIntent().getExtras();String path=bundle.getString("test");FileInputStream fa=new FileInputStream(path);Bitmap bm=BitmapFactory.decodeStream(fa);//原图Bitmap wm=BitmapFactory.decodeResource(getResources(), R.drawable.wate_market);//水印//将creatBitmap()方法的返回值(返回位图)放到图片控件显示img.setImageBitmap(createBitMap(bm,wm));} catch (IOException e) {e.printStackTrace();}}});}private Bitmap createBitMap(Bitmap src,Bitmap wmsrc){/*** 水印制作方法*/String tag="xx";Log.d(tag, "开始了,画图");if(src==null){return null;}int w=src.getWidth();int h=src.getHeight();int wmw=wmsrc.getWidth();int wmh=wmsrc.getHeight();//create the new bitmapBitmap newb=Bitmap.createBitmap(w,h,Config.ARGB_8888);//创建一个底图Canvas cv=new Canvas(newb);//将底图画进去cv.drawBitmap(src, 0, 0,null);//在0,0坐标开始画入src//讲水印画进去cv.drawBitmap(wmsrc, w-wmw+5, h-wmh+5, null);//保存图片cv.save(Canvas.ALL_SAVE_FLAG);cv.restore();return newb;
}}7.判断网络状态.
State mWifiState = null;State mMobileState = null;ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);mWifiState = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();mMobileState = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();if (mWifiState != null && mMobileState != null && State.CONNECTED != mWifiState&& State.CONNECTED == mMobileState) {// 手机网络连接成功} else if (mWifiState != null && mMobileState != null && State.CONNECTED != mWifiState && State.CONNECTED != mMobileState) {mHandler.sendEmptyMessage(MSG_SHOW_NET_DIALOG);} else if (mWifiState != null && State.CONNECTED == mWifiState) {// 无线网络连接成功}