Navigation

    Home
    All Categories
    • KEEN Trail Camera
    • Top #ReolinkCaptures Awards
    • Announcements and News
    • Wishlist
    • #ReolinkTrial
    • Discussion About Products
    • Reolink Captures
    • Reolink Client & APP
    #ReolinkTrial
    Reolink Captures
    Log in to post
    Guest
    • Guest
    • Register
    • Login

    Learn More

    Reolink Updates Learn More

    Meet Reolink at IFA 2025! Learn More

    Reolink Q&A Learn More

    Example code for actual doorbell call screen poping up on android

    Reolink Client & APP
    1
    1
    486
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • user_711725607157890_711725607157890
      user_711725607157890 last edited by

      @Reolink-Edificio-Castagna_969979572822233

      Reolink please implement this here is example code where app dosnt need to be ooen for doorbell call screen to pop up

      import android.Manifest;
      import android.content.pm.PackageManager;
      import android.os.Bundle;
      import android.util.Log;
      import android.view.View;
      import android.widget.Button;
      import android.widget.Toast;
      import androidx.appcompat.app.AppCompatActivity;
      import androidx.core.app.ActivityCompat;
      import androidx.core.content.ContextCompat;

      public class DoorbellCallActivity extends AppCompatActivity {
        private static final String TAG = "DoorbellCallActivity";
        private static final int PERMISSION_REQUEST_CODE = 100;

        private boolean isTwoWayAudioEnabled = false;
        private Button twoWayAudioButton;
        private Button recordButton;

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

          // Check for null after findViewById() is a critical safety measure.
          twoWayAudioButton = findViewById(R.id.btn_two_way_audio);
          recordButton = findViewById(R.id.btn_record);

          // Initialize video stream
          startVideoStream();

          if (twoWayAudioButton != null) {
            twoWayAudioButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                // Check permissions before toggling microphone
                if (checkAudioPermission()) {
                  toggleTwoWayAudio();
                } else {
                  requestAudioPermission();
                }
              }
            });
          } else {
            Log.e(TAG, "Button R.id.btn_two_way_audio not found in layout.");
          }


          if (recordButton != null) {
            recordButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                // Start recording only if permissions are granted
                if (checkStorageAndCameraPermissions()) {
                  startRecording();
                } else {
                  requestStorageAndCameraPermissions();
                }
              }
            });
          } else {
            Log.e(TAG, "Button R.id.btn_record not found in layout.");
          }
        }

        // --- Lifecycle Management (CRITICAL MISTAKE CORRECTION) ---

        @Override
        protected void onPause() {
          super.onPause();
          // Stop audio and video processing to save battery and resources
          stopVideoStream();
          if (isTwoWayAudioEnabled) {
            disableTwoWayAudio();
          }
          stopRecording(); // Stop recording if ongoing
        }

        @Override
        protected void onDestroy() {
          super.onDestroy();
          // Release any long-held resources or streaming clients here
          // (The stop methods will be called in onPause, but this is a final cleanup)
        }

        // --- Permission Handling (CRITICAL MISTAKE CORRECTION) ---

        private boolean checkAudioPermission() {
          return ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
        }

        private void requestAudioPermission() {
          ActivityCompat.requestPermissions(this,
              new String[]{Manifest.permission.RECORD_AUDIO},
              PERMISSION_REQUEST_CODE);
        }

        private boolean checkStorageAndCameraPermissions() {
          return ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED &&
              ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
        }

        private void requestStorageAndCameraPermissions() {
          ActivityCompat.requestPermissions(this,
              new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE},
              PERMISSION_REQUEST_CODE);
        }

        @Override
        public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
          super.onRequestPermissionsResult(requestCode, permissions, grantResults);
          if (requestCode == PERMISSION_REQUEST_CODE) {
            // Simple check: if at least one permission was granted
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
              // Permission granted, retry action or update UI
              Toast.makeText(this, "Permission granted. Try again.", Toast.LENGTH_SHORT).show();
            } else {
              Toast.makeText(this, "Permission denied. Audio/Recording functions unavailable.", Toast.LENGTH_LONG).show();
            }
          }
        }


        // --- Core Functionality ---

        private void startVideoStream() {
          Log.i(TAG, "Video stream initialized and started.");
          // Pseudo-code to initialize and display the live video feed
        }

        private void stopVideoStream() {
          Log.i(TAG, "Video stream stopped and resources released.");
          // Pseudo-code to stop and release video resources
        }

        private void toggleTwoWayAudio() {
          isTwoWayAudioEnabled = !isTwoWayAudioEnabled;
          if (isTwoWayAudioEnabled) {
            enableTwoWayAudio();
          } else {
            disableTwoWayAudio();
          }
          // Update the button text/icon to reflect the new state (UI update)
          if (twoWayAudioButton != null) {
            twoWayAudioButton.setText(isTwoWayAudioEnabled ? "Audio ON" : "Audio OFF");
          }
        }

        private void enableTwoWayAudio() {
          Log.i(TAG, "Two-way audio activated (microphone enabled).");
          // Activate microphone and allow two-way audio streaming
        }

        private void disableTwoWayAudio() {
          Log.i(TAG, "Two-way audio disabled (microphone muted).");
          // Disable microphone for one-way audio only
        }

        private void startRecording() {
          Log.i(TAG, "Video recording started.");
          // Pseudo-code to start recording the video feed
        }

        private void stopRecording() {
          Log.i(TAG, "Video recording stopped.");
          // Pseudo-code to stop and finalize the video recording
        }
      }

      Reply Quote
      Share
      • Share this Post
      • Facebook
      • Twitter
      • copy the link
        Copied!
      0
        View 0 replies
      • First post
        Last post
      All Categories
      Announcements and News Reolink Client & APP Discussion About Products #ReolinkTrial Reolink Captures Wishlist KEEN Trail Camera
      Never miss Reolink hot deals, news, and updates tailored for you.

      Thanks for your subscription!

      Please enter a valid email address.

      Oops… Something went wrong. Please try again later.

      You are already subscribed to this email list. :)

      Submission failed. Please try again later.

      Reolink Store|Support|About Us|Privacy Policy|Terms and Conditions

      Copyright 2025 © Reolink All Rights Reserved.

      Welcome Back!

      Hi there! Join the Commnunity to get all the latest news, tips and more!

      Join Now