1、内容提供者是让当前的app的数据可以让其他应用访问,其他应该可以通过内容提供者访问当前app的数据库

contentProvider的主要目的是提供一个开发的接口,让其他的应该能够访问当前应用的数据

2、建立的操作类必须继承自定义的内容提供者必须继承ContentProvider

3、创建的创建的PersonProvider必须在应用的主包名和主包名的子目录下,现在应用的主包名是 package="test.weiyuan.sqllite1"

4、内容提供者编写好之后需要在清单文件中进行注册,Android的四大组件都需要在清单文件中进行注册,因为provide是让外部的应用通过provide能够访问当前应用的数据,所以需要指明provide的访问路径   android:authorities,一般采用包名+provider的名字的形式

我们看下清单配置文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test.weiyuan.sqllite1" > <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
//对内容提供者进行注册
<provider
android:authorities="test.weiyuan.sqllite1.PersonProvider"
android:name=".PersonProvider"
android:exported="true"> </provider>
<activity
android:name=".MyActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application> </manifest>

上面的三个属性必须必须填写,其中Android:exported为true表示该数据允许外面的程序访问,不要忘记填写

整个程序的代码框架也是采用mvc的架构

我们来一一分析

DbOpenHelper 类:
package dB;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast; public class DbOpenHelper extends SQLiteOpenHelper
{ public DbOpenHelper(Context context) { super(context, "wy.db", null, 2);
} @Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL("CREATE TABLE person(personid integer primary key autoincrement, name varchar(20), phone VARCHAR(12) NULL)"); } @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { }
}

业务库操作接口类:

可以有下面的两种方式操作数据库:

/**
* 文件名:PersonService.java
* 版权:版权所有 (C) 中国电科30所三部
* 描述:
* 修改人: wei.yuan
* 修改时间:2015/1/9
* 修改内容:新增
*/
package service; import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log; import java.util.ArrayList;
import java.util.List; import dB.DbOpenHelper;
import domain.Person; /**
* 项目名称:SQLLite1
* 类描述:
* 创建人:wei.yuan
* 创建时间:2015/1/9 11:08
* 修改人:wei.yuan
* 修改时间:2015/1/9 11:08
* 修改备注:
* 版权:版权所有 (C) 中国电科30所三部
*/
public class PersonService {
private DbOpenHelper dbOpenHelper; public PersonService(Context context) {
this.dbOpenHelper = new DbOpenHelper(context);
}
public void save(Person person){
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
db.execSQL("insert into person(name, phone) values(?,?)",
new Object[]{person.getName(), person.getPhone()});
}
/**
* 删除记录
* @param name 记录ID
*/
public void delete(String name,String phone){
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
db.execSQL("delete from person where name=? and phone=?", new Object[]{name,phone});
}
/**
* 更新记录
* @param person
*/
public void update(Person person,String name,String phone){
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
db.execSQL("update person set name=?,phone=? where name=? and phone=?",
new Object[]{person.getName(), person.getPhone(),name,phone});
}
/**
* 查询记录
* @param name 记录ID
* @return
*/
public Person find(String name,String phone){
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("select * from person where name=? and phone = ?", new String[]{name,phone});
if(cursor.moveToNext()){
int personid = cursor.getInt(cursor.getColumnIndex("personid"));
String name1 = cursor.getString(cursor.getColumnIndex("name"));
String phone1 = cursor.getString(cursor.getColumnIndex("phone"));
return new Person( name1, phone1);
}
cursor.close();
return null;
}
/**
* 分页获取记录
* @param offset 跳过前面多少条记录
* @param maxResult 每页获取多少条记录
* @return
*/
public List<Person> getScrollData(int offset, int maxResult){
List<Person> persons = new ArrayList<Person>();
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("select * from person order by personid asc limit ?,?",
new String[]{String.valueOf(offset), String.valueOf(maxResult)});
while(cursor.moveToNext()){
int personid = cursor.getInt(cursor.getColumnIndex("personid")); /*这里也可以写成
* String name = cursor.getString(1);
String phone = cursor.getString(2);
默认的表自带的id字段为0 ,name为第一个字段所有为1 ,phone为第二个字段为2*/
String name = cursor.getString(cursor.getColumnIndex("name"));
String phone = cursor.getString(cursor.getColumnIndex("phone"));
persons.add(new Person( name, phone));
}
cursor.close();
return persons;
} /**
* 获取记录总数
* @return
*/
public long getCount(){
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("select count(*) from person", null);
cursor.moveToFirst();
long result = cursor.getLong(0);//统计之后只有一个默认的字段,所以为0
cursor.close();
return result;
} /*使用 SimpleCursorAdapter加装数据的时候,创建的数据库表的主键必须是_id,
* 这里我们使用personid as _id,将创建表的主键personid变成_id
* 返回cursor对象的时候,千万不能关闭cursor对象:cursor.close();*/
public Cursor getScrollCursorData(int offset, int maxResult){
List<Person> persons = new ArrayList<Person>();
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("select personid as _id,name,phone from person order by personid asc limit ?,?",
new String[]{String.valueOf(offset), String.valueOf(maxResult)}); return cursor;//返回cursor对象之前,千万不能关闭cursor对象cursor.close();
} }

