标签: android-contentprovider

如何处理搜索建议点击项目

我使用了官方的Android示例代码"SearchableDictionary"(链接:http://jayxie.com/mirrors/android-sdk/resources/samples/SearchableDictionary/index.html ),它为我们提供了一个搜索界面,您可以在其中搜索一句话,你有两个选择:

1-输入关键字并单击搜索图标(键盘),以显示所有匹配结果的列表视图.单击ListView中的单词以检索定义.

2-每当searchView关键字发生变化时,放置关键字并自动显示一个建议列表,这样您就可以点击建议来检索她的定义.

这是当您单击大列表视图中的项而不是建议列表中时调用的搜索函数的代码.

     private void doSearch(String queryStr) { 
            // get a Cursor, prepare the ListAdapter and set it
     final DataBaseHelper myDbHelper = new DataBaseHelper(this);
     myDbHelper.openDataBase();
     Cursor cursor = managedQuery(DictionaryProvider.CONTENT_URI, null, null,
             new String[] {queryStr}, null);
    //Cursor cursor = myDbHelper.fetchListItems(queryStr);
    //cursorr.moveToFirst(); // moves the cursor to the first row in the result set, returns false if the result set is empty.

    startManagingCursor(cursor); /* Managing cursors take care of closing the cursor when
    the activity is destroyed, but …
Run Code Online (Sandbox Code Playgroud)

android android-contentprovider android-listview search-suggestion

1
推荐指数
1
解决办法
3194
查看次数

如何使用内容提供程序删除第一个"n"行

我想使用内容提供程序删除第一个"n"行.

这是我的代码:

    private void deleteOldItems(int number) {
    String where = HistoryTable.COLUMN_ID + "<=?";
    getContentResolver()
            .delete(Uri.parse("content://com.ipiit.client.contentprovider.HistoryContentProvider/histories"),
                    where, new String[] {String.valueOf(number)});
    }
Run Code Online (Sandbox Code Playgroud)

我工作但只有一次.如何始终删除第一行?

sqlite android android-contentprovider

1
推荐指数
1
解决办法
1127
查看次数

如何访问不同活动中片段的 contentResolver?

情况是我有一个MainFragment(extends a ListFragment, implements LoaderManager.LoaderCallbacks<Cursor>) 是从MainActivity. DetailsActivity从该片段调用一个新活动以在列表视图中显示某个项目的内容,将 id 作为意图参数。如何getContentResolver()使用 Uri 访问其方法?

我现在从访问内容解析器中得到的错误是:

`java.lang.IllegalArgumentException: Unknown URL content://com.xxxx.words.contentprovider/words`

uri = Uri.parse(MainContentProvider.CONTENT_URI.toString());
            getContentResolver().insert(uri, contentValues);

CONTENT_URI = Uri.parse("content://" + "com.xxxx.words.contentprovider" + "/" + "words");
Run Code Online (Sandbox Code Playgroud)

安卓清单文件:

<provider
        android:authorities="com.xxxx.words.contentprovider.MainContentProvider"
        android:name=".contentprovider.MainContentProvider"/>
Run Code Online (Sandbox Code Playgroud)

或者我应该只返回一个BundleDetailsActivity初始片段和访问的内容提供商?

android android-contentresolver android-contentprovider android-fragments android-activity

1
推荐指数
2
解决办法
1万
查看次数

Android以编程方式将联系人设置为收藏夹

任何人都可以告诉我,如果我有一个联系人列表并在我的应用程序中阅读它们,我想直接从我的应用程序设置与收藏夹的联系,这样当我再次打开手机联系时,我将能够找到最喜欢的联系人Android手机列表.

请帮忙

android contacts android-contentprovider android-contacts

1
推荐指数
1
解决办法
1790
查看次数

无法从其他应用访问customProvider.它说它缺少已有的权限

我正在尝试使用自定义内容提供程序创建一个从另一个应用程序访问SQLite表的应用程序.我收到以下错误:

java.lang.SecurityException: Permission Denial: reading com.example.carlos.gymlog.MiContentProvider uri content://mi.uri.porquesi/sesiones from pid=2375, uid=10064 requires android.permission.permRead, or grantUriPermission()
Run Code Online (Sandbox Code Playgroud)

但是,我的"发件人"应用程序(具有数据库的应用程序)已具有所需的权限:

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/MiTema" >
        <activity
            android:name=".Principal"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <provider android:name="MiContentProvider"
            android:authorities="mi.uri.porquesi"
            android:readPermission="android.permission.permRead"
            android:exported="true"
            android:grantUriPermissions="true"> </provider>

    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

这是导致"receiver"应用程序(尝试访问另一个)的错误的代码:

ArrayList<Sesion> sacarDatos(Context c){

        Uri cUri = Uri.parse("content://mi.uri.porquesi/sesiones");
        ContentProviderClient miCP = c.getContentResolver().acquireContentProviderClient(cUri);

        ArrayList<Sesion> sesiones = null;
        try {
            Cursor cur  = miCP.query(cUri, null, null, null, null);
            sesiones = new …
Run Code Online (Sandbox Code Playgroud)

sqlite android android-contentprovider

1
推荐指数
1
解决办法
762
查看次数

在Android Studio 2.3.3中创建ContentProvider

我正在使用 Android Studio 2.3.3,并尝试将 Content Provider 组件添加到项目中。即使在尝试了 URI 权限条目的许多变体之后,我仍然收到错误“URI 权限必须是有效的 URI 权限”。全新项目的结果相同,如下所示。这是在 Studio 中运行还是条目有问题?

Android Studio 配置组件

android intellij-idea android-contentprovider android-studio

1
推荐指数
1
解决办法
320
查看次数

contact_last_updated_timestamp 标志到底返回什么?

我正在获取给定时间戳后更新的联系人,我的代码是

Uri uri = ContactsContract.Contacts.CONTENT_URI;
Cursor cursor = cur = contentResolver.query(uri, null, "contact_last_updated_timestamp > ?", new String[]{timeStamp}, null);
Run Code Online (Sandbox Code Playgroud)

但光标返回给定时间戳之后未更新/删除/添加的联系人。
问题是光标返回设备联系人列表中的一些联系人。
这意味着查询错误的可能性较小。
我的问题是,为什么光标返回未更新/删除/添加的联系人?
如何获取给定时间戳后更新的联系人列表?(不使用ContentObserver)

先感谢您!

android android-contentprovider android-contacts

1
推荐指数
1
解决办法
690
查看次数

Android 10 MediaStore API 更改

Uri uri = MediaStore.Audio.Artists.Albums.getContentUri("external", 
artistId);

String[] projection = new String[] {BaseColumns._ID};

Cursor cursor = 
mContext.getApplicationContext().getContentResolver().query
(uri,
projection,
null,
null,
null);
Run Code Online (Sandbox Code Playgroud)

在 Android 10 之前,BaseColumns._ID 返回专辑 ID,现在在 10 中,它返回一些随机 ID。

当我将投影传递为 null 并检索下面的所有列名时,我得到的列名。这是在 Android 10 中。 [numsongs、artist、numsongs_by_artist、album、album_art、album_key、artist_id、maxyear、minyear、album_id]

Android 10 以下没有 _id 列。

要获得 10 中的专辑 ID,我必须使用以下投影

String[] projection = new String[] 
{MediaStore.Audio.Artists.Albums.ALBUM_ID};
Run Code Online (Sandbox Code Playgroud)

对于下面相同的 Uri 是我在 Android 10 以下获得的可用列。 [album_art、maxyear、minyear、artist、album、artist_key、numsongs_by_artist、_id、numsongs、album_key、artist]

这里没有专辑_id 列,_id 返回专辑_id。现在在 10 中是不可用的。

现在我需要使用不同的代码来获取专辑 ID,一个用于 Android 10,另一个用于低于 Android 10。

这些变化在 Android 10 行为变化中没有列出。这对我们来说是非常关键的变化,像这样的一个小变化可能会破坏我们每天有 150 万人使用的整个应用程序。

怎么会有人像这样改变而不让开发人员知道呢?(或)我在文档中遗漏了什么。(或)如何跟踪这些更改?

android mediastore android-music-player android-contentprovider android-10.0

1
推荐指数
1
解决办法
2783
查看次数

无法从其他应用程序访问自定义内容提供程序

我有 2 个应用程序,我希望应用程序 A 通过内容提供商与 B 共享数据,我可以访问应用程序 A 中的内容提供商,但不能访问应用程序 BI 中的内容提供商,感觉我的权限混乱,但不知道如何修复它。这是我的文件...应用程序 A 的清单文件:

 <permission android:name="myper.READ" android:protectionLevel="normal"  />
<permission android:name="myper.WRITE" android:protectionLevel="normal"  />

<application
    android:name=".ui.MyApplication"
    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/Theme.Ex">

    <activity android:name="com.abcd.aaaaa.ui.MainActivity"
        >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <provider
        android:authorities="com.advance.usercontentprovider"
        android:name=".contentprovider.UserContentProvider"
        android:enabled="true"
        android:exported="true"
        android:multiprocess="true"
        android:readPermission="myper.READ"
        android:writePermission="myper.WRITE"
    />
</application>
Run Code Online (Sandbox Code Playgroud)

和 B 的清单文件:

<uses-permission android:name="myper.READ" />
<uses-permission android:name="myper.WRITE" />

<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/Theme.aaaa">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

</application>
Run Code Online (Sandbox Code Playgroud)

自定义内容提供商: …

android android-contentprovider kotlin

1
推荐指数
1
解决办法
1262
查看次数

IntentService RuntimeException

可能重复:
Android RuntimeException:无法实例化服务

问题:开始IntentService生成一个RuntimeException.

我很无能为力.如果您需要更多信息,请询问.日志:

D/dalvikvm( 6839): newInstance failed: no <init>()
D/AndroidRuntime( 6839): Shutting down VM
W/dalvikvm( 6839): threadid=1: thread exiting with uncaught exception (group=0x40015560)
E/AndroidRuntime( 6839): FATAL EXCEPTION: main
E/AndroidRuntime( 6839): java.lang.RuntimeException: Unable to instantiate service org.xyz.android.service.MyService: java.lang.InstantiationException: org.xyz.android.service.MyService
E/AndroidRuntime( 6839):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:1929)
E/AndroidRuntime( 6839):    at android.app.ActivityThread.access$2500(ActivityThread.java:117)
E/AndroidRuntime( 6839):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
E/AndroidRuntime( 6839):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 6839):    at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 6839):    at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime( 6839):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 6839):    at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 6839):    at …
Run Code Online (Sandbox Code Playgroud)

android android-contentprovider runtimeexception intentservice

0
推荐指数
1
解决办法
2247
查看次数