Firebase数据库未从Firebase数据库参考中获取数据

WebRoose开发:

一切工作正常,但DatabaseReference并未获取数据,这就像只是在忽略我的代码来运行,并且好像我的互联网无法正常工作一样,请帮助我在以下社区中加入我的代码和图像。

以前它可以正常工作,但是由于我只是更改了一些代码以仅使currentVersion> = vCode,所以即使数据库中的值小于<currentVersion,用户也可以继续,但是在构建它之后,我的应用程序未从Firebase提取数据,因此我尝试了要卸载它,请从Play商店再次安装较旧的版本,因为它也无法获取数据,请提供帮助。我不知道我做错了什么。因此,我计划安装ParrotOS,这样也许可以工作,但是最好先咨询专家

Firebase数据库映像

MainActivity.java

public class MainActivity extends AppCompatActivity {
    TextView appName;
    FirebaseUser firebaseUser;
    String currentVersionName;
    long currentVersionCode;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        appName = findViewById(R.id.appName);
        currentVersionName = BuildConfig.VERSION_NAME;
        currentVersionCode = BuildConfig.VERSION_CODE;
        animateAppName();
        netConn();
        FirebaseAuth.getInstance();

    }

    public void applyScreenChange(){
        String sharedPerfId = "MyAppPref";
        SharedPreferences sharedPreferences = getSharedPreferences(sharedPerfId,0);
        boolean isAdvertiserLoggedIn = sharedPreferences.getBoolean("isAdvertiserLoggedIn",false);
        boolean isCreatorLoggedIn = sharedPreferences.getBoolean("isCreatorLoggedIn",false);
        if (isAdvertiserLoggedIn){
            skipSetupToAdvertiser();
        }
        else if (isCreatorLoggedIn){
            skipSetupToCreator();
        }
        else {
            newActivity();
        }
    }

    public void animateAppName(){
        appName.setTranslationY(-1000f);
        appName.animate().translationYBy(1000f).setDuration(500);
    }

    public void netConn(){
        ConnectivityManager connectivityManager = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
        assert connectivityManager != null;
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        if(networkInfo == null || !networkInfo.isConnected() || !networkInfo.isAvailable()){
            AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
            alertDialog.setTitle("No Internet Connection");
            alertDialog.setMessage("Connect to Network and Then try again");
            alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Exit", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    MainActivity.super.onBackPressed();
                }
            });
            alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Retry", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    netConn();
                }
            });
            alertDialog.setCanceledOnTouchOutside(false);
            alertDialog.show();

        }else {

//            Check older version

//            applyScreenChange();


            DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("Version");
            databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot snapshot) {
                    String vName = (String) snapshot.child("latestVersionName").getValue();
                    long vCode = (long) snapshot.child("latestVersionCode").getValue();
                    if (currentVersionName.equals(vName) && currentVersionCode >= vCode){
                        applyScreenChange();

                        // TODO: 16-08-2020 add condition to open app if version is higher
                    }else {
                        Toast.makeText(MainActivity.this, "Old Version", Toast.LENGTH_SHORT).show();
                        AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
                        alertDialog.setTitle("You're on Older Version");
                        alertDialog.setMessage("This Version is no more supported, Kindly update your App to Continue");
                        alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Exit", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                MainActivity.super.onBackPressed();
                            }
                        });
                        alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Update", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
//                                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.app_link))));
                                Toast.makeText(MainActivity.this, "Kindly Search Sponso on PlayStore and Update", Toast.LENGTH_SHORT).show();
                                finish();
                            }
                        });
                        alertDialog.setCanceledOnTouchOutside(false);
                        alertDialog.show();
                    }
                }

                @Override
                public void onCancelled(@NonNull DatabaseError error) {

                }
            });
        }
    }

    public void newActivity(){
                Intent intent = new Intent(MainActivity.this, AdvertiserCreatorChooser.class);
                startActivity(intent);
                finish();
    }


    public void skipSetupToAdvertiser(){
        firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
        if (firebaseUser!=null) {
                    Intent intent = new Intent(MainActivity.this, AdvertiserHome.class);
                    startActivity(intent);
                    finish();
        }else{
                    Intent intent = new Intent(MainActivity.this, AdvertiserLoginRegister.class);
                    startActivity(intent);
                    finish();
        }
    }

    public void skipSetupToCreator(){
        firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
        if (firebaseUser!=null) {
                    Intent intent = new Intent(MainActivity.this, CreatorHome.class);
                    startActivity(intent);
                    finish();
        }else {
                    Intent intent = new Intent(MainActivity.this, CreatorLoginRegister.class);
                    startActivity(intent);
                    finish();
        }
    }
}

manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.webroose.sponso">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

    <application
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:allowBackup="true"
        android:theme="@style/AppTheme">
        <activity android:name=".Advertiser.AdvertiserCampaignUpdate"/>
        <activity android:name=".Advertiser.ui.main.AdvertiserSettings" />
        <activity android:name=".Creator.CreatorRecentlyChat" />
        <activity android:name=".Advertiser.AdvertiserRecentlyChat" />
        <activity android:name=".Advertiser.AdvertiserChatActivity" />
        <activity android:name=".Creator.CreatorChatActivity" />

        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="@string/app_id" />

        <activity android:name=".Creator.CreatorUserDetails" />
        <activity android:name=".Creator.CreatorList" />
        <activity android:name=".Common.AboutUs" />
        <activity
            android:name=".AdvertiserHome"
            android:label="@string/title_activity_advertiser_home"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".Advertiser.AdvertiserLoginRegister"
            android:label="@string/title_activity_advertiser_login_register"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity android:name=".Common.PrivacyPolicy" />
        <activity android:name=".Common.ChangePassword" />
        <activity android:name=".Creator.CreatorSettings" />
        <activity android:name=".Common.ChangeEmail" />
        <activity android:name=".Advertiser.AdvertiserUserDetails" />
        <activity android:name=".Advertiser.AdvertiserList" />
        <activity
            android:name=".CreatorHome"
            android:label="@string/title_activity_creator_home"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".Creator.CreatorLoginRegister"
            android:label="@string/title_activity_creator_login_register"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity android:name=".AdvertiserCreatorChooser" />
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <meta-data
            android:name="preloaded_fonts"
            android:resource="@array/preloaded_fonts" />
    </application>

</manifest>

依赖

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
    implementation 'com.google.android.material:material:1.2.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'com.google.firebase:firebase-database:19.4.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.navigation:navigation-fragment:2.3.0'
    implementation 'androidx.navigation:navigation-ui:2.3.0'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation 'com.google.firebase:firebase-auth:19.3.2'
    implementation 'com.google.firebase:firebase-database:19.4.0'
    implementation 'com.firebaseui:firebase-ui-database:6.2.0'
    implementation 'com.google.android.gms:play-services-ads:19.3.0'
    implementation 'com.android.support:multidex:2.0.0'
    implementation 'com.google.firebase:firebase-analytics:17.5.0'
    implementation 'com.google.firebase:firebase-messaging:20.2.4'
    implementation 'com.facebook.android:audience-network-sdk:5.10.1'
}
WebRoose开发:

而实际的问题是Firebase数据库

用firebase数据库检查下图

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章