短信备份

原创 2015年11月18日 14:40:48
package com.xh.tx.sms;

import java.util.Date;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends Activity {

	private static final String TAG = "MainActivity";
	private final String uri = "content://sms/";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	
		writeSMS();
		
	}

	private void readSMS() {
		ContentResolver resolver = this.getContentResolver(); //获取访问内容提供者的工具类
		String[] projection = new String[]{"_id","address","date","type","body"};
	
		Cursor cursor = resolver.query(Uri.parse(uri), projection, null, null, null);
		
		if(null != cursor && cursor.getCount() > 0)
		{
			while(cursor.moveToNext())
			{
				Integer _id = cursor.getInt(0);
				String address = cursor.getString(1);
				Long date = cursor.getLong(2);
				Integer type = cursor.getInt(3);
				String body = cursor.getString(4);
				
				Log.i(TAG, _id +" " + " address=" +address + " date = " + new Date(date) + " type=" + type + " body =" + body);
			}
			
			cursor.close();
		}
		
	}

	public void writeSMS()
	{
		ContentResolver resolver = this.getContentResolver(); //获取访问内容提供者的工具类
		
		resolver.registerContentObserver(Uri.parse(uri), true, new MyObserver(new Handler())); //内容观察者
		
		ContentValues values = new ContentValues();
		
		//desc 降序排列 limit 用来限制你返回多少条记录
		Cursor cursor = resolver.query(Uri.parse(uri), new String[]{"_id"}, null, null, " _id desc limit 1");
		
		if(null != cursor && cursor.moveToFirst())
		{
			//Log.e(TAG, "-----------------=" + cursor.getInt(0));
			//values.put("RecNo", cursor.getInt(0)+1);
			values.put("address", "95535");
			values.put("date", System.currentTimeMillis());
			values.put("type", "1");
			values.put("body", "你好啊 亲爱的!");
			
			Log.i(TAG, resolver.insert(Uri.parse(uri), values) + " ====");
		}
		
	}
	
	class MyObserver extends ContentObserver
	{

		public MyObserver(Handler handler) {
			super(handler);
			
		}
		
		@Override
		public void onChange(boolean selfChange) {
			super.onChange(selfChange);
	
			ContentResolver resolver = MainActivity.this.getContentResolver(); //获取访问内容提供者的工具类
			String[] projection = new String[]{"_id","address","date","type","body"};
			
			Cursor cursor = resolver.query(Uri.parse("content://sms/outbox"), projection, null, null, null);
			
			if(null != cursor && cursor.getCount() > 0)
			{
				while(cursor.moveToNext())
				{
					Integer _id = cursor.getInt(0);
					String address = cursor.getString(1);
					Long date = cursor.getLong(2);
					Integer type = cursor.getInt(3);
					String body = cursor.getString(4);
					
					Log.i(TAG, _id +" " + " address=" +address + " date = " + new Date(date) + " type=" + type + " body =" + body);
				}
				
				cursor.close();
		}
		}
	}
}




版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

android备份系统的短信

  • 2014-06-23 22:24
  • 636KB
  • 下载

短信备份-加密

SmsUtils public class SmsUtils { public interface BackUpCallBackMsg{ void before(int count); v...

ppc pim程序,可备份短信

  • 2008-11-15 23:06
  • 210KB
  • 下载

短信备份

package com.su.smsbackuprestore.operatesms; import java.io.File; import java.io.FileNotFoundEx...
  • yun90
  • yun90
  • 2012-06-07 10:18
  • 319

安卓 android备份短信

  • 2015-08-19 17:20
  • 1.19MB
  • 下载

android短信备份

  • 2015-07-06 15:25
  • 1.13MB
  • 下载

Android项目:手机安全卫士(14)—— 短信备份

Android项目:手机安全卫士(14)—— 短信备份1 概述哈哈,今天又是全新的一天,最近为工作上的事有点闹心,不过学习的心不变,还是需要坚持不懈的努力。今天的任务是实现短信备份功能,这个比较简单,...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)