- 浏览: 61934 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (37)
- Oracle (2)
- JavaScript (4)
- Java (7)
- Flex (0)
- SqlServer (0)
- html (1)
- extjs (5)
- Struts+Spring+Hibernate (0)
- Android (10)
- OpenFlashChart (0)
- Myeclipse (0)
- J2EE (2)
- Ext中window的用法(人员信息)Beta 3.0 (0)
- CSS (1)
- 没事,看看,会有帮助 (1)
- HTML5 (0)
- hadoop (1)
- nagios (1)
- 文件夹监控(JNotify/Sigar) (2)
- spring rest (1)
- HBase (0)
最新评论
-
learn_2010:
IE 8 不兼容,层里面的内容没有办法点击了.
DIV解决背景图片拉伸而不平铺的效果 -
弃天笑:
说得很有道理呀一早看到这个篇文章就好了
总结过去10年的程序员生涯 (经验) -
intresources:
二进制 原码 反码 补码 -
zhangxpower:
恩,有.我试过了.
jquery的$(document).ready()与window.onload区别 -
lybykw:
有这等事?
jquery的$(document).ready()与window.onload区别
Android很有用的代码片段
1:查看是否有存储卡插入
[img]
2:让某个Activity透明
OnCreate中不设Layout this.setTheme(R.style.Theme_Transparent);
以下是Theme_Transparent的定义(注意transparent_bg是一副透明的图片)
3:在屏幕元素中设置句柄
使用Activity.findViewById来取得屏幕上的元素的句柄. 使用该句柄您可以设置或获取任何该对象外露的值.
4:发送短信
6:发送Mail
7:注册一个BroadcastReceiver
8:定义ContentObserver,监听某个数据表
9:获得 手机UA
10:清空手机上Cookie
11:建立GPRS连接
12:PreferenceActivity 用法
13:通过HttpClient从指定server获取数据
14:显示toast
Java代码
the end .......
1:查看是否有存储卡插入
[img]
1.String status=Environment.getExternalStorageState(); 2.if(status.equals(Enviroment.MEDIA_MOUNTED)) 3.{ 4. 说明有SD卡插入 5.}[/img]
2:让某个Activity透明
OnCreate中不设Layout this.setTheme(R.style.Theme_Transparent);
以下是Theme_Transparent的定义(注意transparent_bg是一副透明的图片)
3:在屏幕元素中设置句柄
使用Activity.findViewById来取得屏幕上的元素的句柄. 使用该句柄您可以设置或获取任何该对象外露的值.
1.TextView msgTextView = (TextView)findViewById(R.id.msg); 2. msgTextView.setText(R.string.push_me);
4:发送短信
1. String body=”this is mms demo”; 2.Intent mmsintent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(”smsto”, number, null)); 3.mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body); 4.mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, true); 5.mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, true); 6. startActivity(mmsintent); 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:发送彩信
1.StringBuilder sb = new StringBuilder(); 2. sb.append(”file://”); 3. sb.append(fd.getAbsoluteFile()); 4. Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(”mmsto”, number, null)); 5. // Below extra datas are all optional. 6. intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT, subject); 7. intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body); 8. intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI, sb.toString()); 9. intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, composeMode); 10. intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, exitOnSent); 11. startActivity(intent); 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
1. mime = “img/jpg”; 2.shareIntent.setDataAndType(Uri.fromFile(fd), mime); 3.shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fd)); 4.shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject); 5.shareIntent.putExtra(Intent.EXTRA_TEXT, body); 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
1.registerReceiver(mMasterResetReciever, new IntentFilter(”oms.action.MASTERRESET”)); 2.private BroadcastReceiver mMasterResetReciever = new BroadcastReceiver() { 3. public void onReceive(Context context, Intent intent){ 4. String action = intent.getAction(); 5. if(”oms.action.MASTERRESET”.equals(action)){ 6. RecoverDefaultConfig(); 7. } 8. } 9. }; 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,监听某个数据表
1.private ContentObserver mDownloadsObserver = new DownloadsChangeObserver(Downloads.CONTENT_URI); 2.private class DownloadsChangeObserver extends ContentObserver { 3. public DownloadsChangeObserver(Uri uri) { 4. super(new Handler()); 5. } 6. @Override 7. public void onChange(boolean selfChange) {} 8. } 9. 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
1.public String getUserAgent() 2. { 3. String user_agent = ProductProperties.get(ProductProperties.USER_AGENT_KEY, null); 4. return user_agent; 5. } public String getUserAgent() { String user_agent = ProductProperties.get(ProductProperties.USER_AGENT_KEY, null); return user_agent; }
10:清空手机上Cookie
1.CookieSyncManager.createInstance(getApplicationContext()); 2. CookieManager.getInstance().removeAllCookie(); CookieSyncManager.createInstance(getApplicationContext()); CookieManager.getInstance().removeAllCookie();
11:建立GPRS连接
1.//Dial the GPRS link. 2. private boolean openDataConnection() { 3. // Set up data connection. 4. DataConnection conn = DataConnection.getInstance(); 5. if (connectMode == 0) { 6. ret = conn.openConnection(mContext, “cmwap”, “cmwap”, “cmwap”); 7. } else { 8. ret = conn.openConnection(mContext, “cmnet”, “”, “”); 9. } 10. } //Dial the GPRS link. private boolean openDataConnection() { // Set up data connection. DataConnection conn = DataConnection.getInstance(); if (connectMode == 0) { ret = conn.openConnection(mContext, “cmwap”, “cmwap”, “cmwap”); } else { ret = conn.openConnection(mContext, “cmnet”, “”, “”); } }
12:PreferenceActivity 用法
1.public class Setting extends PreferenceActivity 2.{ 3. public void onCreate(Bundle savedInstanceState) { 4. super.onCreate(savedInstanceState); 5. addPreferencesFromResource(R.xml.settings); 6. } 7.} 8.Setting.xml: 9. android:key=”seting2″ 10. android:title=”@string/seting2″ 11. android:summary=”@string/seting2″/> 12. android:key=”seting1″ 13. android:title=”@string/seting1″ 14. android:summaryOff=”@string/seting1summaryOff” 15. android:summaryOn=”@stringseting1summaryOff”/> 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获取数据
1. DefaultHttpClient httpClient = new DefaultHttpClient(); 2.HttpGet method = new HttpGet(“http://www.baidu.com/1.html”); 3.HttpResponse resp; 4.Reader reader = null; 5.try { 6. // AllClientPNames.TIMEOUT 7. HttpParams params = new BasicHttpParams(); 8. params.setIntParameter(AllClientPNames.CONNECTION_TIMEOUT, 10000); 9. httpClient.setParams(params); 10. resp = httpClient.execute(method); 11. int status = resp.getStatusLine().getStatusCode(); 12. if (status != HttpStatus.SC_OK) return false; 13. // HttpStatus.SC_OK; 14. return true; 15.} catch (ClientProtocolException e) { 16. // TODO Auto-generated catch block 17. e.printStackTrace(); 18.} catch (IOException e) { 19. // TODO Auto-generated catch block 20. e.printStackTrace(); 21.} finally { 22. if (reader != null) try { 23. reader.close(); 24. } catch (IOException e) { 25. // TODO Auto-generated catch block 26. e.printStackTrace(); 27. } 28.} 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(); } }
14:显示toast
Java代码
1. 2.Toast.makeText(this._getApplicationContext(), R.string._item, Toast.LENGTH_SHORT).show();
the end .......
发表评论
-
android中intent的详解、用法、参数
2011-08-22 18:53 2801在一个Android应用中,主要是由四种组件组成的,这四种组件 ... -
ContentProvider详解及使用大全
2011-08-19 15:53 1864Android中的Content provider机制可支持在 ... -
花样Android ProgressBar 史上最强大讲解
2011-08-17 01:12 3016多式样ProgressBar 普通圆形ProgressBar ... -
android eclipse中查看源码
2011-08-16 22:23 972在开发android 时不能查看源码必是很不爽的一件事,看过网 ... -
conversion to dalvik format failed with error 1的解决办法
2011-08-15 17:31 745android低版本工程(如1.5)放到高版本环境中(如2.2 ... -
android解决中文乱码的所有方案
2011-08-07 14:27 2194解决方法: 1.修改Tomcat服务器conf\server. ... -
permission大全及场景的用法
2011-08-05 00:23 1070以下附Android 权限大全中英对照,以备使用,根据网友提醒 ... -
sax(simple api for xml ) 图解1.0
2011-08-03 08:45 684方便以后的查看。 -
manifest.xml 详解1
2011-08-03 00:14 1198一,重要性AndroidManife ... -
aidl
2011-07-22 14:48 0<当前任务>
相关推荐
Android第七章Android广播机制最新版,实用教程,2019年,基于广播机制,通信互用,Android开发
详细介绍Android开发的理论基础,书中还附有示例。并且书中还附带了Android开发中总结的笔记心得。
[Android开发实用技巧]实现圆角Activity 原文地址: http://blog.csdn.net/ruils/article/details/16953961
android开发基本入门资料,学习开发android,搭建环境,开发实例,market发布
Android 开发实用功能 用法 droidenv : 初始化给定目标的环境 compile : 编译整个树 (make -j4) 或子文件夹 (mmm && make snod) emu : 运行模拟器 安装 克隆回购 git clone https://github.com/rchiossi/droidenv ~...
Android在线音乐播放器很实用Android开发
basic4android+开发教程实用.pdf
《Android应用开发范例精解》通过通俗易懂的开发实例及项目案例,详细介绍了Android应用开发的知识体系及实用开发技术。 《Android应用开发范例精解》共14章,分为3篇。第1篇为基础篇,涵盖Android背景及开发环境和...
android实用教程android实用教程android实用教android实用教程程android实用教android实用教程程android实用教程
Android+Cookbook实用开发技巧集101.pdf
android开发中超炫实用的动画,经典源码,开发中应用广泛
哔哩哔哩"2020原生Android基础实用开发"视频的学习笔记
180个Android开发常见问题、实用技巧及注意事项,有利于Android开发过程中少走弯路。
全书论述了Android开发概述,Android应用程序组成,Android UI(用户界面)基础,Android UI系统控件基础,Android UI系统控件进阶,Android UI菜单、对话框,Android组件广播消息与服务,Android数据存储与访问,...
android程序开发实用教程电子课件,一共十五章内容,全硬核实战,非常适合android开发中文入门。
个人整理的Android开发资料,实用,具体下载地址间附件内网盘; 疯狂Android讲义高清PDF及源代码 深入浅出Android高清PDF及源代码 Google.Android开发入门与实战.PDF及源代码 Android应用开发入门教程(经典版).pdf ...
Android开发视频教学源码 Android开发学习很好的实用代码
android开发相关基础和实用的小知识 android开发相关基础和实用的小知识 android开发相关基础和实用的小知识 android开发相关基础和实用的小知识
android开发中有很多实用的shell命令,可以减少我们在手机端的操作,提高开发效率,我将我在工作中常用的shell命令收集整理封装成脚本,作一个分享.
实用Android开发工具和资源精选 APK权限大全 - Android必懂知识 最无私的Android资料(书籍+代码)分享[总结] Android中文帮助教程(非常合适新手入门) android程序编写及调试新手入门 大家一起学Android(Windows...