** Приложение работает нормально, когда приложение BackGround и Foreground. Мы не получим действие, когда приложение будет убито **
Я новичок в реакции-нативной, может впервые реализовать уведомление о sh в android.
this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen: NotificationOpen) => {
console.log('notificationOpenedListener');
}
);
Android Файл манифеста
Это теги xml, которые добавляются согласно RNfirebase.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.ISEASUser">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/app_launcher"
android:roundIcon="@mipmap/app_launcher"
android:allowBackup="false"
android:usesCleartextTraffic="true"
tools:targetApi="28"
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".Splash"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:exported="true"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<meta-data
android:name="io.fabric.ApiKey"
android:value="6980976bb2301e19b62096ef7ef5c36cb41e64a6" />
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />
<!-- Scheduled Notifications (Optional) -->
<receiver android:name="io.invertase.firebase.notifications.RNFirebaseNotificationReceiver"/>
<receiver android:enabled="true" android:exported="true" android:name="io.invertase.firebase.notifications.RNFirebaseNotificationsRebootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
Spla sh Экран Обработка намерений в Spla sh Экран
import android.os.Bundle;
import android.os.Handler;
import android.content.Intent;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
public class Splash extends AppCompatActivity {
private static final String TAG = "Splash";
private Handler handler = new Handler();
private Runnable runnable = new Runnable() {
@Override
public void run() {
Intent in=new Intent(Splash.this,MainActivity.class);
Bundle extras = getIntent().getExtras();
Log.d(TAG , "extrasrun: "+extras.toString());
if(extras != null){
in.putExtras(extras);
}
startActivity(in);
finish();
}
};
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.d(TAG, "intentrun: "+intent.toString());
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
}
@Override
protected void onResume() {
super.onResume();
handler.postDelayed(runnable, 5000);
}
@Override
protected void onPause() {
super.onPause();
handler.removeCallbacks(runnable);
}
}
Приложение. js createNotification = asyn c (Navigator) => {
this._checkPermission()
//Creating Notification in Foreground
const channel = new firebase.notifications.Android.Channel(
'com.iseas',
'Iseas',
firebase.notifications.Android.Importance.Max
).setDescription('Iseas User Channel Discription');
firebase.notifications().android.createChannel(channel);
this.unsubscribeFromNotificationListener = firebase.notifications().onNotification((notification) => {
if (Platform.OS === 'android') {
const localNotification = new firebase.notifications.Notification({
sound: 'default',
show_in_foreground: true,
show_in_background: true,
})
.setTitle(notification.title)
.setBody(notification.body)
.setData(notification.data)
.android.setChannelId('com.iseas') // e.g. the id you chose above
.android.setSmallIcon('app_launcher') // create this icon in Android Studio
.android.setColor('#000000') // you can set a color here
.android.setPriority(firebase.notifications.Android.Priority.High);
firebase.notifications()
.displayNotification(localNotification)
.catch(err => console.error(err));
} else if (Platform.OS === 'ios') {
console.log('Platform.OS', 'Reached')
const localNotification = new firebase.notifications.Notification()
.setTitle(notification.title)
.setBody(notification.body)
.setData(notification.data)
.ios.setBadge(notification.ios.badge);
firebase.notifications()
.displayNotification(localNotification)
.catch(err => console.error(err));
}
});
this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification: Notification) => {
alert('onNotificationDisplayed')
});
const getInitialNotification = await firebase.notifications().getInitialNotification((notification)=>{
alert("getInitialNotification")
});
if(getInitialNotification){
alert("If Condition"+JSON.stringify(getInitialNotification.notification.data))
}
this.notificationOpenedListener = await firebase.notifications().onNotificationOpened((notificationOpen) => {
alert('notificationOpenedListener');
});
}