最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

flutter - [Awesome Notifications]( 7347): Attempt to invoke virtual method 'java.lang.Object android.content.Context.get

programmeradmin1浏览0评论

how to solve this error while using flutter awesome notification package

E/Android: Awesome Notifications: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference (NotificationThread:58) D/SensorManager( 7347): sensorCTSV isCtsVerifier false E/flutter ( 7347): [ERROR:flutter/runtime/dart_vm_initializer(40)] Unhandled Exception: PlatformException(NOTIFICATION_THREAD_EXCEPTION, Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference, unexpectedError, null) E/flutter ( 7347): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:646:7) E/flutter ( 7347): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18) E/flutter ( 7347): E/flutter ( 7347): #2 MethodChannelAwesomeNotifications.createNotification (package:awesome_notifications/awesome_notifications_method_channel.dart:102:29) E/flutter ( 7347): E/flutter ( 7347): #3 NotificationPermissionCubit.triggerNotification (package:bintern/features/firebase_notifications/presentation/manager/notification_permissions_cubit/notification_permission_cubit.dart:69:5) E/flutter ( 7347): E/flutter ( 7347):

flutter doctor:-

[√] Flutter (Channel stable, 3.27.1, on Microsoft Windows [Version 10.0.17763.6775], locale
    en-IN)
    • Flutter version 3.27.1 on channel stable at C:\flutter
    • Upstream repository .git
    • Framework revision 17025dd882 (8 weeks ago), 2024-12-17 03:23:09 +0900
    • Engine revision cb4b5fff73
    • Dart version 3.6.0
    • DevTools version 2.40.2

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 36.0.0-rc3)
    • Android SDK at C:\Users\PRINCE\AppData\Local\Android\sdk
    • Platform android-35, build-tools 36.0.0-rc3
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 21.0.4+-12508038-b607.1)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.4.4)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.4.33213.308
    • Windows 10 SDK version 10.0.22000.0

[√] Android Studio (version 2024.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       
    • Dart plugin can be installed from:
       
    • Java version OpenJDK Runtime Environment (build 21.0.4+-12508038-b607.1)

[√] VS Code (version 1.96.4)
    • VS Code at C:\Users\PRINCE\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension can be installed from:
       .flutter

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.17763.6775]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 132.0.6834.160
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 132.0.2957.140

[√] Network resources
    • All expected network resources are available.

pubspec.yaml

  firebase_core: ^3.10.1
  firebase_analytics: ^11.4.1
  firebase_messaging: ^15.2.2
  awesome_notifications_fcm: ^0.10.0
  awesome_notifications: ^0.10.0
  awesome_notifications_core: ^0.10.0
  app_settings: ^5.2.0

andrid.manifest

<manifest xmlns:android=";>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <queries>
        <!-- If your app checks for call support -->
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="tel" />
        </intent>
        <!-- If your app checks for email support -->
        <intent>
            <action android:name="android.intent.action.SENDTO" />
            <data android:scheme="mailto" />
        </intent>
    </queries>
    <application
        android:label="app"
        android:name="${applicationName}"
        android:icon="@mipmap/launcher_icon">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

im trying to user flutter awesome notification to trigger notification.

My Notification Channel Code:

AwesomeNotifications().initialize(
    null,
    [
      NotificationChannel(
        channelKey: 'firebase_push_channel',
        channelName: 'Firebase-Push-Notification',
        channelDescription: 'To Show Firebase Push Notifications',
        playSound: true,
        criticalAlerts: true,
      ),
    ],
    debug: true,
  );

My Trigger Code:-

 void triggerNotification() async {
    await AwesomeNotifications().createNotification(
      content: NotificationContent(
        id: 10,
        channelKey: 'firebase_push_channel',
        title: 'Simple Notification',
        body: 'Simple Basic Demo Notification',
      ),
    );
  }

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论