在使用Android O及更高版本的RN应用程序上播放自定义声音时,我遇到了问题。
当targetSdkVersion为23时,一切都很好,因为增加到26,它在Oreo及更高版本上将不起作用。
要查看会发生什么,我在notification.build()
:Log.i(LOG_TAG, "Info: " + info)
在Android 7上,它显示:
12-11 11:07:14.466 9084 9345 I RNPushNotification: Info: Notification(pri=1 contentView=null vibrate=[0,300] sound=android.resource://br.com.getrak.gconnect/2131427328 defaults=0x4 flags=0x10 color=0xffff6600 category=call vis=PRIVATE)
在Android O上,它显示:
12-11 11:27:59.444 32608 32655 I RNPushNotification: Info: Notification(channel=rn-push-notification-channel-id pri=1 contentView=null vibrate=null sound=null defaults=0x4 flags=0x10 color=0xffff6600 category=call vis=PRIVATE)
我在AndroidManifest.xml上配置了一个频道,我的配置似乎与示例类似。
build.gradle:
ext {
buildToolsVersion = "27.0.3"
minSdkVersion = 21
compileSdkVersion = 26
targetSdkVersion = 26
supportLibVersion = "26.1.0"
googlePlayServicesVersion = "+"
}
Android Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com;.xxx.myapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name=".MainApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/AppTheme">
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name"
android:value="MyApp"/>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description"
android:value="MyApp Alerts"/>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService" />
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
</manifest>
我可能会缺少什么?