0

我使用 react-native-push-notification localNotification 方法。但是android和ios都没有发生任何事情。我链接库。在 android logcat 输出中,我看到以下输出:

11-25 18:46:38.373 618 735 E RNPushNotification: failed to send push notification
11-25 18:46:38.373 618 735 E RNPushNotification: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.ComponentName android.content.Intent.getComponent()' on a null object reference
11-25 18:46:38.373 618 735 E RNPushNotification: at com.dieam.reactnativepushnotification.modules.RNPushNotificationHelper.getMainActivityClass(RNPushNotificationHelper.java:56)
11-25 18:46:38.373 618 735 E RNPushNotification: at com.dieam.reactnativepushnotification.modules.RNPushNotificationHelper.sendToNotificationCentre(RNPushNotificationHelper.java:137)
11-25 18:46:38.373 618 735 E RNPushNotification: at com.dieam.reactnativepushnotification.modules.RNPushNotification.presentLocalNotification(RNPushNotification.java:156)

项目的gradle设置是:

buildToolsVersion = "27.0.3"
minSdkVersion = 19
compileSdkVersion = 27
targetSdkVersion = 27
supportLibVersion = "27.1.1"

这是我的代码。我在反应 App 组件之前在 App.js 中使用 configure 方法。

export const configure = ()=>{

  PushNotification.configure({

    onRegister: function(token) {
      console.log( 'TOKEN:', token );
    },
    onNotification: function(notification) {
      console.log( 'NOTIFICATION');
    },

    permissions: {
      alert: true,
      badge: true,
      sound: true
    },

    popInitialNotification: true,
    requestPermissions: true,
  });


}


export const localNotification = (title="",bigText="" )=>{

  PushNotification.localNotification({

    title:title,
    message: bigText,
    playSound: true,
    soundName: 'default',


  });

}

这是我的 AndroidManifest.xml

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

 .....
  .....


  <uses-permission android:name="android.permission.GET_TASKS" />                       <!-- <- Add this line -->
  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>           <!-- <- Add this line -->
  <uses-permission android:name="android.permission.VIBRATE"/>

  <application
    android:name=".MainApplication"
    android:label="@string/app_name"
    android:icon="@mipmap/ic_launcher"
    android:allowBackup="false"
    android:theme="@style/AppTheme">

    <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_name"
                android:value="xchannel"/>
    <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_description"
                android:value="YOUR NOTIFICATION CHANNEL DESCRIPTION"/>
    <!-- Change the resource name to your App's accent color - or any other color you want -->
    <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
                android:resource="@android:color/white"/>


    <activity
      android:name=".MainActivity"
      android:label="@string/app_name"
      android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
      android:windowSoftInputMode="adjustResize">


      <intent-filter>
        <action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />

        <!-- enable deep linking -->
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <!-- for example pay://herfehplus !-->
        <data android:scheme="pay"
              android:host="payhost"
        />


      </intent-filter>
    </activity>


    <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
  </application>

</manifest>
4

0 回答 0