访问内容提供者
来源:互联网 发布:误清空回收站恢复软件 编辑:程序博客网 时间:2024/06/05 00:47
package com.xh.tx.test;import android.app.Activity;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {// Handle action bar item clicks here. The action bar will// automatically handle clicks on the Home/Up button, so long// as you specify a parent activity in AndroidManifest.xml.int id = item.getItemId();if (id == R.id.action_settings) {return true;}return super.onOptionsItemSelected(item);}}
package com.xh.tx.test;import android.content.ContentResolver;import android.content.ContentValues;import android.database.Cursor;import android.net.Uri;import android.test.AndroidTestCase;import android.util.Log;public class TestPersonContentProvider extends AndroidTestCase {private static final String TAG = "TestPersonContentProvider";public void testInsert(){//访问地址:content://com.xh.tx.contentprivoder.PersonContentPrivoder/person/insertContentResolver resolver = getContext().getContentResolver();ContentValues values = new ContentValues();values.put("name","zs");values.put("age","20");resolver.insert(Uri.parse("content://com.xh.tx.contentprivoder.PersonContentPrivoder/person/insert"),values);}public void testUpdate(){ContentResolver resolver = getContext().getContentResolver(); //内容提供者的访问类ContentValues values = new ContentValues();values.put("name", "1505");String where = "id = ?";String[] selectionArgs = new String[]{"1"};int id = resolver.update(Uri.parse("content://com.xh.tx.contentprivoder.PersonContentPrivoder/person/update"), values , where, selectionArgs);Log.d(TAG, "UPDATE .... = " + id);}public void testQuery(){ContentResolver resolver = getContext().getContentResolver(); //内容提供者的访问类//content://com.xh.tx.contentprivoder.PersonContentPrivoder/person/queryString[] projection = new String[]{"id","name","age"};Cursor cursor = resolver.query(Uri.parse("content://com.xh.tx.contentprivoder.PersonContentPrivoder/person/query"), projection, null, null, null);if(null != cursor && cursor.getCount() > 0){while(cursor.moveToNext()){Integer id = cursor.getInt(0);String name = cursor.getString(1);Integer age = cursor.getInt(2);Log.d(TAG, "id=" + id + " name= " + name + " age= " + age);}cursor.close(); // 一定记住不要忘了关闭游标}}}
0 0
- 内容提供者访问
- 访问内容提供者
- 访问内容提供者
- 内容提供者访问通讯录
- 访问内容提供者
- Android 访问自定义内容提供者
- Android_09_自定义内容提供者及访问内容提供者
- 内容提供者创建,访问和权限
- android_访问系统短信内容提供者
- ContentProvider内容提供者,跨进程访问方式
- 内容提供者
- 内容提供者
- 内容提供者
- 内容提供者
- 内容提供者
- 内容提供者
- 内容提供者
- 内容提供者
- Java环境变量配置
- 命令行乱码处理
- hdu 3501 欧拉函数
- JAVA自定义序列化的神奇方法
- ASP.NET权限管理系统(FrameWork) 1.0.7
- 访问内容提供者
- spring security过滤器
- 程序从后台到前台,内存被回收导致的空现象
- STM32驱动DP83848注意事项
- 杂言·二
- Android 异步加载解决方案
- 如何将table表中的数据导出excel表
- No index path for table cell being reused 这个问题
- java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)错误原因