【发布时间】:2019-08-20 08:44:34
【问题描述】:
我正在制作一个可以在单击按钮时写入 firebase 数据库的应用程序。 该应用程序正在模拟器上运行,但它不适用于我的物理设备。 该应用程序上周运行良好,但今天开始出错。 这是主要的活动代码:
public class MainActivity extends AppCompatActivity {
private Firebase fled1;
Button on;
Button off;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
on= findViewById(R.id.on);
off= findViewById(R.id.off);
on.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DatabaseReference fled1 = FirebaseDatabase.getInstance().getReferenceFromUrl("https://testproject-tb.firebaseio.com/");
DatabaseReference fled1Child = fled1.child("Button1");
fled1Child.setValue("1");
}
});
off.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DatabaseReference fled1 = FirebaseDatabase.getInstance().getReferenceFromUrl("https://testproject-tb.firebaseio.com/");
DatabaseReference fled1Child = fled1.child("Button1");
fled1Child.setValue("0");
}
});
}
这是我的清单文件,我添加了所有所需的权限:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lalitahuja.iotbutton">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.example.lalitahuja.iotbutton.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
这是构建 Gradle 文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.lalitahuja.iotbutton"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-database:16.1.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.7'
implementation 'com.google.firebase:firebase-auth:16.2.0'
implementation 'com.firebase:firebase-client-android:2.5.2'
}
apply plugin: 'com.google.gms.google-services'
我得到的错误:
E/FirebaseInstanceId:令牌检索失败:SERVICE_NOT_AVAILABLE
编辑:我尝试了互联网上现有的解决方案,但没有一个有效。
【问题讨论】:
-
您的物理设备型号是什么?是否已登录 google play 服务?
-
我有 3 台不同的小米设备 Mi Redmi 3s、Mi A1、Mi Note 4 所有设备都使用不同的帐户登录 google play 服务。上周该应用在所有设备上都运行良好,但今天我在所有设备上都遇到了同样的错误。
-
呃哦,我刚刚看到另一个用户提出的另一个关于这个问题的问题。听起来像是 Firebase 服务中断
-
但是在 Firebase 状态页面上没有提到实时数据库的中断,你可以在这个链接上查看 status.firebase.google.com
-
那么还有什么问题 - 您是否误删除了身份验证密钥?
标签: android firebase firebase-realtime-database