Coder Social home page Coder Social logo

nt4f04und / android_content_provider Goto Github PK

View Code? Open in Web Editor NEW
14.0 14.0 4.0 149 KB

Flutter plugin to use ContentProvider/ContentResolver APIs on Android

License: BSD 2-Clause "Simplified" License

Kotlin 31.17% Java 7.45% Dart 61.38%
android content-provider flutter flutter-plugin plugin

android_content_provider's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

android_content_provider's Issues

Widget inspector is not working

Hi! Thanks for the plugin!
There is an error with widget inspector. It does not start when the project has a custom ContentProvider.

On your example_provider it's also not working. How can we solve this problem?

Снимок экрана 2023-12-06 в 19 38 00

@pragma('vm:entry-point')
void exampleContentProviderEntrypoint() {
  MyAndroidContentProvider(
    'com.nt4f04und.android_content_provider_example.MyAndroidContentProvider',
  );
}
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.1)
[✓] VS Code (version 1.84.2)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!```

Unable to get the provider

Launching lib/main.dart on sdk gphone64 arm64 in debug mode...
Running Gradle task 'assembleDebug'...
✓ Built build/app/outputs/flutter-apk/app-debug.apk.
Installing build/app/outputs/flutter-apk/app.apk...
E/AndroidRuntime(22557): FATAL EXCEPTION: main
E/AndroidRuntime(22557): Process: com.example.content_provider, PID: 22557
E/AndroidRuntime(22557): java.lang.RuntimeException: Unable to get provider com.example.content_provider.MyAndroidContentProvider: java.lang.ClassNotFoundException: Didn't find class "com.example.content_provider.MyAndroidContentProvider" on path: DexPathList[[zip file "/data/app/~~FJz_B56z_SzEzgvhvEwn3g==/com.example.content_provider-Xu7Gp4ZA7unlA_9hB2S6vA==/base.apk"],nativeLibraryDirectories=[/data/app/~~FJz_B56z_SzEzgvhvEwn3g==/com.example.content_provider-Xu7Gp4ZA7unlA_9hB2S6vA==/lib/arm64, /data/app/~~FJz_B56z_SzEzgvhvEwn3g==/com.example.content_provider-Xu7Gp4ZA7unlA_9hB2S6vA==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]
E/AndroidRuntime(22557): at android.app.ActivityThread.installProvider(ActivityThread.java:7436)
E/AndroidRuntime(22557): at android.app.ActivityThread.installContentProviders(ActivityThread.java:6948)
E/AndroidRuntime(22557): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6719)
E/AndroidRuntime(22557): at android.app.ActivityThread.access$1500(ActivityThread.java:256)
E/AndroidRuntime(22557): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2090)
E/AndroidRuntime(22557): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(22557): at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime(22557): at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime(22557): at android.app.ActivityThread.main(ActivityThread.java:7842)
E/AndroidRuntime(22557): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(22557): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/AndroidRuntime(22557): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
E/AndroidRuntime(22557): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.content_provider.MyAndroidContentProvider" on path: DexPathList[[zip file "/data/app/~~FJz_B56z_SzEzgvhvEwn3g==/com.example.content_provider-Xu7Gp4ZA7unlA_9hB2S6vA==/base.apk"],nativeLibraryDirectories=[/data/app/~~FJz_B56z_SzEzgvhvEwn3g==/com.example.content_provider-Xu7Gp4ZA7unlA_9hB2S6vA==/lib/arm64, /data/app/~~FJz_B56z_SzEzgvhvEwn3g==/com.example.content_provider-Xu7Gp4ZA7unlA_9hB2S6vA==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]
E/AndroidRuntime(22557): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
E/AndroidRuntime(22557): at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/AndroidRuntime(22557): at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/AndroidRuntime(22557): at android.app.AppComponentFactory.instantiateProvider(AppComponentFactory.java:147)
E/AndroidRuntime(22557): at androidx.core.app.CoreComponentFactory.instantiateProvider(CoreComponentFactory.java:67)
E/AndroidRuntime(22557): at android.app.ActivityThread.installProvider(ActivityThread.java:7420)
E/AndroidRuntime(22557): ... 11 more

null cannot be cast to non-null type kotlin.String

full error : [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(ERROR, Method call failed, java.lang.NullPointerException: null cannot be cast to non-null type kotlin.String

const uri =
        'content://com.nt4f04und.android_content_provider_example.MyAndroidContentProvider/hello';
    final values = ContentValues();
    values.putString("streams", "stream 1");
    await AndroidContentResolver.instance.insert(uri: uri, values: values);

Unable to get provider com.nt4f04und.android_content_provider_example.MyAndroidContentProvider

Hello,

I'm trying to add functionality of providing data to example. I'm following instructions in README and I did all steps.

When I'm trying to build it - it stacks and shows me an error.

Launching lib/main.dart on sdk gphone x86 in debug mode... ✓ Built build/app/outputs/flutter-apk/app-debug.apk. E/AndroidRuntime(10875): FATAL EXCEPTION: main E/AndroidRuntime(10875): Process: com.nt4f04und.android_content_provider_example, PID: 10875 E/AndroidRuntime(10875): java.lang.RuntimeException: Unable to get provider com.nt4f04und.android_content_provider_example.MyAndroidContentProvider: java.lang.ClassNotFoundException: Didn't find class "com.nt4f04und.android_content_provider_example.MyAndroidContentProvider" on path: DexPathList[[zip file "/data/app/~~qFgYI7_uF_VuZ7SP_YEthQ==/com.nt4f04und.android_content_provider_example-r0Iu4fuBXqpjGethMdzamA==/base.apk"],nativeLibraryDirectories=[/data/app/~~qFgYI7_uF_VuZ7SP_YEthQ==/com.nt4f04und.android_content_provider_example-r0Iu4fuBXqpjGethMdzamA==/lib/x86, /data/app/~~qFgYI7_uF_VuZ7SP_YEthQ==/com.nt4f04und.android_content_provider_example-r0Iu4fuBXqpjGethMdzamA==/base.apk!/lib/x86, /system/lib, /system_ext/lib]] E/AndroidRuntime(10875): at android.app.ActivityThread.installProvider(ActivityThread.java:7244) E/AndroidRuntime(10875): at android.app.ActivityThread.installContentProviders(ActivityThread.java:6780) E/AndroidRuntime(10875): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6697) E/AndroidRuntime(10875): at android.app.ActivityThread.access$1300(ActivityThread.java:237) E/AndroidRuntime(10875): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913) E/AndroidRuntime(10875): at android.os.Handler.dispatchMessage(Handler.java:106) E/AndroidRuntime(10875): at android.os.Looper.loop(Looper.java:223) E/AndroidRuntime(10875): at android.app.ActivityThread.main(ActivityThread.java:7656) E/AndroidRuntime(10875): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(10875): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) E/AndroidRuntime(10875): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) E/AndroidRuntime(10875): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.nt4f04und.android_content_provider_example.MyAndroidContentProvider" on path: DexPathList[[zip file "/data/app/~~qFgYI7_uF_VuZ7SP_YEthQ==/com.nt4f04und.android_content_provider_example-r0Iu4fuBXqpjGethMdzamA==/base.apk"],nativeLibraryDirectories=[/data/app/~~qFgYI7_uF_VuZ7SP_YEthQ==/com.nt4f04und.android_content_provider_example-r0Iu4fuBXqpjGethMdzamA==/lib/x86, /data/app/~~qFgYI7_uF_VuZ7SP_YEthQ==/com.nt4f04und.android_content_provider_example-r0Iu4fuBXqpjGethMdzamA==/base.apk!/lib/x86, /system/lib, /system_ext/lib]] E/AndroidRuntime(10875): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207) E/AndroidRuntime(10875): at java.lang.ClassLoader.loadClass(ClassLoader.java:379) E/AndroidRuntime(10875): at java.lang.ClassLoader.loadClass(ClassLoader.java:312) E/AndroidRuntime(10875): at android.app.AppComponentFactory.instantiateProvider(AppComponentFactory.java:147) E/AndroidRuntime(10875): at androidx.core.app.CoreComponentFactory.instantiateProvider(CoreComponentFactory.java:67) E/AndroidRuntime(10875): at android.app.ActivityThread.installProvider(ActivityThread.java:7228) E/AndroidRuntime(10875): ... 10 more Exited

Looks like it failed to found instance of class MyAndroidContentProvider.

Didn't find class "com.example.content_provider.MainActivity"

Launching lib/main.dart on sdk gphone64 arm64 in debug mode...
Running Gradle task 'assembleDebug'...
✓ Built build/app/outputs/flutter-apk/app-debug.apk.
E/AndroidRuntime(23532): FATAL EXCEPTION: main
E/AndroidRuntime(23532): Process: com.example.content_provider, PID: 23532
E/AndroidRuntime(23532): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.content_provider/com.example.content_provider.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.content_provider.MainActivity" on path: DexPathList[[zip file "/data/app/~~ri1EIfwfv0KCTArCWiLKXA==/com.example.content_provider-uH1AcXEyOAHOM6kIcsJS0Q==/base.apk"],nativeLibraryDirectories=[/data/app/~~ri1EIfwfv0KCTArCWiLKXA==/com.example.content_provider-uH1AcXEyOAHOM6kIcsJS0Q==/lib/arm64, /data/app/~~ri1EIfwfv0KCTArCWiLKXA==/com.example.content_provider-uH1AcXEyOAHOM6kIcsJS0Q==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]
E/AndroidRuntime(23532): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3591)
E/AndroidRuntime(23532): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3842)
E/AndroidRuntime(23532): at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
E/AndroidRuntime(23532): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E/AndroidRuntime(23532): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E/AndroidRuntime(23532): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2252)
E/AndroidRuntime(23532): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(23532): at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime(23532): at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime(23532): at android.app.ActivityThread.main(ActivityThread.java:7842)
E/AndroidRuntime(23532): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(23532): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/AndroidRuntime(23532): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
E/AndroidRuntime(23532): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.content_provider.MainActivity" on path: DexPathList[[zip file "/data/app/~~ri1EIfwfv0KCTArCWiLKXA==/com.example.content_provider-uH1AcXEyOAHOM6kIcsJS0Q==/base.apk"],nativeLibraryDirectories=[/data/app/~~ri1EIfwfv0KCTArCWiLKXA==/com.example.content_provider-uH1AcXEyOAHOM6kIcsJS0Q==/lib/arm64, /data/app/~~ri1EIfwfv0KCTArCWiLKXA==/com.example.content_provider-uH1AcXEyOAHOM6kIcsJS0Q==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]
E/AndroidRuntime(23532): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
E/AndroidRuntime(23532): at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/AndroidRuntime(23532): at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/AndroidRuntime(23532): at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
E/AndroidRuntime(23532): at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
E/AndroidRuntime(23532): at android.app.Instrumentation.newActivity(Instrumentation.java:1285)
E/AndroidRuntime(23532): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3578)
E/AndroidRuntime(23532): ... 12 more

Namespace not specified

Hi! I get the error below after update to Gradle 8.1.1. Is there anything I can do or do I need to wait for a new version of android_content_provider before I can update Gradle?

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':android_content_provider'.
> Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
   > Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.

     If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 459ms
Running Gradle task 'assembleRelease'...                           875ms
Gradle task assembleRelease failed with exit code 1

Proper integration tests support

Currently the integration_test app is just an app that I run manually, like a normal Flutter app on emulator/device.
In that case, tests run in LiveTestWidgetsFlutterBinding, and it works.

However, I never figured out how to run instrumented integration tests with integration_test plugin, because of the issue flutter/flutter#96739

Plugin should support proper integration_test framework.

Opening this issue here for it be discoverable by other people.

Initialization Problems

Hey @nt4f04uNd - first of all thanks for creating this awesome content provider plugin!

I have trouble getting this to work based on the current Flutter 3.7 release, after defining the extensions and manifest entries, I cannot start my app anymore:

E/flutter (22085): [ERROR:flutter/runtime/dart_isolate.cc(668)] Could not resolve main entrypoint function.
E/flutter (22085): [ERROR:flutter/runtime/dart_isolate.cc(168)] Could not run the run main Dart entrypoint.
E/flutter (22085): [ERROR:flutter/runtime/runtime_controller.cc(417)] Could not create root isolate.
E/flutter (22085): [ERROR:flutter/shell/common/shell.cc(606)] Could not launch engine with configuration.

I then tried out to run your example project, however in this case I could complete the compilation, I get these warnings when calling flutter run in the example folder:

Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/03 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/03 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/03 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: unexpected element (uri:"", local:"extension-level"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
e: C:\Users\PC\Development\DentsplySirona\android_content_provider\android\src\main\kotlin\com\nt4f04und\android_content_provider\AndroidContentResolver.kt: (108, 88): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type Drawable?

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':android_content_provider:compileDebugKotlin'.
> Compilation error. See log for more details

When I now change the line 108 from

"icon" to bitmapToBytes(info.icon.loadDrawable(context).toBitmap()),

to

"icon" to bitmapToBytes(info.icon.loadDrawable(context)!!.toBitmap()),

AND I upgraded the permission_handler to ^10.2.0, then I could run your example without error messages.

Then I tried reading data from the example content provider in MyAndroidContentProvider / main.dart like so:

  @override
  Future<CursorData?> query(
    String uri,
    List<String>? projection,
    String? selection,
    List<String>? selectionArgs,
    String? sortOrder,
  ) async {
    return MatrixCursorData(
      columnNames: ['title', 'description'],
      notificationUris: ['First title', 'First description'],
    );
  }

To read this I hijacked the existing callToMyAndroidContentProvider method:

  Future<void> callToMyAndroidContentProvider() async {
    final cursor = await AndroidContentResolver.instance.query(
      uri:
          'content://com.nt4f04und.android_content_provider_example.MyAndroidContentProvider/some_uri',
      projection: ['title', 'description'],
    );
    print('got MyAndroidContentProvider query: $cursor');
    if (cursor != null) {
      try {
        final end =
            (await cursor.batchedGet().getCount().commit()).first as int;
        final batch = cursor.batchedGet().getInt(0).getString(1);

        // Fast!
        // While a bit less flexible, commitRange is much faster (approximately 10x)
        await measure(() async {
          final data = await batch.commitRange(0, end);
          print('got data: "$data"');
        });

        if (mounted) {
          setState(() {
            // We loaded the songs.
          });
        }
      } finally {
        cursor.close();
      }
    }
  }

Note that I also tried the content URI without the /some_uri at the end.

When trying to read data in this manner, I got the following problem:

Exception has occurred.
PlatformException (PlatformException(ERROR, Method call failed, java.lang.SecurityException: Failed to find provider null for user 0; expected to find a valid ContentProvider for this authority
	at android.os.Parcel.createExceptionOrNull(Parcel.java:3011)
	at android.os.Parcel.createException(Parcel.java:2995)
	at android.os.Parcel.readException(Parcel.java:2978)
	at android.os.Parcel.readException(Parcel.java:2920)
	at android.content.IContentService$Stub$Proxy.registerContentObserver(IContentService.java:1032)
	at android.content.ContentResolver.registerContentObserver(ContentResolver.java:2712)
	at android.database.AbstractCursor.setNotificationUris(AbstractCursor.java:453)
	at android.database.AbstractCursor.setNotificationUris(AbstractCursor.java:428)
	at com.nt4f04und.android_content_provider.AndroidContentProvider.matrixCursorFromMap(AndroidContentProvider.kt:405)
	at com.nt4f04und.android_content_provider.AndroidContentProvider.query(AndroidContentProvider.kt:468)
	at android.content.ContentProvider$Transport.query(ContentProvider.java:285)
	at android.content.ContentResolver.query(ContentResolver.java:1219)
	at android.content.ContentResolver.query(ContentResolver.java:1151)
	at android.content.ContentResolver.query(ContentResolver.java:1107)
	at com.nt4f04und.android_content_provider.AndroidContentResolver.onMethodCall(AndroidContentResolver.kt:175)
	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:322)
	at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$2j2MERcK825A5j1fv5sZ7xB2Iuo.run(Unknown Source:12)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)

....now I feel stuck. Can you help?

unable to get actual path of the file

Hello Dear Developer, first of All thanks for develop such a great package. But it just give us the content path. How can we get the exist file, to perform different operations over it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.