迁移到Firebase Cloud Messaging后.当打开我的应用程序时,它会崩溃并抛出错误,说java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist.我已经放入了我的新google-services.json并更新了我的SDK.
这是我的MainActivity
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Check Google play service
GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
int resultCode = googleAPI.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this,
PLAY_SERVICES_RESOLUTION_REQUEST).show();
} else {
Log.e(LOG_TAG, "This device is not supported.");
finish();
}
}
Log.i(TAG, "InstanceID token: " + FirebaseInstanceId.getInstance().getToken());
}
}
Run Code Online (Sandbox Code Playgroud) 在我MainActivity的日志中,我可以看到使用的令牌FirebaseInstanceId.getInstance().getToken(),它显示生成的令牌.但似乎在我 MyFirebaseInstanceIDService扩展到的地方FirebaseInstanceIdService,onTokenRefresh()没有被调用,在这个函数中,据说令牌最初是在这里生成的.我需要打电话给我,sendRegistrationToServer()这就是为什么我想知道它为什么不进入的原因onTokenRefresh().
这是我的代码
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
sendRegistrationToServer(refreshedToken);
}
}
Run Code Online (Sandbox Code Playgroud) android firebase firebase-cloud-messaging firebase-notifications
迁移到Firebase后,我测试了使用firebase控制台发送通知它工作正常,但我需要在特定时间发送每日通知,因此我不使用firebase控制台而是使用我以前的cron作业每天发送通知.我改变了https://android.googleapis.com/gcm/send对https://fcm.googleapis.com/fcm/send,但我的设备没有收到任何通知.
有什么方法可以解决这个问题吗?或者我错过了什么?我的cron工作对我仍在使用GCM的设备工作正常.
这是我的代码
function sendNotificationFCM($apiKey, $registrationIDs, $messageText,$id) {
$headers = array(
'Content-Type:application/json',
'Authorization:key=' . $apiKey
);
$message = array(
'registration_ids' => $registrationIDs,
'data' => array(
"message" => $messageText,
"id" => $id,
),
);
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => 'https://fcm.googleapis.com/fcm/send',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => json_encode($message)
));
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
Run Code Online (Sandbox Code Playgroud)
}
cron android firebase google-cloud-messaging firebase-cloud-messaging
在我ListProvider实现的类中,RemoteViewsFactory我已经在下面编写了以下代码:
@Override
public RemoteViews getViewAt(int position) {
RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.list_row);
rv.setTextViewText(R.id.heading, merch_name);
rv.setTextViewText(R.id.content, teaser);
Bundle extras = new Bundle();
extras.putInt(WidgetProvider.EXTRA_ITEM, position);
extras.putString(WidgetProvider.MERCHANT_ITEM, mWidgetItems.get(position).merchant_id);
Intent fillInIntent = new Intent();
fillInIntent.putExtras(extras);
rv.setOnClickFillInIntent(R.id.llRow, fillInIntent);
return rv;
}
Run Code Online (Sandbox Code Playgroud)
当我点击时,我把Logs in my onReceiveof WidgetProviderit中有正确的ID,但是在打开活动后它没有正确的ID放在哪里extras.还有时间,它没有打开Activity我提供的,只是打开我的MainActivity.当我从中删除我的应用程序recently open app然后使用时,会发生这种情况widget.
这里是我的代码onReceive在我WidgetProvider
public class WidgetProvider extends AppWidgetProvider {
public static final String TOAST_ACTION = "my.packagename.TOAST_ACTION";
public static final …Run Code Online (Sandbox Code Playgroud) 在Firebase控制台中,我们可以设置特定的时间和日期,以便何时推送通知.但有没有办法我们可以每天设置它?例如,它会在每周一,周三和周五或每天发送?
我在我的应用程序中实施了Firebase Cloud Messaging,在使用Firebase控制台时,Android和iOS中的应用程序收到了我的通知.但是因为我想每天推送通知,所以我在服务器端创建了一个cron作业.我注意到每次触发我的cron时我的应用程序崩溃了
在我的iOS客户端中,它不会收到任何通知.
在我的Android客户端,它显示一个错误:
java.lang.String com.google.firebase.messaging.RemoteMessage$Notification.getBody()' on a null object reference
在我FirebaseMessagingService这里的地方是我的代码
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@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());
}
Run Code Online (Sandbox Code Playgroud)
在我的服务器端
function sendNotificationFCM($apiKey, $registrationIDs, $messageText,$id) {
$headers = array(
'Content-Type:application/json',
'Authorization:key=' . $apiKey
);
$message = array(
'registration_ids' => $registrationIDs,
'data' => array(
"message" => $messageText,
"id" => $id,
),
);
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => 'https://fcm.googleapis.com/fcm/send', …Run Code Online (Sandbox Code Playgroud) 我是新手ReactNative,我收到了错误undefined is not a object,我this.state.rows试图View在用户点击时动态添加Button.我尝试使用这个,而不是使用getInitialState我使用constructor(props)但我继续有上述错误.这是我的代码
constructor(props) {
super(props);
this.state = {
rows: [],
};
}
addRow(){
this.state.rows.push(index++)
this.setState({ rows: this.state.rows })
}
render(){
let contactView = () => {
return <View>
<AddComponent />
</View>
}
return(
<View>
<View>
{contactView}
</View>
<TouchableHighlight onPress={ this.addRow } >
<Text>Add</Text>
</TouchableHighlight>
</View>
);
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助!
我迁移到Firebase Cloud Messaging,当初次尝试发送消息时,我使用Firebase中的控制台接收到通知,然后尝试在几分钟后发送另一个通知,但我不再收到另一个通知,但是在我的Firebase控制台中,它说是 Completed
更新
这是我的代码
主要活动
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
checkPlayServices();
Log.i(TAG, "InstanceID token: " + FirebaseInstanceId.getInstance().getToken());
}
....
}
Run Code Online (Sandbox Code Playgroud)
MyFirebaseInstanceIDService
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
sendRegistrationToServer(refreshedToken);
}
}
Run Code Online (Sandbox Code Playgroud)
MyFirebaseMessagingService
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
// [START receive_message]
@Override
public …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用cron作业发送通知.我从GCM迁移到FCM.在我的服务器端,我改变了https://android.googleapis.com/gcm/send to https://fcm.googleapis.com/fcm/send,也更新了如何请求数据变化registration_ids来to.检查json传递它是一个有效的json但我有一个错误Field "to" must be a JSON string.反正有没有解决这个问题?
这是我的代码
function sendNotificationFCM($apiKey, $registrationIDs, $messageText,$id) {
$headers = array(
'Content-Type:application/json',
'Authorization:key=' . $apiKey
);
$message = array(
'to' => $registrationIDs,
'data' => array(
"message" => $messageText,
"id" => $id,
),
);
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => 'https://fcm.googleapis.com/fcm/send',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => json_encode($message)
));
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
Run Code Online (Sandbox Code Playgroud) 我已经搜索了几个星期,但我找不到答案。我正在尝试ListView在widget. 我设法填充了ListView. 我的问题是当我点击里面的一个项目时,ListView我想打开一个Activity并将Id该项目的传递给Activity我调用的。但似乎我无法Id正确传递它,它总是null在去Activity我打电话的时候。
这是我的代码
小部件提供程序
public class WidgetProvider extends AppWidgetProvider {
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
....
for (int i = 0; i < N; ++i) {
RemoteViews remoteViews = updateWidgetListView(context,
appWidgetIds[i]);
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds[i], R.id.listViewWidget);
appWidgetManager.updateAppWidget(appWidgetIds[i], remoteViews);
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
private RemoteViews updateWidgetListView(Context context, int appWidgetId) {
//For ListView
Intent svcIntent = new Intent(context, WidgetService.class); …Run Code Online (Sandbox Code Playgroud) android ×10
firebase ×7
java ×2
listview ×2
widget ×2
cron ×1
javascript ×1
json ×1
php ×1
react-native ×1