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

firebase - AngularFireMessaging requestPermission not functioning only on android cordova app - Stack Overflow

programmeradmin0浏览0评论

I am working on an ionic cordova application, I have implemented the @angular/fire/compat/messaging plugin

I have the following code

requestPermission() {
console.log('requestPermission()');
this.afMessaging.requestPermission
  .subscribe(
    {
      next: (v) => console.log(v),
      error: (e) => console.error(e),
      complete: () => console.info('complete')
    }
  );

}

when I run the app using ionic serve this code works fine, it hits the next observable and grants permission however when i compile the app into an apk and run it on android. it dose not succeed, it only logs the "complete" message. and dose not throw an error or hit the next observable with a denied or a granted. It simply dose nothing.

when you go into app permissions you can go enable notifications manually however this dose not change the result. the same happens with all the afMessaging functions like getToken or requestToken

the firebase-messaging-sw.js is being regestered on mobile successfully and i assume everthing else is setup correctly as it works on browser.

my AndroidManifest.xml file is also as follows:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" xmlns:android=";>
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:networkSecurityConfig="@xml/network_security_config" android:supportsRtl="true">
    <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:exported="true" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@style/Theme.App.SplashScreen" android:windowSoftInputMode="adjustResize">
        <intent-filter android:label="@string/launcher_name">
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <provider android:authorities="${applicationId}.cdv.core.file.provider" android:exported="false" android:grantUriPermissions="true" android:name="androidx.core.content.FileProvider">
        <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/cdv_core_file_provider_paths" />
    </provider>
    <service android:exported="false" android:name="by.chemerisuk.cordova.firebase.FirebaseMessagingPluginService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
    <meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="default" />
</application>
<queries>
    <intent>
        <action android:name="android.media.action.IMAGE_CAPTURE" />
    </intent>
</queries>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
发布评论

评论列表(0)

  1. 暂无评论