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. Problem A: The Monocycle

    uva10047:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&am ...

  2. ios入门之c语言篇——基本函数——3——判断日期是一年的第几天

    3.判断日期是一年的第几天 参数返回值解析: 参数: y:int,年份: m:int,月份 d:int,日期 返回值: sum:传入日期是当年的第几天: 函数解析: leapyear(y);判断y是不 ...

  3. Cognos请求流程——<转>

    访问Cognos8 匿名访问 用户通过浏览器发起Cognos访问请求,请求被送至Cognos Gateway Gateway接收请求并发送给一个dispatcher dispatcher发现请求没有附 ...

  4. 深入浅出 Java Concurrency (1) : J.U.C的整体认识

    转 http://www.blogjava.net/xylz/archive/2010/06/30/324915.html 去年年底有一个Guice的研究计划,可惜由于工作“繁忙”加上实际工作中没有用 ...

  5. 关于Mysql当中"Got error 134 from storage engine"的解决办法

    今天在开发程序的时候,有一个表, 当调用这个类别时总是调用不出来,很是恼火.后台打印sql语句为: SELECT * FROM `xx_article` WHERE `cid1` =6 LIMIT 0 ...

  6. ♫【异步】短小强悍的JavaScript异步调用库

    短小强悍的JavaScript异步调用库 var queue = function(funcs, scope) { (function next() { if(funcs.length > 0) ...

  7. QTP自传之录制

    录制,是一件吃力不讨好的活.很多人以为录制就是我的主要甚至全部的功能,这是大错特错的.不过,录制功能却是不熟悉我的人了解我的有效途径,是大家学习的有力武器.今天就先从录制功能说起吧. 说到录制,就不得 ...

  8. Introduction to Glide, Image Loader Library for Android, recommended by Google

    In the passed Google Developer Summit Thailand, Google introduced us an Image Loader Library for And ...

  9. lightoj 1198 最大权重匹配

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1198 #include <cstdio> #include <cst ...

  10. C#序列化和反序列化

    序列化和反序列化 序列化就是将一个对象的状态(各个属性量)保存起来,然后在适当的时候再获得. 序列化分为两大部分:序列化和反序列化.序列化是这个过程的第一部分,将数据分解成字节流,以便存储在文件中或在 ...