Dev-hwang / flutter_foreground_task

This plugin is used to implement a foreground service on the Android platform.
https://pub.dev/packages/flutter_foreground_task
MIT License
140 stars 105 forks source link

Issue with Getting Notification Permission #176

Closed SyedKaz00 closed 1 month ago

SyedKaz00 commented 10 months ago

I have followed the example and the instructions in the readme, however there is a recurring issue to do with getting the notification permission.

E/SurfaceSyncer(26831): Failed to find sync for id=0 W/Parcel (26831): Expecting binder but got null! D/CompatibilityChangeReporter(26831): Compat change id reported: 78294732; UID 10162; state: DISABLED E/flutter (26831): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(NOTIFICATION_PERMISSION_REQUEST_CANCELLED, The dialog was closed or the request was canceled during a runtime notification permission request., null, null) E/flutter (26831): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7) E/flutter (26831): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:296:18) E/flutter (26831): <asynchronous suspension> E/flutter (26831): #2 MethodChannelFlutterForegroundTask.requestNotificationPermission (package:flutter_foreground_task/flutter_foreground_task_method_channel.dart:245:11) E/flutter (26831): <asynchronous suspension> E/flutter (26831): #3 _MyHomePageState._requestPermissionForAndroid (package:whispr/main.dart:129:7) E/flutter (26831): <asynchronous suspension> E/flutter (26831): #4 _MyHomePageState.initState.<anonymous closure> (package:whispr/main.dart:188:7) E/flutter (26831): <asynchronous suspension> E/flutter (26831): This is what my androidManifest looks like `<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.dti.whispr">

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

<application
    android:label="whispr"
    android:name="${applicationName}"
    android:icon="@mipmap/ic_launcher">
    <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>
   <service
       android:name="com.pravera.flutter_foreground_task.service.ForegroundService"/>
    <!-- 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>

` The same issue is also occurring when I copy the entire main.dart file from the example. Anyone face this issue, as it seem to do with the android code once it passes the MethodChannel

zhaoxu666 commented 7 months ago

I have a same issue, but when I targetSdkVersion update 33, it`s worked。

Dev-hwang commented 1 month ago

@SyedKaz00 @zhaoxu666

Does the same problem occur in the latest version?