当更改为targetSdkVersion 28

时间:2020-05-26 16:51:06

标签: android flutter firebase-cloud-messaging android-push-notification

当我将targetSdkVersion设置为25时,我的Flutter App中有一个针对FCM的自定义通知声音,它可以正常工作,但是一旦将targetSdkVersion更改为28,就会播放默认声音。

我正在使用插件firebase_messaging 6.0.9

这是我的AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="*********">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>


    <application

        android:name=".Application"
        android:label="*****"
        android:icon="@mipmap/ic_launcher">

        <meta-data android:name="com.google.android.geo.API_KEY"
                   android:value="*********"/>
        <meta-data
                android:name="com.google.firebase.messaging.default_notification_icon"
                android:resource="@mipmap/ic_notification" 
                />

        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">

            <meta-data
                android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

    </application>

</manifest>


这是我的有效载荷:

    public function toFcm($notifiable)
    {
        $message = new FcmMessage();
        $notification = [
            'title'        => "Nouvelle commande #".$this->order->id." pour ".$this->order->foodOrders[0]->food->restaurant->name,
            'body'         => $this->order->user->name,
            'icon'         => $this->order->foodOrders[0]->food->restaurant->getFirstMediaUrl('image', 'thumb'),
            'sound'        => 'sale.wav', // Optional 
            'click_action' => "FLUTTER_NOTIFICATION_CLICK",
            'id' => '1',
            'status' => 'done',

        ];
        $message->content($notification)->data($notification)->priority(FcmMessage::PRIORITY_HIGH);

        return $message;
    }

我不确定我缺少什么,谢谢您的帮助!

0 个答案:

没有答案