1.服务器端有一个Login.aspx,例如,用Login.aspx?imei=XXXX登陆之后,服务器端另一个session.aspx中就会显示为mobile.而如果不登陆直接访问session.aspx的话就是none.
我在Android客户端做了一个WebView,用Login.aspx?imei=XXXX访问网页.然后获取session.aspx的内容来做身份判定.例如,if(TextUtils.equals(sbstr, "mobile")){do A}else{do B}但是结果却是do B.用WebView登陆之后获得的session.aspx的内容不应该是mobile然后do A的么?我用PC浏览器试过.是mobile的..
2.定时查询服务器内容并判定是否已存在..服务器端有一个popup.aspx..打开后是一个数字N.然后我需要隔一段时间获取一次popup.aspx的内容.然后查询本地txt文件.如果N在txt中已存在..则不处理..如果N在txt中不存在则提醒并将N添加到txt中..请问这个应该是什么思路..我之前试过用Thread.sleep();然后执行一个get动作..但是这个往onCreate中放就会直接not responding.放在菜单项的话则是一点击就not responding..
= =以前没接触过Android编程..毕业设计要做这个..头疼死了..麻烦诸位..谢谢..
我在Android客户端做了一个WebView,用Login.aspx?imei=XXXX访问网页.然后获取session.aspx的内容来做身份判定.例如,if(TextUtils.equals(sbstr, "mobile")){do A}else{do B}但是结果却是do B.用WebView登陆之后获得的session.aspx的内容不应该是mobile然后do A的么?我用PC浏览器试过.是mobile的..
2.定时查询服务器内容并判定是否已存在..服务器端有一个popup.aspx..打开后是一个数字N.然后我需要隔一段时间获取一次popup.aspx的内容.然后查询本地txt文件.如果N在txt中已存在..则不处理..如果N在txt中不存在则提醒并将N添加到txt中..请问这个应该是什么思路..我之前试过用Thread.sleep();然后执行一个get动作..但是这个往onCreate中放就会直接not responding.放在菜单项的话则是一点击就not responding..
= =以前没接触过Android编程..毕业设计要做这个..头疼死了..麻烦诸位..谢谢..
解决方案 »
- 关于Android res文件夹下的drawable-hdpi,ldpi和mdpi
- 编写一个简易的图片浏览器
- android 地图加载overlay,为什么不能一个个显示
- 哪位兄台可以帮帮忙啊,做个拍照调图片库上传程序,小弟已经想了三天多了
- 关于Android里面调用native code(c++,c)有哪几种方法?
- 联系人中文排序问题
- 散分求教:不用再xml中定义,直接在代码中用方法来设置WebView组件的大小和所处的位置
- 为什么listview能显示,但是加上onIntemlistener却没反映?
- 问调试程序的数据目录?
- android,view的重绘
- java如何读取Dataset数据
- 关于Android上Home键与Return键功能
2 把UI线程和网络线程分开,用ipc去通讯
public class SIMActivity extends Activity {
/** Called when the activity is first created. */
String path;
String sbstr = null;
String popup = null;
String popup1 = null;
String popup2 = null;
int idxof = 0; private Context mContext;
private Notification mNotification;
private NotificationManager mNotificationManager;
private final static int NOTIFICATION_ID = 0x0001; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webView = new WebView(this);
setupViews();
//此处省略无问题代码
...
if(idxof != -1){
handler.removeCallbacks(update);
}else{handler.post(update);}
}
public Handler handler = new Handler();
public Runnable update = new Runnable(){
public void run(){
//地址只是示例
String httpUrl = "http://192.168.1.1/news/popup.aspx";
StringBuffer sb = new StringBuffer();
URL urlx = null;
try{
urlx = new URL(httpUrl);
}catch(MalformedURLException e){
e.printStackTrace();
}
if (urlx != null){
try{
HttpURLConnection urlConn =
(HttpURLConnection) urlx.openConnection();
urlConn.connect();
InputStream input = urlConn.getInputStream();
InputStreamReader inputReader = new InputStreamReader(input);
BufferedReader reader = new BufferedReader(inputReader);
String inputLine = null;
while((inputLine = reader.readLine()) != null){
sb.append(inputLine).append("\n");
}
reader.close();
inputReader.close();
input.close();
urlConn.disconnect();
}catch(IOException e){
e.printStackTrace();
}
}else{
Log.i("TAG","url is null");
} if (sb != null){
String sbtr = sb.toString();
int index = sbtr.indexOf("|");
int len = sbtr.length();
popup = sbtr.substring(0,index);
popup1 = sbtr.substring(index+1,len);
System.out.println("popup="+popup);
Log.i("TAG",sbstr);
}else{
Log.i("TAG","null");
}
popup2 = ","+popup+",";
File sdDir = Environment.getExternalStorageDirectory();
path = sdDir.getAbsolutePath();
File file1 = new File(path,"/history.txt");
if(!file1.exists()){
InputStream inputStream = getResources().openRawResource(R.raw.history);
if (popup2 != null){
try{
byte[] reader = popup2.getBytes();
while(inputStream.read(reader) != -1){
}
writefile(reader,path+"/history.txt");
}catch(IOException e){
}finally{
try{inputStream.close();
}catch(IOException e){
e.printStackTrace();
}
}
}else{
Log.i("TAG","null");
}
compare(path);
}else{
compare(path);
if(idxof != -1){
System.out.println("already got");
}else{
try{RandomAccessFile raf=new RandomAccessFile(path,"rw");
raf.seek(raf.length());
raf.write(popup2.getBytes());
}catch(IOException e){
e.printStackTrace();
}
Intent mIntent = new Intent(mContext,SIMActivity.class);
mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent mContentIntent =PendingIntent.getActivity(mContext,0, mIntent, 0);
mNotification.setLatestEventInfo(mContext, "通知", "有新的通知", mContentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mNotification);
}
}
handler.postDelayed(update, 10*1000);
}
};
public void writefile(byte[] str,String path){
FileOutputStream out;
try{
File file = new File(path);
file.createNewFile();
out = new FileOutputStream(file);
out.write(str);
out.close();
}catch(IOException e){
}
}
private void compare(String path){
File file = new File(path,"/history.txt");
InputStream is = null;
try{
is = new FileInputStream(file);
}catch(FileNotFoundException e1){
e1.printStackTrace();
}
byte[] buffer = new byte[1024];
int rd = 0;
ByteArrayOutputStream baops = new ByteArrayOutputStream();
try{
while((rd = is.read(buffer)) != -1){
baops.write(buffer,0,rd);
}
String temp = new String(baops.toByteArray(),"GB2312");
baops.close();
idxof = temp.indexOf(popup2);
}catch(IOException e){
e.printStackTrace();
}
}目的是想隔一段时间获取一次目标页面上的信息并与本地txt内容进行比较..请问是哪里出了问题呢..感觉什么都没有输出..String也没有得到正确的赋值..