'What steps to take to verify my Android Firebase app is on the cloud

I'm a newbie to the firebase cloud process. I have a commercial a security camera to view my house that I can view on my phone many miles from my home. Getting into IoT, I developed an Android app to turn a porch light on or off. My Android app works with my local internet but now I want to put it into the cloud so I can use it outside of my house internet. To check and see if the app is on the Firebase cloud? I use my security camera several miles away checking to see if OnOff app working on the cloud. As of now it is not working. What am doing wrong? I installed all the required code to for firebase. Sync works with id 'com.google.gms.google-services' and installed it on my phone. Here is my code. build.gradle(app) code

    plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
}


android {
    compileSdk 31

    defaultConfig {
        applicationId "com.example.newonoff"
        minSdk 23
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.6.0'
    implementation 'com.android.volley:volley:1.2.1'
    implementation platform('com.google.firebase:firebase-bom:30.0.0')
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.firebase:firebase-core:21.0.0'
    implementation 'com.google.firebase:firebase-firestore'
    implementation 'com.google.firebase:firebase-crashlytics-buildtools:2.8.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

build.gradle(newOnOff)

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.4"
        classpath 'com.google.gms:google-services:4.3.10'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

google-services.json

{
  "project_info": {
    "project_number": "582227243238",
    "project_id": "newonoff-30307",
    "storage_bucket": "newonoff-30307.appspot.com"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "1:582227243238:android:23cff0bf99b266c6ca0b27",
        "android_client_info": {
          "package_name": "com.example.newonoff"
        }
      },
      "oauth_client": [
        {
          "client_id": "582227243238-ue3ucjg31u00jgs6q32679qv6882a2fk.apps.googleusercontent.com",
          "client_type": 3
        }
      ],
      "api_key": [
        {
          "current_key": "AIzaSyCV7GpkxkEjDtTTA7Xera5RGG111KyIgrM"
        }
      ],
      "services": {
        "appinvite_service": {
          "other_platform_oauth_client": [
            {
              "client_id": "582227243238-ue3ucjg31u00jgs6q32679qv6882a2fk.apps.googleusercontent.com",
              "client_type": 3
            }
          ]
        }
      }
    }
  ],
  "configuration_version": "1"
}
```
Android Manifest code
```
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.newonoff">

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

    <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/Theme.NewOnOff">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
```
layout
```
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    
    <Button
        android:id="@+id/btn_ledOn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="60dp"
        android:layout_marginTop="50dp"
        android:layout_marginEnd="32dp"
        android:layout_marginBottom="493dp"
        android:onClick="buttonClick"
        android:text="ON"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/btn_ledOff"
        app:layout_constraintStart_toStartOf="parent" />

    <Button
        android:id="@+id/btn_ledOff"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="32dp"
        android:layout_marginTop="50dp"
        android:layout_marginEnd="36dp"
        android:layout_marginBottom="497dp"
        android:onClick="buttonClick"
        android:text="OFF"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/btn_ledOn"

        app:layout_constraintVertical_bias="1.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
```
Main Activity
```
package com.example.newonoff;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
//import com.android.volley.toolbox.HttpRequestTask;
import com.google.firebase.crashlytics.buildtools.reloc.org.apache.http.HttpResponse;
import com.google.firebase.crashlytics.buildtools.reloc.org.apache.http.client.ClientProtocolException;
import com.google.firebase.crashlytics.buildtools.reloc.org.apache.http.client.HttpClient;
import com.google.firebase.crashlytics.buildtools.reloc.org.apache.http.client.methods.HttpGet;
import com.google.firebase.crashlytics.buildtools.reloc.org.apache.http.impl.client.DefaultHttpClient;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;

public class MainActivity extends AppCompatActivity {
    final Context context = this;
    //private EditText ipAddress;
    private Button ledOn;
    private Button ledOff;
    String ipAddress="192.168.12.243";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //ipAddress = findViewById(R.id.edt_ip);
        ledOn = (Button) findViewById(R.id.btn_ledOn);
        ledOff = (Button) findViewById(R.id.btn_ledOff);
    }

    /**
     * When the button clicks this method executes
     **/
    public void buttonClick(View view) {
        String ledStatus;

        //if (ipAddress.getText().toString().equals(""))
            //Toast.makeText(MainActivity.this, "Please enter the ip address...", Toast.LENGTH_SHORT).show();

        //else {
            if (view == ledOn)
                ledStatus = "1";

            else
                ledStatus = "0";

            //Connect to default port number. Ex: http://IpAddress:80
           // String serverAdress = ipAddress.getText().toString() + ":" + "80";
            String serverAdress = ipAddress + ":" + "80";
            HttpRequestTask requestTask = new HttpRequestTask(serverAdress);
            requestTask.execute(ledStatus);

    }
    private class HttpRequestTask extends AsyncTask<String, Void, String> {

        private String serverAdress;
        private String serverResponse = "";
        private AlertDialog dialog;

        public HttpRequestTask(String serverAdress) {
            this.serverAdress = serverAdress;

            dialog = new AlertDialog.Builder(context)
                    .setTitle("HTTP Response from Ip Address:")
                    .setCancelable(true)
                    .create();
        }

        @Override
        protected String doInBackground(String... params) {
            dialog.setMessage("Data sent , waiting response from server...");

            /*if (!dialog.isShowing())
                dialog.show();*/

            String val = params[0];
            final String url = "http://" + serverAdress + "/led/" + val;

            try {
                HttpClient client = new DefaultHttpClient();
                HttpGet getRequest = new HttpGet();
                getRequest.setURI(new URI(url));
                HttpResponse response = client.execute(getRequest);

                InputStream inputStream = null;
                inputStream = response.getEntity().getContent();
                BufferedReader bufferedReader =
                        new BufferedReader(new InputStreamReader(inputStream));

                serverResponse = bufferedReader.readLine();
                inputStream.close();

            } catch (URISyntaxException e) {
                e.printStackTrace();
                serverResponse = e.getMessage();
            } catch (ClientProtocolException e) {
                e.printStackTrace();
                serverResponse = e.getMessage();
            } catch (IOException e) {
                e.printStackTrace();
                serverResponse = e.getMessage();
            }

            return serverResponse;
        }
        @Override
        protected void onPreExecute() {}
           /* dialog.setMessage("Sending data to server, please wait...");

            if (!dialog.isShowing())
                dialog.show();
        }*/
        @Override
        protected void onPostExecute(String s) {}
            /*dialog.setMessage(serverResponse);

            if (!dialog.isShowing())
                dialog.show();
        }*/


    }
}
```









    





Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source