小编nat*_*iyu的帖子

名称为[DEFAULT]的FirebaseApp不存在

迁移到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)

java android firebase

71
推荐指数
5
解决办法
4万
查看次数

不调用Firebase onTokenRefresh()

在我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

69
推荐指数
5
解决办法
6万
查看次数

如何在服务器端实现firebase云消息传递?

迁移到Firebase后,我测试了使用firebase控制台发送通知它工作正常,但我需要在特定时间发送每日通知,因此我不使用firebase控制台而是使用我以前的cron作业每天发送通知.我改变了https://android.googleapis.com/gcm/sendhttps://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

11
推荐指数
2
解决办法
2万
查看次数

如何传递数据并从Widget中打开一个Activity?[Android]产品

在我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)

android listview widget

9
推荐指数
1
解决办法
1281
查看次数

使用Firebase云消息传递创建每日推送通知

在Firebase控制台中,我们可以设置特定的时间和日期,以便何时推送通知.但有没有办法我们可以每天设置它?例如,它会在每周一,周三和周五或每天发送?

java android firebase firebase-cloud-messaging

8
推荐指数
2
解决办法
4057
查看次数

remoteMessage.getNotification()中的错误.getBody()

我在我的应用程序中实施了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)

android firebase firebase-cloud-messaging

8
推荐指数
1
解决办法
1万
查看次数

Undefined不是this.state中的对象 - ReactNative

我是新手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)

谢谢您的帮助!

javascript android react-native

6
推荐指数
1
解决办法
5674
查看次数

我的设备未收到其他通知(FCM)

我迁移到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)

android firebase firebase-cloud-messaging

5
推荐指数
1
解决办法
1359
查看次数

字段"to"必须是JSON字符串[Firebase]

我正在尝试使用cron作业发送通知.我从GCM迁移到FCM.在我的服务器端,我改变了https://android.googleapis.com/gcm/send to https://fcm.googleapis.com/fcm/send,也更新了如何请求数据变化registration_idsto.检查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)

php android json firebase firebase-cloud-messaging

5
推荐指数
1
解决办法
8277
查看次数

处理 Widget ListView [Android] 中的项目点击

我已经搜索了几个星期,但我找不到答案。我正在尝试ListViewwidget. 我设法填充了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 listview widget

5
推荐指数
1
解决办法
2469
查看次数