android开发:使用HttpURLConnection读取验证码,并且发送请求进行验证的方法

imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new Thread(new Runnable() {
@Override
public void run() {
try {
URL url = new URL(“http://192.168.1.205/verify.php?rand=29569″);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();//建立链接

InputStream in = conn.getInputStream();//读取图片先

bitmap = BitmapFactory.decodeStream(in);//解码图片
handler.sendEmptyMessage(1);//发送消息,把图片显示出去

android开发:传感器操作的实例

text1 = (TextView)findViewById(R.id.text1);//方向传感器
text2 = (TextView)findViewById(R.id.text2);//磁场传感器
text3 = (TextView)findViewById(R.id.text3);//温度传感器
text4 = (TextView)findViewById(R.id.text4);//光感传感器
text5 = (TextView)findViewById(R.id.text5);//压力传感器

mSensor = (SensorManager) getSystemService(SENSOR_SERVICE); //获取Sensor的服务对象

然后在onResume中注册需要开发的传感器监听,代码:
@Override

android开发:为桌面创建一个快捷方式的代码

直接上代码:

Parcelable icon = Intent.ShortcutIconResource.fromContext(mContext,R.mipmap.ic_launcher);//桌面的图标
String appname = getString(R.string.app_name);//快捷方式的名称
Intent intent;

//添加
intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,appname);//名称
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,icon);   //桌面图标
intent.putExtra("duplicate",false);//不允许创建多个快捷方式

intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,new Intent(MainActivity.this,MainActivity.class));//设置要启动的class
sendBroadcast(intent);//发送广播

android开发:xml解析读取的方法XmlResourceParser、XmlPullParser

public Object parserXml(XmlResourceParser xml){

ArrayList
_list = new ArrayList<>();//三维数组对象
ArrayList
_city = new ArrayList<>(); //城市二维数组对象

areaInfo province = new areaInfo(); //省份对象
areaInfo city = new areaInfo(); //城市对象

try {

while (xml.getEventType() != XmlResourceParser.END_DOCUMENT){ //XML开始解析

String name = null;

android开发:网络应用URL、URLConnection、PrintWriter、WebView、addJavascriptInterface

开发网络应用:URL、URLConnection、WebView详细使用方法;

URL:
首先new一个URL(url)对象,需要传入一个网址
然后使用openStream打开输入流
然后就可以读取数据了。
URLConnection 一般用于POST
首先创建一个URL对象
然后使用URL对象的openConnection方法返回一个URLConnection对象。
接着就可以设置一些文件头、参数了。conn.setConnectTimeout(5000);//设置链接超时为5秒 conn.addRequestProperty(“Accept”,”*/*”);//添加请求参数conn.addRequestProperty(“Connection”,”keep-alive”);
conn.addRequestProperty(“User-Agent”,”android os 0.002 “+ getPackageName());//可以改变请求头,下面会展示全部代码。
WebView 这个主要是先演示一下 JS代码操作java对象类
主要的方法是web.addJavascriptInterface(new test(this),”mytest”);第一个参数是java对象,第二个参数是js调用的对象;js的代码如下:
mytest.showTip($(“#text”).val());
mytest.showTip2();

15960616263118
 
Copyright © 2008-2021 lanxinbase.com Rights Reserved. | 粤ICP备14086738号-3 |