方式二:

package service;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import java.util.ArrayList;
import java.util.List; import dB.DbOpenHelper;
import domain.Person; public class OtherPersonService {
private DbOpenHelper dbOpenHelper; public OtherPersonService(Context context) {
this.dbOpenHelper = new DbOpenHelper(context);
}
public void save(Person person){
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("name",person.getName());
values.put("phone",person.getPhone());
db.insert("person",null,values);
}
/**
* 删除记录
* @param name 记录ID
*/
public void delete(String name,String phone){
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
/* db.execSQL("delete from person where name=? and phone=?", new Object[]{name,phone});*/
db.delete("person", "name=? and phone= ?", new String[]{name ,phone});
}
/**
* 更新记录
* @param person
*/
public void update(Person person,String name,String phone){
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
/* db.execSQL("update person set name=?,phone=? where name=? and phone=?",
new Object[]{person.getName(), person.getPhone(),name,phone});*/
ContentValues values = new ContentValues();
values.put("name",person.getName());
values.put("phone",person.getPhone());
db.update("person",values,"name=? and phone=?",new String[]{name ,phone});
}
/**
* 查询记录
* @param name 记录ID
* @return
*/
public Person find(String name,String phone){
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
/* Cursor cursor = db.rawQuery("select * from person where name=? and phone = ?", new String[]{name, phone});*/
Cursor cursor = db.query("person",null,"name=? and phone=?",new String[]{name,phone},null,null,null);
if(cursor.moveToNext()){
int personid = cursor.getInt(cursor.getColumnIndex("personid"));
String name1 = cursor.getString(cursor.getColumnIndex("name"));
String phone1 = cursor.getString(cursor.getColumnIndex("phone"));
return new Person( name1, phone1);
}
cursor.close();
return null;
}
/**
* 分页获取记录
* @param offset 跳过前面多少条记录
* @param maxResult 每页获取多少条记录
* @return
*/
public List<Person> getScrollData(int offset, int maxResult){
List<Person> persons = new ArrayList<Person>();
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
/* Cursor cursor = db.rawQuery("select * from person order by personid asc limit ?,?",*/
Cursor cursor = db.query("person",null,null,null,null,null,"personid asc",offset+ ","+ maxResult);
while(cursor.moveToNext()){
int personid = cursor.getInt(cursor.getColumnIndex("personid")); /*这里也可以写成
* String name = cursor.getString(1);
String phone = cursor.getString(2);
默认的表自带的id字段为0 ,name为第一个字段所有为1 ,phone为第二个字段为2*/
String name = cursor.getString(cursor.getColumnIndex("name"));
String phone = cursor.getString(cursor.getColumnIndex("phone"));
persons.add(new Person( name, phone));
}
cursor.close();
return persons;
} /**
* 获取记录总数
* @return
*/
public long getCount(){
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
/*Cursor cursor = db.rawQuery("select count(*) from person", null);*/
Cursor cursor = db.query("person", new String[]{"count(*)"}, null, null, null, null, null);
cursor.moveToFirst();
long result = cursor.getLong(0);//统计之后只有一个默认的字段,所以为0
cursor.close();
return result;
} /*使用 SimpleCursorAdapter加装数据的时候,创建的数据库表的主键必须是_id,
* 这里我们使用personid as _id,将创建表的主键personid变成_id
* 返回cursor对象的时候,千万不能关闭cursor对象:cursor.close();*/
public Cursor getScrollCursorData(int offset, int maxResult){
List<Person> persons = new ArrayList<Person>();
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("select personid as _id,name,phone from person order by personid asc limit ?,?",
new String[]{String.valueOf(offset), String.valueOf(maxResult)}); return cursor;//返回cursor对象之前,千万不能关闭cursor对象cursor.close();
}
}

