代码应该允许用户发送消息,消息应该存储在firebase数据库中,但我得到一个firebase警告,并且没有任何内容添加到数据库中。 我在代码中有一个身份验证部分,它的工作非常正常,所以我想知道可能出现什么问题。
编辑:我之前已经尝试过这个答案: https://stackoverflow.com/a/39480273/7310034
火力警告警告:
E/FA: AppMeasurementReceiver not registered/enabled
E/FA: AppMeasurementService not registered/enabled
E/FA: Uploading is not possible. App measurement disabled
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.firebase.udacity.friendlychat">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<service
android:name="com.google.android.gms.measurement.AppMeasurementService"
android:enabled="true"
android:exported="false" />
<receiver
android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
android:enabled="true">
<intent-filter>
<action android:name="com.google.android.gms.measurement.UPLOAD" />
<action android:name="com.android.vending.INSTALL_REFERRER"/>
</intent-filter>
</receiver>
<activity android:name="com.google.firebase.udacity.friendlychat.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
涉及的MainActivity代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mUsername = ANONYMOUS;
mFirebaseDatabase = FirebaseDatabase.getInstance();
mFirebaseAuth = FirebaseAuth.getInstance();
mFirebaseStorage = FirebaseStorage.getInstance();
mMessagesDatabaseReference = mFirebaseDatabase.getReference().child("messages");
mChatPhotoStorageReference = mFirebaseStorage.getReference().child("chat_photos");
// Initialize references to views
mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
mMessageListView = (ListView) findViewById(R.id.messageListView);
mPhotoPickerButton = (ImageButton) findViewById(R.id.photoPickerButton);
mMessageEditText = (EditText) findViewById(R.id.messageEditText);
mSendButton = (Button) findViewById(R.id.sendButton);
// Initialize message ListView and its adapter
List<FriendlyMessage> friendlyMessages = new ArrayList<>();
mMessageAdapter = new MessageAdapter(this, R.layout.item_message, friendlyMessages);
mMessageListView.setAdapter(mMessageAdapter);
// Initialize progress bar
mProgressBar.setVisibility(ProgressBar.INVISIBLE);
// Send button sends a message and clears the EditText
mSendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.e("I am on click ","and adding a ten");
// This object has all the keys that we’ll store as a message in the realtime database.
FriendlyMessage friendlyMessage = new FriendlyMessage(mMessageEditText.getText().toString(), mUsername, null);
Log.e("I am on click ","and adding a 999999");
mMessagesDatabaseReference.push().setValue(friendlyMessage);
Log.e(String.valueOf(friendlyMessage)," Surprise! ");
// Clear input box
mMessageEditText.setText("");
}
});