1:查看是否有存储卡插入

String status=Environment.getExternalStorageState();
if(status.equals(Enviroment.MEDIA_MOUNTED))
{
;//说明有SD卡插入
}

2:让某个Activity透明

在OnCreate 中不设Layout,然后this.setTheme(R.style.Theme_Transparent);

3:获取屏幕宽高

DisplayMetrics dm = new DisplayMetrics();
//获取窗口属性
getWindowManager().getDefaultDisplay().getMetrics(dm);
int screenWidth = dm.widthPixels;
int screenHeight = dm.heightPixels;

4:发送短信

String body=”this is mms demo”;
Intent mmsIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(”smsto”, number, null));
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:发送彩信

StringBuilder sb = new StringBuilder();
sb.append(”file://”);
sb.append(fd.getAbsoluteFile());
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(”mmsto”, number, null));
// Below extra datas are all optional.
intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT, subject);
intent.putExtra(Messaging.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(intent);

6:发送Mail

mime = “img/jpg”;
shareIntent.setDataAndType(Uri.fromFile(fd), mime);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fd));
shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
shareIntent.putExtra(Intent.EXTRA_TEXT, body);

7:注册一个 BroadcastReceiver

registerReceiver(mMasterResetReciever, new IntentFilter(”oms.action.MASTERRESET”));
private BroadcastReceiver mMasterResetReciever = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent){
String action = intent.getAction();
if(”oms.action.MASTERRESET”.equals(action)){
RecoverDefaultConfig();
}
}
};

8:定义ContentObserver,监听某个数据表

private ContentObserver mDownloadsObserver = new DownloadsChangeObserver(Downloads.CONTENT_URI);
private class DownloadsChangeObserver extends ContentObserver {
public DownloadsChangeObserver(Uri uri) {
super(new Handler());
}
@Override
public void onChange(boolean selfChange) {}
}

9:获得 手机UA

public String getUserAgent() {   

String user_agent = ProductProperties.get(ProductProperties.USER_AGENT_KEY, null);  

return user_agent;   

}

10:清空手机上Cookie

CookieSyncManager.createInstance(getApplicationContext());   

CookieManager.getInstance().removeAllCookie();

11:建立GPRS 连接

private boolean openDataConnection() {   

DataConnection conn = DataConnection.getInstance();  

 if (connectMode == 0) {   

  ret = conn.openConnection(mContext, “cmwap”, “cmwap”, “cmwap”);  

 } else {   

  ret = conn.openConnection(mContext, “cmnet”, “”, “”);   

}  

}

12:PreferenceActivity 用法

public class Setting extends PreferenceActivity{  

 public void onCreate(Bundle savedInstanceState) {   

 super.onCreate(savedInstanceState);  

 addPreferencesFromResource(R.xml.settings);  

 }  

}

Setting.xml:

android:key=”seting2″   

android:title=”@string/seting2″   

android:summary=”@string/seting2″/>   

android:key=”seting1″   

android:title=”@string/seting1″   

android:summaryOff=”@string/seting1summaryOff”   

android:summaryOn=”@stringseting1summaryOff”/>

13:通过 HttpClient从指定server获取数据

DefaultHttpClient httpClient = new DefaultHttpClient();   