javaBenn对象:

package domain;

public class Person
{ private String name;
private String phone; @Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
", phone='" + phone + '\'' +
'}';
} public Person(String name, String phone) {
this.name = name;
this.phone = phone;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getPhone() {
return phone;
} public void setPhone(String phone) {
this.phone = phone;
}
}

下面也是我们最为关键的内容提供者操作类:通过该类其他的应该就可以访问当前应用的数据,只要是业务操作,业务操作的异常都不要内部进行try catch捕获,而应该将业务操作的异常返回给调用者,当调用者进行业务操作的时候,如果遇到了异常就知道该业务操作是成功还是失败了,然后做出相应的处理。相当的关键

package test.weiyuan.sqllite1;

import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.util.Log; import dB.DbOpenHelper; /**
* Created by wei.yuan on 2015/6/3.
* 一定要在清单文件中对内容提供者进行注册
* PersonProvider必须在应用的包名目录下或者包名的子目录下
*/
public class PersonProvider extends ContentProvider { private DbOpenHelper dbOpenHelper;
//该类用于检测的外部应用输入的URL是否正确,如果正确返回码就是codePerson,不正确返回UriMatcher.NO_MATCH
private static final int codePerson = 1;
private static final int codePerson1 = 2;
//该类用于检测的外部应用输入的URL是否正确,如果不正确返回码就是new UriMatcher(UriMatcher.NO_MATCH)构造函数中的参数,这里是UriMatcher.NO_MATCH
private static final UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
static
{
//这个url表示对整个person表进行操作,如果url匹配返回的值是codePerson
uriMatcher.addURI("test.weiyuan.sqllite1.PersonProvider","person",codePerson);
//这个url表示对person表中的某个记录进行操作,#表示的是数字,就是对应的person表中的某个记录
// android中#代表数字,*表示任意的字符,如果url匹配返回的值是codePerson1
uriMatcher.addURI("test.weiyuan.sqllite1.PersonProvider","person/#",codePerson1);
}
//onCreate()之后被调用一次,在调用的时候创建数据库,记得返回值为true
@Override
public boolean onCreate() {
dbOpenHelper = new DbOpenHelper(getContext());
return true;
} //查询数据表的数据
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
SQLiteDatabase database = dbOpenHelper.getWritableDatabase();
switch (uriMatcher.match(uri))
{
//更新整个表
case codePerson: return database.query("person",projection,selection,selectionArgs,null,null,sortOrder); //更新表中的某条记录
case codePerson1:
long row_id = ContentUris.parseId(uri);
String where = " personid="+row_id;
Log.i("weiyuan",""+row_id);
if (selection!=null&&!"".equals(selection.trim()))
{
where += "and "+selection;
}
return database.query("person",null,where,selectionArgs,null,null,sortOrder); default: //如果传人的url不正确,抛出一个异常提示用户
throw new IllegalArgumentException("this is a unkown url-->"+uri); } } //返回要操作数据的内容类型,如txt文本就是plain/text类型
@Override
public String getType(Uri uri) {
switch (uriMatcher.match(uri))
{
//操作的是多条数据记录
case codePerson:
return "vnd.android.cursor.dir/person";
//操作的是单条数据
case codePerson1:
return "vnd.android.cursor.item/person";
default:
throw new IllegalArgumentException("this is a unkown url-->"+uri);
}
} //可以让外面的应用向内容提供者插入数据
@Override
public Uri insert(Uri uri, ContentValues values) {
SQLiteDatabase database = dbOpenHelper.getWritableDatabase();
switch (uriMatcher.match(uri))
{
case codePerson:
//这里如果values为空,就必须需要第二个参数有值这里为"name",如果values有值,第二个参数默认为空值
long rowid = database.insert("person",null,values);
// Uri insertUri = Uri.parse("context://test.weiyuan.providers.PersonProvider/person/"+rowid);可以使用下面的方法http://blog.csdn.net/feng88724/article/details/6331396
Uri insertUri = ContentUris.withAppendedId(uri,rowid);
if(database!=null)
{
database.close();
} return insertUri; default:
//如果传人的url不正确,抛出一个异常提示用户
if(database!=null)
{
database.close();
}
throw new IllegalArgumentException("this is a unkown url-->"+uri); } } //返回值int表示你删除了多少条记录
@Override
public int delete(Uri uri, String selection, String[] selectionArgs)
{
SQLiteDatabase database = dbOpenHelper.getWritableDatabase();
int num = 0;//删除的记录数目
switch (uriMatcher.match(uri))
{
//删除整个表
case codePerson: num =database.delete("preson",selection,selectionArgs);
if(database!=null)
{
database.close();
}
break;
//删除表中的某条记录
case codePerson1:
// 从url中要删除的记录的id
long row_id = ContentUris.parseId(uri);
String where = " personid="+ row_id;
//外面传递进行的条件
if (selection!=null&&!"".equals(selection.trim()))
{
where += "and "+selection;
}
num = database.delete("person",where,selectionArgs);
if(database!=null)
{
database.close();
}
break; default:
//如果传人的url不正确,抛出一个异常提示用户
throw new IllegalArgumentException("this is a unkown url-->"+uri); } return num;
} @Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { SQLiteDatabase database = dbOpenHelper.getWritableDatabase();
switch (uriMatcher.match(uri))
{
//更新整个表
case codePerson: database.update("preson",values,selection,selectionArgs);
if(database!=null)
{
database.close();
}
break;
//更新表中的某条记录
case codePerson1:
long row_id = ContentUris.parseId(uri);
String where = " personid="+row_id;
Log.i("weiyuan",""+row_id);
if (selection!=null&&!"".equals(selection.trim()))
{
where += "and "+selection;
}
database.update("person",values,where,selectionArgs);
if(database!=null)
{
database.close();
}
break; default:
if(database!=null)
{
database.close();
}
//如果传人的url不正确,抛出一个异常提示用户
throw new IllegalArgumentException("this is a unkown url-->"+uri); }
return 0;
}
}

