android开发之zip文件压缩解压缩

 更新时间:2016年9月20日 20:01  点击:1552
本文章介绍了关于android开发之zip文件压缩解压缩 ,有需要学习android手机开发时文件操作的朋友可以参考一下。
 代码如下 复制代码

//----------------- DirTraversal.java
package com.once;

import java.io.File;
import java.util.ArrayList;
import java.util.LinkedList;
/**
* 文件夹遍历
* @author once
*
*/
public class DirTraversal {

//no recursion
public static LinkedList<File> listLinkedFiles(String strPath) {
LinkedList<File> list = new LinkedList<File>();
File dir = new File(strPath);
File file[] = dir.listFiles();
for (int i = 0; i < file.length; i++) {
if (file[i].isDirectory())
list.add(file[i]);
else
System.out.println(file[i].getAbsolutePath());
}
File tmp;
while (!list.isEmpty()) {
tmp = (File) list.removeFirst();
if (tmp.isDirectory()) {
file = tmp.listFiles();
if (file == null)
continue;
for (int i = 0; i < file.length; i++) {
if (file[i].isDirectory())
list.add(file[i]);
else
System.out.println(file[i].getAbsolutePath());
}
} else {
System.out.println(tmp.getAbsolutePath());
}
}
return list;
}


//recursion
public static ArrayList<File> listFiles(String strPath) {
return refreshFileList(strPath);
}

public static ArrayList<File> refreshFileList(String strPath) {
ArrayList<File> filelist = new ArrayList<File>();
File dir = new File(strPath);
File[] files = dir.listFiles();

if (files == null)
return null;
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
refreshFileList(files[i].getAbsolutePath());
} else {
if(files[i].getName().toLowerCase().endsWith("zip"))
filelist.add(files[i]);
}
}
return filelist;
}
}

//----------------- ZipUtils.java
package com.once;

import java.io.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;

/**
* Java utils 实现的Zip工具
*
* @author once
*/
public class ZipUtils {
private static final int BUFF_SIZE = 1024 * 1024; // 1M Byte

/**
* 批量压缩文件(夹)
*
* @param resFileList 要压缩的文件(夹)列表
* @param zipFile 生成的压缩文件
* @throws IOException 当压缩过程出错时抛出
*/
public static void zipFiles(Collection<File> resFileList, File zipFile) throws IOException {
ZipOutputStream zipout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(
zipFile), BUFF_SIZE));
for (File resFile : resFileList) {
zipFile(resFile, zipout, "");
}
zipout.close();
}

/**
* 批量压缩文件(夹)
*
* @param resFileList 要压缩的文件(夹)列表
* @param zipFile 生成的压缩文件
* @param comment 压缩文件的注释
* @throws IOException 当压缩过程出错时抛出
*/
public static void zipFiles(Collection<File> resFileList, File zipFile, String comment)
throws IOException {
ZipOutputStream zipout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(
zipFile), BUFF_SIZE));
for (File resFile : resFileList) {
zipFile(resFile, zipout, "");
}
zipout.setComment(comment);
zipout.close();
}

/**
* 解压缩一个文件
*
* @param zipFile 压缩文件
* @param folderPath 解压缩的目标目录
* @throws IOException 当解压缩过程出错时抛出
*/
public static void upZipFile(File zipFile, String folderPath) throws ZipException, IOException {
File desDir = new File(folderPath);
if (!desDir.exists()) {
desDir.mkdirs();
}
ZipFile zf = new ZipFile(zipFile);
for (Enumeration<?> entries = zf.entries(); entries.hasMoreElements();) {
ZipEntry entry = ((ZipEntry)entries.nextElement());
InputStream in = zf.getInputStream(entry);
String str = folderPath + File.separator + entry.getName();
str = new String(str.getBytes("8859_1"), "GB2312");
File desFile = new File(str);
if (!desFile.exists()) {
File fileParentDir = desFile.getParentFile();
if (!fileParentDir.exists()) {
fileParentDir.mkdirs();
}
desFile.createNewFile();
}
OutputStream out = new FileOutputStream(desFile);
byte buffer[] = new byte[BUFF_SIZE];
int realLength;
while ((realLength = in.read(buffer)) > 0) {
out.write(buffer, 0, realLength);
}
in.close();
out.close();
}
}

