【网学网提醒】:网学会员编辑为广大网友搜集整理了:Android技术点点绩等信息,祝愿广大网友取得需要的信息,参考学习。
softwarepassion/android-series-get-post-and-multipart-post-requests/
发送Get请求
try{
HttpClientclient=newDefaultHttpClient();
StringgetURL="google";
HttpGetget=newHttpGet(getURL);
HttpResponseresponseGet=client.execute(get);
HttpEntityresEntityGet=responseGet.getEntity();
if(resEntityGet!=null){
//dosomethingwiththeresponse
Log.i("GETRESPONSE",EntityUtils.toString(resEntityGet));
}
}catch(Exceptione){
e.printStackTrace();
}
发送post请求
try{
HttpClientclient=newDefaultHttpClient();
StringpostURL="somepostaddress";
HttpPostpost=newHttpPost(postURL);
List
params=newArrayList();
params.add(newBasicNameValuePair("user","kris"));
params.add(newBasicNameValuePair("pass","xyz"));
UrlEncodedFormEntityent=newUrlEncodedFormEntity(params,HTTP.UTF_8);
post.setEntity(ent);
HttpResponseresponsePOST=client.execute(post);
HttpEntityresEntity=responsePOST.getEntity();
if(resEntity!=null){
Log.i("RESPONSE",EntityUtils.toString(resEntity));
}
}catch(Exceptione){
e.printStackTrace();
}
发送postfile
Filefile=newFile("path/to/your/file.txt");
try{
HttpClientclient=newDefaultHttpClient();
StringpostURL="someposturl";
HttpPostpost=newHttpPost(postURL);
FileBodybin=newFileBody(file);
MultipartEntityreqEntity=newMultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("myFile",bin);
post.setEntity(reqEntity);
HttpResponseresponse=client.execute(post);
HttpEntityresEntity=response.getEntity();
if(resEntity!=null){
Log.i("RESPONSE",EntityUtils.toString(resEntity));
}
}catch(Exceptione){
e.printStackTrace();
}
//andorid邮箱验证
Patternpattern=Patternpile(".+@.+\\.[a-z]+");
Stringemail="xyz@xyzdomain";
Matchermatcher=pattern.matcher(email);
booleanmatchFound=matcher.matches();
========================================================================
//程序设置系统桌面壁纸
1.给程序添加设置壁纸权限
2.在程序里添加设置壁纸代码
getApplicationContext().setWallpaper(bitmap)
//加载一个布局toView
LayoutInflaterinflater=Context.LayoutInflater.from(mContext);
convertView=inflater.inflate(R.layout.searchlistlayout,null);
好例子
oschina.net/code/list_releted_codes?id=954&;p=1
//=======================读取项目Assets目录下文件
private
BitmapgetImageFromAssetFile(StringfileName){
Bitmapimage=null;
try{
AssetManageram=context.getAssets();
InputStreamis=am.open(fileName);
image=BitmapFactory.decodeStream(is);
is.close();
}catch(Exceptione){
}
returnimage;
}
InputStreamin=getResources().getAssets().open(fileName);
Android的TextView的组件可以使用多种网页标签,如下标签Android都支持:
//连接
//呈现出题文本效果,但对中文无效果
//呈现大号字体效果
定义块引用标签之间的文本会从常规文本中分离出来
//回车换行
//定义引用
//定义一个定义项目
//定义文档中的分区或节
//把文本定义为强调的内容,但对中文无效果
//文本的字体、字体尺寸、字体颜色
//可定义标题
//斜体效果
//展示图片
//定义段落
//呈现小号字体效果
//定义加删除线文本,但不知为什么效果无法展示
给文本定义为语气更强的强调的内容
//定义下标文本
//定义上标文本
//呈现类似打字机或等宽的文本效果
//为文本添加下划线
//设置PreferenceActivity样式
@android:color/black
@color/window_bg
@null
42.0dip
@style/CustomWindowTitleText
@style/CustomWindowTitleBackground
@style/customCheckBox
@style/customListView