HttpGet method = new HttpGet(“http://www.baidu.com/1.html”);   

HttpResponse resp;   

Reader reader = null;   

try {   

// AllClientPNames.TIMEOUT   

HttpParams params = new BasicHttpParams();   

params.setIntParameter(AllClientPNames.CONNECTION_TIMEOUT, 10000);   

httpClient.setParams(params);  

resp = httpClient.execute(method);   

int status = resp.getStatusLine().getStatusCode();   

if (status != HttpStatus.SC_OK)  

 return false;  

 // HttpStatus.SC_OK;  

 return true;  

 } catch (ClientProtocolException e) {   

// TODO Auto-generated catch block   

e.printStackTrace();   

} catch (IOException e) {   

// TODO Auto-generated catch block e.printStackTrace();  

 } finally {   

if (reader != null)   

try {  

 reader.close();   

} catch (IOException e) {   

// TODO Auto-generated   

catch block e.printStackTrace();  

 }   

}

13个简单有用的android开发代码的更多相关文章

  1. 黑客破译android开发代码真就那么简单?

    很多程序员辛辛苦苦开发出的android开发代码,很容易就被黑客翻译了. Google似乎也发现了这个问题,从SDK2.3开始我们可以看到在android-sdk-windows\tools\下面多了 ...

  2. Android开发 --代码布局

    Android开发 --代码布局 在线性布局LinearLayout里加入view比较简单,因为属性比较少,布局简单 示例,加入一个TextView LinearLayout layout = (Li ...

  3. Android开发代码规范(转)

    Android开发代码规范 1.命名基本原则    在面向对象编程中,对于类,对象,方法,变量等方面的命名是非常有技巧的.比如,大小写的区分,使用不同字母开头等等.但究其本,追其源,在为一个资源其名称 ...

  4. android 开发代码被黑客破译有那么容易吗?

    很多程序员辛辛苦苦开发出的android开发代码,很容易就被黑客翻译了. Google似乎也发现了这个问题,从SDK2.3开始我们可以看到在android-sdk-windows\tools\下面多了 ...

  5. Android开发代码规范总结

    本篇开始总结Android开发中的一些注意事项,提高代码质量(仅供参考): 1.  Activity间的数据通信,对于数据量比较大的,避免使用 Intent + Parcelable 的方式,可以考虑 ...

  6. [Android开发] 代码code设置9.png/9-patch 图片背景后,此view中的TextView等控件显示不正常(常见于listview中)

    == 0) { convertView.setBackgroundResource(R.drawable.list_gray_9); } else { convertView.setBackgroun ...

  7. Android开发代码规范

    目录 1.命名基本原则  2.命名基本规范 2.1编程基本命名规范 2.2分类命名规范 3.分类命名规范 3.1基本数据类型命名规范 3.2控件命名规范 3.3变量命名规范 3.4整个项目的目录规范化 ...

  8. Android开发代码混淆经验(Eclipse)

    为了防止自己的劳动成果被别人窃取,混淆代码能有效防止被反编译,下面来总结以下混淆代码的步骤: 2.编辑项目下的proguard-project.txt,添加不需要混淆的规则(model.泛型.反射.第 ...

  9. Android开发 ---代码创建选项菜单、隐藏菜单项、菜单的生命周期,菜单按钮图标设置、搜索框、xml中设置子菜单

    1.activity_main.xml 描述: 定义了一个按钮 <?xml version="1.0" encoding="utf-8"?> < ...

随机推荐

  1. hdu3652B-number

    Problem Description A wqb-number, or B-number for short, is a non-negative integer whose decimal for ...

  2. 实现一个简单的sniffer

    #include<stdio.h> #include<pcap.h> #include<unistd.h> #include<stdlib.h> //# ...

  3. frame,bounds,center-三者的含义

    frame与bounds的区别比较 frame,bounds,center-三者的含义 偶然觉的,这三个属性有时候定位的时候,需要用.于是就来搞清楚,到底frame,bounds,center 这三个 ...

  4. 转:关于PHP性能优化

    原文来自于:http://www.cnblogs.com/qq78292959/archive/2012/12/28/2837272.html 1.升级硬件的一般规则:对于 PHP 脚本而言,主要的瓶 ...

  5. How Much Did It Rain? Winner's Interview: 1st place, Devin Anzelmo

    How Much Did It Rain? Winner's Interview: 1st place, Devin Anzelmo An early insight into the importa ...

  6. etErrorMode(SEM_NOGPFAULTERRORBOX); 去除错误对话框.

    etErrorMode(SEM_NOGPFAULTERRORBOX);  去除错误对话框. http://www.cnblogs.com/-clq/archive/2012/01/22/2328783 ...

  7. Java switch-case

    首先从原理上来阐述这个问题: switch(表达式){case 常量表达式1:语句1;....case 常量表达式2:语句2;default:语句;}1.default就是如果没有符合的case就执行 ...

  8. TransactionScope IsolationLevel 事务隔离级别

    事务有四个特性 第一原子性,事务具有独立的不能被拆分的,不能只做部分,事务的性质是要么全做,要么都不做. 第二统一性,在事务执行之前和事务执行之后的数据是一致. 第三隔离性,事务是独立的,开发者不能查 ...

  9. bzoj3531

    不难想到树链剖分这题的难点是记录的是路径上宗教相同的点裸的想法是对每一种宗教都开一棵线段树,记录每个点的评级但显然这样会爆空间,仔细分析一下,这些线段树内很多点压根就没用到因此我们考虑对线段树动态开点 ...

  10. iOS应用架构浅谈

    (整理至http://www.cocoachina.com/ios/20150414/11557.html) 缘由 从事iOS工作一年多了,主要从事QQ钱包SDK开发和财付通app维护,随着对业务的慢 ...