/**
* 解压文件名包含传入文字的文件
*
* @param zipFile 压缩文件
* @param folderPath 目标文件夹
* @param nameContains 传入的文件匹配名
* @throws ZipException 压缩格式有误时抛出
* @throws IOException IO错误时抛出
*/
public static ArrayList<File> upZipSelectedFile(File zipFile, String folderPath,
String nameContains) throws ZipException, IOException {
ArrayList<File> fileList = new ArrayList<File>();

File desDir = new File(folderPath);
if (!desDir.exists()) {
desDir.mkdir();
}

ZipFile zf = new ZipFile(zipFile);
for (Enumeration<?> entries = zf.entries(); entries.hasMoreElements();) {
ZipEntry entry = ((ZipEntry)entries.nextElement());
if (entry.getName().contains(nameContains)) {
InputStream in = zf.getInputStream(entry);
String str = folderPath + File.separator + entry.getName();
str = new String(str.getBytes("8859_1"), "GB2312");
// str.getBytes("GB2312"),"8859_1" 输出
// str.getBytes("8859_1"),"GB2312" 输入
File desFile = new File(str);
if (!desFile.exists()) {
File fileParentDir = desFile.getParentFile();
if (!fileParentDir.exists()) {
fileParentDir.mkdirs();
}
desFile.createNewFile();
}
OutputStream out = new FileOutputStream(desFile);
byte buffer[] = new byte[BUFF_SIZE];
int realLength;
while ((realLength = in.read(buffer)) > 0) {
out.write(buffer, 0, realLength);
}
in.close();
out.close();
fileList.add(desFile);
}
}
return fileList;
}

/**
* 获得压缩文件内文件列表
*
* @param zipFile 压缩文件
* @return 压缩文件内文件名称
* @throws ZipException 压缩文件格式有误时抛出
* @throws IOException 当解压缩过程出错时抛出
*/
public static ArrayList<String> getEntriesNames(File zipFile) throws ZipException, IOException {
ArrayList<String> entryNames = new ArrayList<String>();
Enumeration<?> entries = getEntriesEnumeration(zipFile);
while (entries.hasMoreElements()) {
ZipEntry entry = ((ZipEntry)entries.nextElement());
entryNames.add(new String(getEntryName(entry).getBytes("GB2312"), "8859_1"));
}
return entryNames;
}

/**
* 获得压缩文件内压缩文件对象以取得其属性
*
* @param zipFile 压缩文件
* @return 返回一个压缩文件列表
* @throws ZipException 压缩文件格式有误时抛出
* @throws IOException IO操作有误时抛出
*/
public static Enumeration<?> getEntriesEnumeration(File zipFile) throws ZipException,
IOException {
ZipFile zf = new ZipFile(zipFile);
return zf.entries();

}

/**
* 取得压缩文件对象的注释
*
* @param entry 压缩文件对象
* @return 压缩文件对象的注释
* @throws UnsupportedEncodingException
*/
public static String getEntryComment(ZipEntry entry) throws UnsupportedEncodingException {
return new String(entry.getComment().getBytes("GB2312"), "8859_1");
}

/**
* 取得压缩文件对象的名称
*
* @param entry 压缩文件对象
* @return 压缩文件对象的名称
* @throws UnsupportedEncodingException
*/
public static String getEntryName(ZipEntry entry) throws UnsupportedEncodingException {
return new String(entry.getName().getBytes("GB2312"), "8859_1");
}