注意点2:

首先先让数据库这个app运行起来,现在我们在新建立一个app,在这个app中访问数据库app中的数据

我们使用测试工具类的办法来实现Android studio 中测试类必须继承AndroidTestCase,该类中的所有测试方法必须以test开头

package testSQLLite;

import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.test.AndroidTestCase;
import android.util.Log; /**
* Created by wei.yuan on 2015/6/3.
*/
public class TestContextProvider extends AndroidTestCase {
final static String TAG ="weiyuan"; //测试插入数据
public void testInsert() throws Exception
{
//注意uri中的字符串一般是小写,下面写成大写不太规范,一般遵循包名+类名,注意conten不要写成context了
Uri uri = Uri.parse("content://test.weiyuan.sqllite1.PersonProvider/person");
ContentResolver resolver = getContext().getContentResolver();
ContentValues values = new ContentValues();
values.put("name","aonier");
values.put("phone","28");
// 下面 resolver.insert(uri,values)这个函数本质上是调用了PersonProvider这个内容提供者中的insert函数
resolver.insert(uri,values);
Log.i(TAG,"数据插入成功!"); } //删除数据
public void testDelete() throws Exception
{
Uri uri = Uri.parse("content://test.weiyuan.sqllite1.PersonProvider/person/1");
long id = ContentUris.parseId(uri);
Log.i(TAG,id+"");
ContentResolver resolver = getContext().getContentResolver(); resolver.delete(uri,null,null);
Log.i(TAG,"数据删除成功!");
} //更新表中的数据
public void testUpdate() throws Exception
{
Uri uri = Uri.parse("content://test.weiyuan.sqllite1.PersonProvider/person/1");
long id = ContentUris.parseId(uri); ContentResolver resolver = getContext().getContentResolver();
ContentValues values = new ContentValues();
values.put("name","aonier");
values.put("phone","34");
resolver.update(uri,values,null,null);
Log.i(TAG, "数据更新成功!");
} //查询数据表的数据
public void testQuery() throws Exception
{
Uri uri = Uri.parse("content://test.weiyuan.sqllite1.PersonProvider/person"); ContentResolver resolver = getContext().getContentResolver();
Cursor cursor =resolver.query(uri, null, null, null, null);
while (cursor.moveToNext())
{
Log.i(TAG,"数据查询成功!"+cursor.getString(cursor.getColumnIndex("name"))); }
//加载自定义适配器的数据 } }

对应上面两种数据库的两种业务操作也可以使用测试类的方式进行测试:

package testSQLLite;

import android.test.AndroidTestCase;
import android.util.Log; import java.util.List; import dB.DbOpenHelper;
import domain.Person;
import service.OtherPersonService; public class OtherTestSQLLite extends AndroidTestCase {
final static String TAG ="weiyuan";
public void testCreateDb()
{
DbOpenHelper dbOpenHelper = new DbOpenHelper(getContext());
dbOpenHelper.getWritableDatabase();
Log.i(TAG,"数据库创建成功");
}
public void testSave() throws Exception{
OtherPersonService service = new OtherPersonService(this.getContext());
for(int i = 0;i<20;i++)
{
service.save(new Person("weiyuan"+i,"12345"+i));
}
Log.i(TAG,"数据保存成功");
} /*主要查找的是姓名和电话一起查找,只要满足了姓名和电话,才正确*/
public void testFind() throws Exception{
OtherPersonService service = new OtherPersonService(this.getContext());
Person person = service.find("weiyuan1","123451");
Log.i(TAG, person.toString());
Log.i(TAG,"数据查找成功"); } /*删除某个记录*/
public void testdelete() throws Exception{
OtherPersonService service = new OtherPersonService(this.getContext());
service.delete("weiyuan1","123451");
Log.i(TAG,"数据删除成功"); }
/*给新某个记录*/
public void testupdate() throws Exception{
OtherPersonService service = new OtherPersonService(this.getContext());
service.update(new Person("chendong","456789"),"weiyuan2","123452");
Log.i(TAG, "数据修改成功"); }
/*获得分页的数据*/
public void testScrollData() throws Exception{
OtherPersonService service = new OtherPersonService(this.getContext());
List<Person> persons = service.getScrollData(0, 5);
for(Person person : persons){
Log.i(TAG, person.toString());
} } public void testCount() throws Exception{
OtherPersonService service = new OtherPersonService(this.getContext());
long result = service.getCount();
Log.i(TAG, result+"");
} }
package testSQLLite;

import android.test.AndroidTestCase;
import android.util.Log;
import android.widget.Toast; import java.util.List; import dB.DbOpenHelper;
import domain.Person;
import service.PersonService; public class TestSQLLite extends AndroidTestCase {
final static String TAG ="weiyuan";
public void testCreateDb()
{
DbOpenHelper dbOpenHelper = new DbOpenHelper(getContext());
dbOpenHelper.getWritableDatabase();
Log.i(TAG,"数据库创建成功");
}
public void testSave() throws Exception{
PersonService service = new PersonService(this.getContext());
for(int i = 0;i<20;i++)
{
service.save(new Person("weiyuan"+i,"12345"+i));
}
Log.i(TAG,"数据保存成功");
} /*主要查找的是姓名和电话一起查找,只要满足了姓名和电话,才正确*/
public void testFind() throws Exception{
PersonService service = new PersonService(this.getContext());
Person person = service.find("chendong","456789");
Log.i(TAG, person.toString());
Log.i(TAG,"数据查找成功"); } /*删除某个记录*/
public void testdelete() throws Exception{
PersonService service = new PersonService(this.getContext());
service.delete("weiyuan1","123451");
Log.i(TAG,"数据删除成功"); }
/*给新某个记录*/
public void testupdate() throws Exception{
PersonService service = new PersonService(this.getContext());
service.update(new Person("chendong","456789"),"weiyuan2","123452");
Log.i(TAG, "数据修改成功"); }
/*获得分页的数据*/
public void testScrollData() throws Exception{
PersonService service = new PersonService(this.getContext());
List<Person> persons = service.getScrollData(0, 5);
for(Person person : persons){
Log.i(TAG, person.toString());
} } public void testCount() throws Exception{
PersonService service = new PersonService(this.getContext());
long result = service.getCount();
Log.i(TAG, result+"");
} }

黎活明8天快速掌握android视频教程--20_采用ContentProvider对外共享数据的更多相关文章

  1. 黎活明8天快速掌握android视频教程--19_采用ListView实现数据列表显示

    1.首先整个程序也是采用mvc的框架 DbOpenHelper 类 package dB; import android.content.Context; import android.databas ...

  2. 黎活明8天快速掌握android视频教程--17_创建数据库与完成数据添删改查

    1.我们首先来看下整个项目 项目也是采用mvc的框架 package dB; import android.content.Context; import android.database.sqlit ...

  3. 黎活明8天快速掌握android视频教程--16_采用SharedPreferences保存用户偏好设置参数

    SharedPreferences保存的数据是xml格式,也是存在数据保存的下面四种权限: 我们来看看 我们来看看具体的业务操作类: /** * 文件名:SharedPrecences.java * ...

  4. 黎活明8天快速掌握android视频教程--15_采用Pull解析器解析和生成XML内容

    1.该项目主要有下面的两个作用 (1)将xml文件解析成对象的List对象,xml文件可以来自手机本地,也可以来自服务器返回的xml数据 (2)强list对象保存成xml文件,xml保存到手机的内存卡 ...

  5. 黎活明8天快速掌握android视频教程--21_监听ContentProvider中数据的变化

    采用ContentProvider除了可以让其他应用访问当前的app的数据之外,还有可以实现当app的数据发送变化的时候,通知注册了数据变化通知的调用者 其他所有的代码都和第20讲的一样,不同的地方看 ...

  6. 黎活明8天快速掌握android视频教程--22_访问通信录中的联系人和添加联系人

    Android系统中联系人的通讯录的contentProvide是一个单独的apk,显示在界面的contact也是一个独立的apk,联系人apk通过contentProvide访问底层的数据库. 现在 ...

  7. 黎活明8天快速掌握android视频教程--25_网络通信之资讯客户端

    1 该项目的主要功能是:后台通过xml或者json格式返回后台的视频资讯,然后Android客户端界面显示出来 首先后台新建立一个java web后台 采用mvc的框架 所以的servlet都放在se ...

  8. 黎活明8天快速掌握android视频教程--24_网络通信之网页源码查看器

    1 该项目的主要功能就是从将后台的html网页在Android的界面上显示出来 后台就是建立一个java web工程在工程尚建立一个html或者jsp文件就可以了,这里主要看Android客户端的程序 ...

  9. 黎活明8天快速掌握android视频教程--23_网络通信之网络图片查看器

    1.首先新建立一个java web项目的工程.使用的是myeclipe开发软件 图片的下载路径是http://192.168.1.103:8080/lihuoming_23/3.png 当前手机和电脑 ...

随机推荐

  1. ES6-变量let和常量const

    1.以往js变量 var 1.可以重复声明 2.无法限制修改(指不能声明常量) 3.没有块级作用域(指{}这样的) 2.现在ES6变量 let 不能重复声明-变量,可以修改,块级作用域 const 不 ...

  2. Chisel3 - util - ReadyValid

    https://mp.weixin.qq.com/s/g7Q9ChxHbAQGkbMmOymh-g   ReadyValid通信接口.通信的双方为数据的生产者(Producer)和消费者(Consum ...

  3. break 与 continue 的作用 详解

    1.break 用break语句可以使流程跳出switch语句体,也可以用break语句在循环结构终止本层循环体,从而提前结束本层循环. 使用说明: (1)只能在循环体内和switch语句体内使用br ...

  4. JAVASE(十五) 泛型 :泛型用例、自定义泛型类、通配符

    个人博客网:https://wushaopei.github.io/    (你想要这里多有) 1.泛型在集合中的使用 1.1 在集合中使用泛型之前的例子 ​ 为什么要有泛型(Generic)? 1. ...

  5. Linux (七)权限控制

    个人博客网:https://wushaopei.github.io/    (你想要这里多有) 1. 概述 Linux需要对登录用户读写执行文件.进入目录.查看增删目录内容等操作进行控制,不能任由用户 ...

  6. Java实现 LeetCode 830 较大分组的位置(暴力模拟)

    830. 较大分组的位置 在一个由小写字母构成的字符串 S 中,包含由一些连续的相同字符所构成的分组. 例如,在字符串 S = "abbxxxxzyy" 中,就含有 "a ...

  7. Java实现 LeetCode 707 设计链表(环形链表)

    707. 设计链表 设计链表的实现.您可以选择使用单链表或双链表.单链表中的节点应该具有两个属性:val 和 next.val 是当前节点的值,next 是指向下一个节点的指针/引用.如果要使用双向链 ...

  8. Java实现 LeetCode 258 各位相加

    258. 各位相加 给定一个非负整数 num,反复将各个位上的数字相加,直到结果为一位数. 示例: 输入: 38 输出: 2 解释: 各位相加的过程为:3 + 8 = 11, 1 + 1 = 2. 由 ...

  9. Java实现蓝桥杯历届试题区间移位

    问题描述 数轴上有n个闭区间D1,-,Dn.其中区间Di用一对整数[ai, bi]来描述,满足ai < bi.已知这些区间的长度之和至少有10000.所以,通过适当的移动这些区间,你总可以使得他 ...

  10. java实现高斯日记

    题目标题: 高斯日记 大数学家高斯有个好习惯:无论如何都要记日记. 他的日记有个与众不同的地方,他从不注明年月日,而是用一个整数代替,比如:4210 后来人们知道,那个整数就是日期,它表示那一天是高斯 ...