android ContentProvider

本文介绍了Android中ContentResolver和ContentProvider的基本用法。通过示例代码展示了如何使用ContentResolver查询数据,并配置了ContentProvider的相关设置。对于理解Android应用间的数据交互具有很好的指导意义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

android ContentProvider


1、ContentProvider内容提供者
2、ContentResolver内容访问者  两个知识



先给一张思维导图


这是 新建的内容访问者MainActivity.java

package com.zking.administrator.g160618_android25_contentresolver;

import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //获取16次课的数据
        //获取内容访问者
        ContentResolver cr=getContentResolver();
        Uri uri=Uri.parse("content://com.zking.administrator.g160618_android16_sqlite.LOGIN");
        Cursor cursor=cr.query(uri,null,null,null,null);
        while(cursor.moveToNext()){
           int uid=cursor.getInt(cursor.getColumnIndex("uid"));
            String uname=cursor.getString(cursor.getColumnIndex("uname")) ;
            String upass=cursor.getString(cursor.getColumnIndex("upass")) ;
            Log.i("test",uid+" "+uname+" "+upass);
        }
    }
}


当然 还有一个内容提供者

那个内容提供者 需要配置一些信息

AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.zking.administrator.g160618_android16_sqlite">

    <application android:allowBackup="true" android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true" android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!--配置内容提供者-->
        <provider
            android:authorities="com.zking.administrator.g160618_android16_sqlite.LOGIN"
            android:name=".MyProvider"
            android:exported="true"
            ></provider>
    </application>

</manifest>








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值