/**
* 压缩文件
*
* @param resFile 需要压缩的文件(夹)
* @param zipout 压缩的目的文件
* @param rootpath 压缩的文件路径
* @throws FileNotFoundException 找不到文件时抛出
* @throws IOException 当压缩过程出错时抛出
*/
private static void zipFile(File resFile, ZipOutputStream zipout, String rootpath)
throws FileNotFoundException, IOException {
rootpath = rootpath + (rootpath.trim().length() == 0 ? "" : File.separator)
+ resFile.getName();
rootpath = new String(rootpath.getBytes("8859_1"), "GB2312");
if (resFile.isDirectory()) {
File[] fileList = resFile.listFiles();
for (File file : fileList) {
zipFile(file, zipout, rootpath);
}
} else {
byte buffer[] = new byte[BUFF_SIZE];
BufferedInputStream in = new BufferedInputStream(new FileInputStream(resFile),
BUFF_SIZE);
zipout.putNextEntry(new ZipEntry(rootpath));
int realLength;
while ((realLength = in.read(buffer)) != -1) {
zipout.write(buffer, 0, realLength);
}
in.close();
zipout.flush();
zipout.closeEntry();
}
}
}

文章分享了关于android ksoap2 访问webservice,连续两次调用时,第二次调用异常(转) 应用,有需要的朋友可以参考一一本文章哈。

1.

 代码如下 复制代码
Webservice.GetVcardByUserNo(String userId,String userNo);

这个是封装了的webservice接口。
2.在程序中连续两次调用该接口时,ksoap2在解析第二次调用返回的结果时抛异常。
    异常信息如下:

 代码如下 复制代码
org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null@1:0 in java.io.InputStreamReader@4383bf38)

3.打断点调试时,不会出现该异常。

4.无奈之下使用android 的HttpURLConnection 直接调用webservice接口,直接使用时不会发生以上异常,所以使用ksoap2 访问webservice需要设置什么呢?

5.使用HttpUrlConnection访问webserivice代码如下:

(一)连接webservice

 代码如下 复制代码

String ServerUrl="webservice地址";
 String soapAction="http://www.111cn.net/PhoneClient/GetVcardJson";

 String data="";

String requestData="<?xml version="1.0" encoding="utf-8"?>rn"+
"<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">rn"
  +"<soap:Header>rn"+
    "<AuthHeader xmlns="http://www.111cn.net/PhoneClient/">rn"+
     "<UserId>"+userID+"</UserId>rn"+
    "</AuthHeader>rn"+
  "</soap:Header>rn"+
  "<soap:Body>rn"+
    "<GetVcardJson xmlns="http://www.111cn.net/PhoneClient/">rn"+
      "<vcardUserNo>"+userNo+"</vcardUserNo>rn"+
    "</GetVcardJson>rn"+
  "</soap:Body>rn"+

"</soap:Envelope>";

try{
URL url =new URL(ServerUrl);
HttpURLConnection con=(HttpURLConnection)url.openConnection();
byte[] bytes=requestData.getBytes("utf-8");
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "text/xml;charset=utf-8");
con.setRequestProperty("SOAPAction",soapAction);
con.setRequestProperty("Content-Length",""+bytes.length);
OutputStream outStream=con.getOutputStream();
outStream.write(bytes);
outStream.flush();
outStream.close();
InputStream inStream=con.getInputStream();

data=parser(inStream);

(二)解析返回的数据

 代码如下 复制代码

