资源描述:
《Android编程14个很有用的代码片段.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Android编程14个很有用的代码片段1:查看是否有存储卡插入Stringstatus=Environment.getExternalStorageState();if(status.equals(Enviroment.MEDIA_MOUNTED)){说明有SD卡插入}2:让某个Activity透明OnCreate中不设Layoutthis.setTheme(R.style.Theme_Transparent);以下是Theme_Transparent的定义(注意transparent_bg是一副透明的图片)3:在屏幕元素
2、中设置句柄使用Activity.findViewById来取得屏幕上的元素的句柄.使用该句柄您可以设置或获取任何该对象外露的值.TextViewmsgTextView=(TextView)findViewById(R.id.msg);msgTextView.setText(R.string.push_me);4:发送短信Stringbody=”thisismmsdemo”;Intentmmsintent=newIntent(Intent.ACTION_SENDTO,Uri.fromParts(”smsto”,number,n
3、ull));mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,true);mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,true);startActivity(mmsintent);5:发送彩信StringBuildersb=newStringBuild
4、er();sb.append(”file://”);sb.append(fd.getAbsoluteFile());Intentintent=newIntent(Intent.ACTION_SENDTO,Uri.fromParts(”mmsto”,number,null));//Belowextradatasarealloptional.intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT,subject);intent.putExtra(Messaging.
5、KEY_ACTION_SENDTO_MESSAGE_BODY,body);intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI,sb.toString());intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,composeMode);intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,exitOnSent);startActivity(inte
6、nt);6:显示toastToast.makeText(this._getApplicationContext(),R.string._item,Toast.LENGTH_SHORT).show();7:发送Mailmime=“img/jpg”;shareIntent.setDataAndType(Uri.fromFile(fd),mime);shareIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(fd));shareIntent.putExtra(Intent.EXTRA
7、_SUBJECT,subject);shareIntent.putExtra(Intent.EXTRA_TEXT,body);8:注册一个BroadcastReceiverregisterReceiver(mMasterResetReciever,newIntentFilter(”OMS.action.MASTERRESET”));privateBroadcastReceivermMasterResetReciever=newBroadcastReceiver(){publicvoidonReceive(Contextcon
8、text,Intentintent){Stringaction=intent.getAction();if(”oms.action.MASTERRESET”.equals(action)){RecoverDefaultConfig();}}};9:定义ContentObserver,监听某