在Android上将应用程序杀死后,我似乎无法收到从FCM控制台发送的FCM推送通知,就像长按“概述”按钮并滑动要杀死的应用程序一样。当应用程序在前台或后台运行时,它绝对可以正常工作。这似乎是一个重复的问题,但是我尝试了其他方法,但似乎还是无法解决。
NotificationService.java
public class NotificationService extends FirebaseMessagingService
{
private static final String TAG = "FCM Service";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
sendNotification(remoteMessage.getNotification().getBody());
}
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
android.support.v4.app.NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Firebase")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}
Run Code Online (Sandbox Code Playgroud)
令牌刷新.java
public …Run Code Online (Sandbox Code Playgroud) 我正在从 JSON 数组中提取数据并从中创建对象,并在我使用for循环创建的对象中从数组中设置我需要的字符串值:
var gamesList = [];
gamesList = this.props.navigation.state.params.gamesList;
var gameIconList = [];
for(var i=0;i<3;i++){
var provider = gamesList[i].provider;
var gameId = gamesList[i].gameId.toString();
gameIconList.push(
<TouchableOpacity onPress={(provider,gameId) => this.launchGame(provider,gameId)}>
<ResponsiveImage source={{uri: gamesList[i].imageUrl}}
initWidth="200" initHeight="120" defaultSource={require('./splash-tile2.png')} />
</TouchableOpacity>
);
}
Run Code Online (Sandbox Code Playgroud)
这一切都发生在render()函数中,{gameIconList}将在return()函数中调用,如下所示:
return(
<ScrollView horizontal={true}>
{gameIconList}
</ScrollView>
);
Run Code Online (Sandbox Code Playgroud)
如您所见,我通过循环将字符串值设置到 onPress 函数调用中,当我单击图像中的图像时,TouchableOpacity我希望将设置的字符串值发送回上面的函数,即:
launchGame = (provider, gameId) => {
params = {
Provider: provider.nativeEvent.text,
Platform: this.state.Platform,
Environment: this.state.Environment,
GameId: gameId,
IsDemo: this.state.IsDemo
};
request …Run Code Online (Sandbox Code Playgroud)