private static String parser(InputStream in){
XmlPullParser parser=Xml.newPullParser();
String data="";
try{
int flag=0;
parser.setInput(in, "utf-8");
int evenType=parser.getEventType();
while(evenType!=XmlPullParser.END_DOCUMENT){
switch(evenType){
case XmlPullParser.START_DOCUMENT:break;
case XmlPullParser.START_TAG:
break;
case XmlPullParser.TEXT:
data=parser.getText();
break;
case XmlPullParser.END_TAG:break;
}
parser.next();
evenType=parser.getEventType();
}

}catch(XmlPullParserException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
return data;
}

最近查看了一些关于开源Android游戏引擎的资料,觉得AndEngine功能强大,例子丰富,更新较快。由于初学,找资料化不少时间,现在将自己在网上收集的比较实用的资料网址贴在这里,大家一起学习和讨论。


1.AndEngine源码和例子代码地址:

Google Code:http://code.google.com/p/andengine/

AndEngine主页:http://www.andengine.org/

example地址:http://code.google.com/p/andengineexamples/

 

2.代码下载

先安装TortoiseHg,然后在想要存放代码的目录右键-->TortoiseHg-->clone

hg clone https://andengine.googlecode.com/hg/andengine

 

3.lib包下载

andengineexamples->Source->Browse->hg->lib(libs->armeabi)->点击想下载的Filename->View raw file

 

4.入门文章

中文 http://blog.111cn.net/cping1982/archive/2011/03/06/6227775.aspx

英文 http://www.andengine.org/forums/ ... rial-list-t417.html

 

虽然听说AndEngine在某些型号的机型上有不稳定的情况出现,但决定学习这个引擎是因为它内置了BOX2D物理引擎,在手机上测试运行也比较流畅,效果很给力~~~希望大家喜欢

本文章简单的介绍了关于andengine入门教程之学习笔记,有需要学习的同学可以参考一下下哦。

例子中主程序.launcher.ExampleLauncher主要继承自ExpandableListActivity的列表,
这里主要定义了另个枚举public enum ExampleGroup和enum Example ,平时因为像他们这样使用比较少,值得学习。

 代码如下 复制代码

enum Example {

// ===========================================================

// Elements

// ===========================================================

 

ANALOGONSCREENCONTROL(AnalogOnScreenControlExample.class, R.string.example_analogonscreencontrol),

ANALOGONSCREENCONTROLS(AnalogOnScreenControlsExample.class, R.string.example_analogonscreencontrols),

ANIMATEDSPRITES(AnimatedSpritesExample.class, R.string.example_animatedsprites),

AUGMENTEDREALITY(AugmentedRealityExample.class, R.string.example_augmentedreality),

AUGMENTEDREALITYHORIZON(AugmentedRealityHorizonExample.class, R.string.example_augmentedrealityhorizon),

AUTOPARALLAXBACKGROUND(AutoParallaxBackgroundExample.class, R.string.example_autoparallaxbackground),

BOUNDCAMERA(BoundCameraExample.class, R.string.example_boundcamera),

CHANGEABLETEXT(ChangeableTextExample.class, R.string.example_changeabletext),

COLLISIONDETECTION(CollisionDetectionExample.class, R.string.example_collisiondetection),

COLORKEYTEXTURESOURCEDECORATOR(ColorKeyTextureSourceDecoratorExample.class, R.string.example_colorkeytexturesourcedecorator),

COORDINATECONVERSION(CoordinateConversionExample.class, R.string.example_coordinateconversion),

CUSTOMFONT(CustomFontExample.class, R.string.example_customfont),

DIGITALONSCREENCONTROL(DigitalOnScreenControlExample.class, R.string.example_digitalonscreencontrol),

EASEFUNCTION(EaseFunctionExample.class, R.string.example_easefunction),

IMAGEFORMATS(ImageFormatsExample.class, R.string.example_imageformats),

LEVELLOADER(LevelLoaderExample.class, R.string.example_levelloader),

LINE(LineExample.class, R.string.example_line),

LOADTEXTURE(LoadTextureExample.class, R.string.example_loadtexture),

MENU(MenuExample.class, R.string.example_menu),

MODPLAYER(ModPlayerExample.class, R.string.example_modplayer),

MOVINGBALL(MovingBallExample.class, R.string.example_movingball),

MULTIPLAYER(MultiplayerExample.class, R.string.example_multiplayer),

MULTITOUCH(MultiTouchExample.class, R.string.example_multitouch),

MUSIC(MusicExample.class, R.string.example_music),

PAUSE(PauseExample.class, R.string.example_pause),

PATHMODIFIER(PathModifierExample.class, R.string.example_pathmodifier),

PARTICLESYSTEMNEXUS(ParticleSystemNexusExample.class, R.string.example_particlesystemnexus),

PARTICLESYSTEMCOOL(ParticleSystemCoolExample.class, R.string.example_particlesystemcool),

PARTICLESYSTEMSIMPLE(ParticleSystemSimpleExample.class, R.string.example_particlesystemsimple),

PHYSICSCONLLISIONFILTERING(PhysicsCollisionFilteringExample.class, R.string.example_physicscollisionfiltering),

PHYSICS(PhysicsExample.class, R.string.example_physics),

PHYSICSFIXEDSTEP(PhysicsFixedStepExample.class, R.string.example_physicsfixedstep),

PHYSICSJUMP(PhysicsJumpExample.class, R.string.example_physicsjump),

PHYSICSREVOLUTEJOINT(PhysicsRevoluteJointExample.class, R.string.example_physicsrevolutejoint),

PHYSICSREMOVE(PhysicsRemoveExample.class, R.string.example_physicsremove),

PINCHZOOM(PinchZoomExample.class, R.string.example_pinchzoom),

RECTANGLE(RectangleExample.class, R.string.example_rectangle),

REPEATINGSPRITEBACKGROUND(RepeatingSpriteBackgroundExample.class, R.string.example_repeatingspritebackground),

ROTATION3D(Rotation3DExample.class, R.string.example_rotation3d),

SHAPEMODIFIER(ShapeModifierExample.class, R.string.example_shapemodifier),

SHAPEMODIFIERIRREGULAR(ShapeModifierIrregularExample.class, R.string.example_shapemodifierirregular),

SOUND(SoundExample.class, R.string.example_sound),

SPLITSCREEN(SplitScreenExample.class, R.string.example_splitscreen),

SPRITE(SpriteExample.class, R.string.example_sprite),

SPRITEREMOVE(SpriteRemoveExample.class, R.string.example_spriteremove),

STROKEFONT(StrokeFontExample.class, R.string.example_strokefont),

SUBMENU(SubMenuExample.class, R.string.example_submenu),

TEXT(TextExample.class, R.string.example_text),

TEXTMENU(TextMenuExample.class, R.string.example_textmenu),

TEXTUREOPTIONS(TextureOptionsExample.class, R.string.example_textureoptions),

TMXTILEDMAP(TMXTiledMapExample.class, R.string.example_tmxtiledmap),

TICKERTEXT(TickerTextExample.class, R.string.example_tickertext),

TOUCHDRAG(TouchDragExample.class, R.string.example_touchdrag),

UNLOADRESOURCES(UnloadResourcesExample.class, R.string.example_unloadresources),

UPDATETEXTURE(UpdateTextureExample.class, R.string.example_updatetexture),

XMLLAYOUT(XMLLayoutExample.class, R.string.example_xmllayout),

ZOOM(ZoomExample.class, R.string.example_zoom),

 

BENCHMARK_ANIMATION(AnimationBenchmark.class, R.string.example_benchmark_animation),

BENCHMARK_PARTICLESYSTEM(ParticleSystemBenchmark.class, R.string.example_benchmark_particlesystem),

BENCHMARK_PHYSICS(PhysicsBenchmark.class, R.string.example_benchmark_physics),

BENCHMARK_SHAPEMODIFIER(ShapeModifierBenchmark.class, R.string.example_benchmark_shapemodifier),

BENCHMARK_SPRITE(SpriteBenchmark.class, R.string.example_benchmark_sprite),

BENCHMARK_TICKERTEXT(TickerTextBenchmark.class, R.string.example_benchmark_tickertext),

 

APP_CITYRADAR(CityRadarActivity.class, R.string.example_app_cityradar),

 

GAME_SNAKE(SnakeGameActivity.class, R.string.example_game_snake),

GAME_RACER(RacerGameActivity.class, R.string.example_game_racer);

 

// ===========================================================

// Constants

// ===========================================================

 

// ===========================================================

// Fields

// ===========================================================

 

public final Class<? extends BaseGameActivity> CLASS;

public final int NAMERESID;

 

// ===========================================================

// Constructors

// ===========================================================

 

private Example(final Class<? extends BaseGameActivity> pExampleClass, final int pNameResID) {

this.CLASS = pExampleClass;

this.NAMERESID = pNameResID;

}

 

// ===========================================================

// Getter & Setter

// ===========================================================

 

// ===========================================================

// Methods for/from SuperClass/Interfaces

// ===========================================================

 

// ===========================================================

// Methods

// ===========================================================

 

// ===========================================================

// Inner and Anonymous Classes

// ===========================================================

}

上面的public final Class<? extends BaseGameActivity> CLASS;表示任何继承自BaseGameActivity的类型,属于泛型,
因为andengine的例子程序都是继承自BaseGameActivity。

 代码如下 复制代码

public enum ExampleGroup {

// ===========================================================

// Elements

// ===========================================================

 

SIMPLE(R.string.examplegroup_simple,

Example.LINE, Example.RECTANGLE, Example.SPRITE, Example.SPRITEREMOVE),

MODIFIER_AND_ANIMATION(R.string.examplegroup_modifier_and_animation,

Example.MOVINGBALL, Example.SHAPEMODIFIER, Example.SHAPEMODIFIERIRREGULAR, Example.PATHMODIFIER, Example.ANIMATEDSPRITES, Example.EASEFUNCTION, Example.ROTATION3D ),

TOUCH(R.string.examplegroup_touch,

Example.TOUCHDRAG, Example.MULTITOUCH, Example.ANALOGONSCREENCONTROL, Example.DIGITALONSCREENCONTROL, Example.ANALOGONSCREENCONTROLS, Example.COORDINATECONVERSION, Example.PINCHZOOM),

PARTICLESYSTEM(R.string.examplegroup_particlesystems,

Example.PARTICLESYSTEMSIMPLE, Example.PARTICLESYSTEMCOOL, Example.PARTICLESYSTEMNEXUS),

MULTIPLAYER(R.string.examplegroup_multiplayer,

Example.MULTIPLAYER),

PHYSICS(R.string.examplegroup_physics,

Example.COLLISIONDETECTION, Example.PHYSICS, Example.PHYSICSFIXEDSTEP, Example.PHYSICSCONLLISIONFILTERING, Example.PHYSICSJUMP, Example.PHYSICSREVOLUTEJOINT, Example.PHYSICSREMOVE ),

TEXT(R.string.examplegroup_text,

Example.TEXT, Example.TICKERTEXT, Example.CHANGEABLETEXT, Example.CUSTOMFONT, Example.STROKEFONT),

AUDIO(R.string.examplegroup_audio,

Example.SOUND, Example.MUSIC, Example.MODPLAYER),

ADVANCED(R.string.examplegroup_advanced,

Example.SPLITSCREEN, Example.BOUNDCAMERA ), // Example.AUGMENTEDREALITY, Example.AUGMENTEDREALITYHORIZON),

BACKGROUND(R.string.examplegroup_background,

Example.REPEATINGSPRITEBACKGROUND, Example.AUTOPARALLAXBACKGROUND, Example.TMXTILEDMAP),

OTHER(R.string.examplegroup_other,

Example.PAUSE, Example.MENU, Example.SUBMENU, Example.TEXTMENU, Example.ZOOM , Example.IMAGEFORMATS, Example.TEXTUREOPTIONS, Example.COLORKEYTEXTURESOURCEDECORATOR, Example.LOADTEXTURE, Example.UPDATETEXTURE, Example.XMLLAYOUT, Example.LEVELLOADER),

APP(R.string.examplegroup_app,

Example.APP_CITYRADAR),

GAME(R.string.examplegroup_game,

Example.GAME_SNAKE, Example.GAME_RACER),

BENCHMARK(R.string.examplegroup_benchmark,

Example.BENCHMARK_SPRITE, Example.BENCHMARK_SHAPEMODIFIER, Example.BENCHMARK_ANIMATION, Example.BENCHMARK_TICKERTEXT, Example.BENCHMARK_PARTICLESYSTEM, Example.BENCHMARK_PHYSICS);

 

// ===========================================================

// Constants

// ===========================================================

 

// ===========================================================

// Fields

// ===========================================================

public final Example[] EXAMPLES;

public final int NAMERESID;

 

// ===========================================================

// Constructors

// ===========================================================

 

private ExampleGroup(final int pNameResID, final Example ... pExamples) {

this.NAMERESID = pNameResID;

this.EXAMPLES = pExamples;

}

 

// ===========================================================

// Getter & Setter

// ===========================================================

 

// ===========================================================

// Methods for/from SuperClass/Interfaces

// ===========================================================

 

// ===========================================================

// Methods

// ===========================================================

 

// ===========================================================

// Inner and Anonymous Classes

// ===========================================================

}

主程序就比较简单,不再介绍了。

本文章分享一篇关于手机开的中的AndroidPN环境建立图文教程,有需要开发android各种应用的朋友可以参考一下本文章哦。
AndroidPN实现了从服务器到android移动平台的文本消息推送。这里先简单说一下androidPN的安装过程。
下载androidpn-client-0.5.0.zip和androidpn-server-0.5.0-bin.zip
网址:http://sourceforge.net/projects/androidpn/ 
解压两个包,Eclipse导入client,配置好目标平台,打开raw/androidpn.properties文件,
 代码如下 复制代码
apiKey=1234567890
xmppHost=10.0.2.2
xmppPort=5222
如果是模拟器来运行客户端程序,把xmppHost配置成10.0.2.2 (模拟器把10.0.2.2认为是所在主机的地址,127.0.0.1是模拟器本身的回环地址).
 代码如下 复制代码
xmppPort=5222 是服务器的xmpp服务监听端口
运行
 代码如下 复制代码
androidpn-server-0.5.0binrun.bat
启动服务器,从浏览器访问
 代码如下 复制代码
http://127.0.0.1:7070/index.do (androidPN Server
有个轻量级的web服务器,在7070端口监听请求,接受用户输入的文本消息)
运行客户端,客户端会向服务器发起连接请求,注册成功后,服务器能识别客户端,并维护和客户端的IP长连接
 进入Notifications界面,输入消息发送
