background image

Android 编程中 14 个解决实际问题的代码片段

1

  

、查看是否有存储卡插入

1

String status=Environment.getExternalStorageState();    

2

   

3

if ( status.equals ( Enviroment.MEDIA_MOUNTED ) )    

4

{    

5

    说明有 SD

    

卡插入

6

}  

2、让某个 Activity 透明
OnCreate 中不设 Layout     

7

this.setTheme(R.style.Theme_Transparent);   

以下是 Theme_Transparent 的定义(注意 transparent_bg

   

是一副透明的图片)

3、在屏幕元素中设置句柄
使用 Activity.findViewById 来取得屏幕上的元素的句柄,使用该句柄您可以设置或获取任
何该对象外露的值。

8

TextView msgTextView = (TextView)findViewById(R.id.msg);       

9

msgTextView.setText(R.string.push_me);  

4、发送短信

10

    String body=”this is mms demo”;     

11

        

12

        Intent mmsintent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(”smsto”, 

number, null));     
13

        

14

        mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, 

body);     
15

        mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, 

true);     
16

    mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, true); 

17

        

18

    startActivity(mmsintent); 

5、发送彩信

19

 StringBuilder sb = new StringBuilder();     

20

        

21

    sb.append(”file://”);     

22

        

                     找软件资料,就到一览软件文库

http://wk.yl1001.com/rj/