模拟器客户端接受到server推送的消息
这样AndroidPN的环境就搭好了,下一步我将深入研究研究实行以及XMPP协议。
[!--infotagslink--]

相关文章

  • php读取zip文件(删除文件,提取文件,增加文件)实例

    下面小编来给大家演示几个php操作zip文件的实例,我们可以读取zip包中指定文件与删除zip包中指定文件,下面来给大这介绍一下。 从zip压缩文件中提取文件 代...2016-11-25
  • C#自定义字符串压缩和解压缩的方法

    这篇文章主要介绍了C#自定义字符串压缩和解压缩的方法,通过自定义C#字符串操作类实现对字符串的压缩与解压的功能,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
  • C# 利用ICSharpCode.SharpZipLib实现在线压缩和解压缩

    本文主要主要介绍了利用ICSharpCode.SharpZipLib第三方的DLL库实现在线压缩和解压缩的功能,并做了相关的代码演示。...2020-06-25
  • php使用ZipArchive函数实现文件的压缩与解压缩

    PHP ZipArchive 是PHP自带的扩展类,可以轻松实现ZIP文件的压缩和解压,使用前首先要确保PHP ZIP 扩展已经开启,具体开启方法这里就不说了,不同的平台开启PHP扩增的方法网上都有,如有疑问欢迎交流。这里整理一下利用php zipA...2015-10-30
  • PHP执行Linux命令实现文件压缩

    在php中可以直接调用linux中的文件压缩命令来实现文件快速压缩与解压缩,有需要的朋友可参考参考。 用PHP调用Linux的命令行 ,执行压缩命令,OK,马上行动! /*拆分成3个...2016-11-25
  • apache环境下载apk文件变成zip文件的方法解决方法

    今天自己的一个安卓站下载.apk文件时变成了zip可能一直是这样,只是我没发现了,后面网上找一些方法 在Apache安装目录下的conf/mime.types文件的对应位置,加上以下一...2016-09-20
  • c#调用winrar解压缩文件代码分享

    这篇文章主要介绍了c#调用winrar解压缩文件的方法,大家参考使用吧...2020-06-25
  • php实现文件压缩

    <?php /* -------------------------- Copyright by T.muqiao(39号天堂桥) 本程序仅供学习讨论使用,在未通知作者作为任何商业用途 视为中华人民共和国不道德公民 联系方式:442536...2016-11-25
  • php实现zip文件解压操作

    PHP解压zip文件函数,源码简短,需要使用 ZZIPlib library 扩展,使用前请确认该扩展已经开启。 <&#63; /***********************@file - path to zip file 需要解压的文件的路径*@destination - destination directory f...2015-11-08
  • asp.net C#实现解压缩文件的方法

    这篇文章主要介绍了asp.net C#实现解压缩文件的方法,分别讲述了三种不同的实现方法,是非常实用的技巧,需要的朋友可以参考下...2021-09-22
  • c#使用DotNetZip封装类操作zip文件(创建/读取/更新)实例

    DotnetZip是一个开源类库,支持.NET的任何语言,可很方便的创建,读取,和更新zip文件。而且还可以使用在.NETCompact Framework中。...2020-06-25
  • C#实现GZip压缩和解压缩入门实例

    C#中用GZip对数据压缩和解压缩非常方便,但是当我第一次拿到这个类的时候却感觉很迷茫,无从下手...2020-06-25
  • C++Zip压缩解压缩示例(支持递归压缩)

    C++Zip压缩解压缩示例,用第三方函数封装而成,支持 UNCODE, ANSCII、支持压缩文件夹、支持递归压缩...2020-04-25
  • 使用php的zlib压缩和解压缩swf文件

    我在以前写过怎么使用c#来压缩和解压缩swf文件,解压缩,压缩和读取flash头文件信息需要使用一个开源的链接库,而且使用起来也不是很方便,但是使用php就不一样了,php包含...2016-11-25
  • C#使用GZipStream实现文件的压缩与解压

    这篇文章主要为大家详细介绍了C#使用GZipStream实现文件的压缩与解压,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-06-25
  • php ZipArchive打包压缩zip文件实例

    ZipArchive类是一个文件压缩解压类是一个php自来的zip类,我们可以直接简单创建一个类然后就能实现打包了,下面一聚教程小编给各位介绍一下吧,有需要了解的朋友可进入参考...2016-11-25
  • c#打包文件解压缩的实例

    下面小编就为大家分享一篇c#打包文件解压缩的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-06-25
  • C++获取zip文件列表方法

    本文将介绍获取zip文件列表的方法,有些新手的朋友可以参考下...2020-04-25
  • php ZipArchive类创建和解压zip文件实例

    如果你使用的是php5.2以下的php版本是无法使用ZipArchive类的,只要php5.2及以上版本才可以方便的使用ZipArchive类来解压与压缩zip文件了,下面小编来给各位同学介绍一下...2016-11-25
  • php使用pclzip类实现文件压缩的方法(附pclzip类下载地址)

    这篇文章主要介绍了php使用pclzip类实现文件压缩的方法,分析了使用pclzip类的具体步骤与实现文件压缩的相关技巧,并附带pclzip类文件的下载地址,需要的朋友可以参考下...2016-05-04