Was fehlt mir hier für diese Klasse? ich habe es mit (>>> ... <<<) markiert.

Brainscrubb

Mitglied
[CODE lang="java" title="zwei importe können nicht gefunden werden was fehlt mir da? muss ich noch etwas implementieren in der Build.gradle?"]package com.brain.chat.Video_Calling;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.media.AudioAttributes;
import android.media.AudioFocusRequest;
import android.media.AudioManager;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.brain.chat.CodeClasses.ApiRequest;
import com.brain.chat.CodeClasses.Callback;
import com.brain.chat.CodeClasses.Variables;
import com.brain.chat.R;
import com.brain.chat.Video_Calling.util.CameraCapturerCompat;
import com.facebook.drawee.view.SimpleDraweeView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.twilio.video.AudioCodec;
import com.twilio.video.CameraCapturer;
>>>> import com.twilio.video.CameraCapturer.CameraSource; <<<
import com.twilio.video.ConnectOptions;
import com.twilio.video.EncodingParameters;
import com.twilio.video.G722Codec;
import com.twilio.video.H264Codec;
import com.twilio.video.IsacCodec;
import com.twilio.video.LocalAudioTrack;
import com.twilio.video.LocalParticipant;
import com.twilio.video.LocalVideoTrack;
import com.twilio.video_OpusCodec;
import com.twilio.video.PcmaCodec;
import com.twilio.video.PcmuCodec;
import com.twilio.video.RemoteAudioTrack;
import com.twilio.video.RemoteAudioTrackPublication;
import com.twilio.video.RemoteDataTrack;
import com.twilio.video.RemoteDataTrackPublication;
import com.twilio.video.RemoteParticipant;
import com.twilio.video.RemoteVideoTrack;
import com.twilio.video.RemoteVideoTrackPublication;
import com.twilio.video.Room;
import com.twilio.video.TwilioException;
import com.twilio.video.Video;
import com.twilio.video.VideoCodec;
>>> import com.twilio.video.VideoRenderer; <<<<<
import com.twilio.video.VideoTrack;
import com.twilio.video.VideoView;
import com.twilio.video.Vp8Codec;
import com.twilio.video.Vp9Codec;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Collections;

public class VideoActivity extends AppCompatActivity {
private static final int CAMERA_MIC_PERMISSION_REQUEST_CODE = 1;
private static final String TAG = "VideoActivity";

public static boolean is_calling_activity_open=false;

public static final String Call_Receive="Call_Receive";
public static final String Call_Send="Call_Send";
public static final String Call_Ringing="Call_Ringing";
public static final String Call_Pick="Call_Pick";
public static final String Call_not_Pick="Call_not_Pick";


private static final String LOCAL_AUDIO_TRACK_NAME = "mic";
private static final String LOCAL_VIDEO_TRACK_NAME = "camera";



public static String identity;

private String accessToken;

private Room room;
private LocalParticipant localParticipant;

private AudioCodec audioCodec;
private VideoCodec videoCodec;


private EncodingParameters encodingParameters;


private VideoView primaryVideoView;
private VideoView thumbnailVideoView;


private SharedPreferences default_preferences;
private SharedPreferences sharedPreferences;

private TextView videoStatusTextView;
private CameraCapturerCompat cameraCapturerCompat;
private LocalAudioTrack localAudioTrack;
private LocalVideoTrack localVideoTrack;
private FloatingActionButton connectActionFab,switchCameraActionFab,localVideoActionFab,muteActionFab,speaker_action_fab;
private ProgressBar reconnectingProgressBar;
private AudioManager audioManager;
private String remoteParticipantIdentity;

private int previousAudioMode;
private boolean previousMicrophoneMute;
private VideoRenderer localVideoView;
private boolean disconnectedFromOnDestroy;
private boolean isSpeakerPhoneEnabled = true;
private boolean enableAutomaticSubscription;



String caller_id,caller_name,caller_image,call_status,call_type,roomname;

public DatabaseReference rootref;

Ringtone ringtoneSound;

LinearLayout calling_action_btns;
public CameraCapturerCompat.Source CameraSource;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

setContentView(R.layout.activity_video);

sharedPreferences=getSharedPreferences(Variables.pref_name,MODE_PRIVATE);

identity= sharedPreferences.getString(Variables.uid,"0");


rootref= FirebaseDatabase.getInstance().getReference();

Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
ringtoneSound = RingtoneManager.getRingtone(getApplicationContext(), ringtoneUri);



primaryVideoView = findViewById(R.id.primary_video_view);
thumbnailVideoView = findViewById(R.id.thumbnail_video_view);
videoStatusTextView = findViewById(R.id.video_status_textview);
reconnectingProgressBar = findViewById(R.id.reconnecting_progress_bar);


calling_action_btns=findViewById(R.id.calling_action_btns);
connectActionFab = findViewById(R.id.connect_action_fab);
switchCameraActionFab = findViewById(R.id.switch_camera_action_fab);
localVideoActionFab = findViewById(R.id.local_video_action_fab);
muteActionFab = findViewById(R.id.mute_action_fab);
speaker_action_fab=findViewById(R.id.speaker_action_fab);

default_preferences = PreferenceManager.getDefaultSharedPreferences(this);


setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);


audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audioManager.setSpeakerphoneOn(isSpeakerPhoneEnabled);

Intent intent=getIntent();

onNewIntent(intent);


createAudioAndVideoTracks();
retrieveAccessTokenfromServer();

intializeUI();

get_user_token();




}


String caller_token="null";
public void get_user_token(){


rootref.child("Users")
.child(caller_id).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot!=null && dataSnapshot.hasChild("token")){
caller_token=dataSnapshot.child("token").getValue().toString();
}


Show_Calling_Dialog();

}

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

}
});

}



CountDownTimer countDownTimer;
public void Start_Countdown_timer(){
countDownTimer=new CountDownTimer(60000,2000) {
@Override
public void onTick(long millisUntilFinished) {

}

@Override
public void onFinish() {
Send_notification(Call_not_Pick,"Calling you...");
disconnectClickListener();
finish();
}
};

countDownTimer.start();
}

public void Stop_timer(){
if(countDownTimer!=null){
countDownTimer.cancel();
}
}

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if(intent!=null) {
caller_id=intent.getStringExtra("id");
caller_name=intent.getStringExtra("name");
caller_image=intent.getStringExtra("image");
call_status=intent.getStringExtra("status");
call_type=intent.getStringExtra("call_type");
roomname=intent.getStringExtra("roomname");
}
do_action_on_status();
}



TextView calling_status_txt;
RelativeLayout calling_user_info_layout;
public void Show_Calling_Dialog() {
calling_user_info_layout=findViewById(R.id.calling_user_info_layout);

calling_user_info_layout.setVisibility(View.VISIBLE);
calling_action_btns.setVisibility(View.GONE);


SimpleDraweeView userimage=findViewById(R.id.userimage);
TextView username=findViewById(R.id.username);
calling_status_txt=findViewById(R.id.calling_status_txt);

if(caller_image!=null && !caller_image.equals("")) {
Uri uri;
if(caller_image.contains("http"))
uri = Uri.parse(caller_image);
else
uri = Uri.parse(Variables.image_base_url+caller_image);

userimage.setImageURI(uri);
}else {
Uri uri = Uri.parse("null");
userimage.setImageURI(uri);
}

username.setText(caller_name);


RelativeLayout receive_disconnect_layout=findViewById(R.id.receive_disconnect_layout);
ImageButton pick_incoming_call=findViewById(R.id.pick_incoming_call);
ImageButton cancel_incoming_btn=findViewById(R.id.cancel_incoming_btn);

pick_incoming_call.setOnClickListener(new View.OnClickListener() {
@SuppressLint("RestrictedApi")
@Override
public void onClick(View v) {

if(accessToken!=null){

if(call_type.equals("video_call"))
calling_user_info_layout.setVisibility(View.GONE);
else {

switchCameraActionFab.setVisibility(View.GONE);
localVideoActionFab.setVisibility(View.GONE);
findViewById(R.id.receive_disconnect_layout).setVisibility(View.GONE);
findViewById(R.id.cancel_call).setVisibility(View.GONE);
}

calling_action_btns.setVisibility(View.VISIBLE);

if (ringtoneSound != null) {
ringtoneSound.stop();
}

VideoActivity.this.connectToRoom(roomname);
Send_notification(Call_Pick,"Pick your Call");
} else {
Toast.makeText(VideoActivity.this, "Call Access token not Found", Toast.LENGTH_SHORT).show();
}

}
});

cancel_incoming_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Send_notification(Call_not_Pick,"Hang out your call");
if (ringtoneSound != null) {
ringtoneSound.stop();
}
finish();
}
});


ImageButton cancel_call=findViewById(R.id.cancel_call);
cancel_call.setVisibility(View.VISIBLE);
cancel_call.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Send_notification(Call_not_Pick,"Hang out your call");
disconnectClickListener();
finish();
}
});

if(call_status.equals(Call_Send)){

receive_disconnect_layout.setVisibility(View.GONE);
cancel_call.setVisibility(View.VISIBLE);
Send_notification(Call_Receive,"Calling you...");

Start_Countdown_timer();

}

else if(call_status.equals(Call_Receive)){
receive_disconnect_layout.setVisibility(View.VISIBLE);
cancel_call.setVisibility(View.GONE);
calling_status_txt.setText("Calling you");
Send_notification(Call_Ringing,"Ringing...");

}



}



@SuppressLint("RestrictedApi")
public void do_action_on_status(){
if(call_status.equals(Call_Pick)) {
if (accessToken != null && calling_user_info_layout != null) {
Stop_timer();

if(call_type.equals("video_call"))
calling_user_info_layout.setVisibility(View.GONE);
else {
switchCameraActionFab.setVisibility(View.GONE);
localVideoActionFab.setVisibility(View.GONE);
findViewById(R.id.receive_disconnect_layout).setVisibility(View.GONE);
findViewById(R.id.cancel_call).setVisibility(View.GONE);
}

calling_action_btns.setVisibility(View.VISIBLE);

VideoActivity.this.connectToRoom(roomname);
Toast.makeText(this, "Pick call", Toast.LENGTH_SHORT).show();
}
}

else if(call_status.equals(Call_Receive)){

if (ringtoneSound != null) {
ringtoneSound.play();
}
}

else if(call_status.equals(Call_Ringing)){
if(calling_status_txt!=null)
calling_status_txt.setText(R.string.ringing);
}

else if(call_status.equals(Call_not_Pick)){
if (ringtoneSound != null) {
ringtoneSound.stop();
}
Toast.makeText(this, caller_name+" hang out the call", Toast.LENGTH_SHORT).show();
finish();
}


}



@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions,
@NonNull int[] grantResults) {
if (requestCode == CAMERA_MIC_PERMISSION_REQUEST_CODE) {
boolean cameraAndMicPermissionGranted = true;

for (int grantResult : grantResults) {
cameraAndMicPermissionGranted &= grantResult == PackageManager.PERMISSION_GRANTED;
}

if (cameraAndMicPermissionGranted) {
createAudioAndVideoTracks();
retrieveAccessTokenfromServer();
} else {
Toast.makeText(this,
"Need mic and speaker permission",
Toast.LENGTH_LONG).show();
}
}
}


@Override
protected void onStart() {
is_calling_activity_open=true;

audioCodec = getAudioCodecPreference(TwilioSettings.PREF_AUDIO_CODEC,
TwilioSettings.PREF_AUDIO_CODEC_DEFAULT);
videoCodec = getVideoCodecPreference(TwilioSettings.PREF_VIDEO_CODEC,
TwilioSettings.PREF_VIDEO_CODEC_DEFAULT);
enableAutomaticSubscription = getAutomaticSubscriptionPreference(TwilioSettings.PREF_ENABLE_AUTOMATIC_SUBSCRIPTION,
TwilioSettings.PREF_ENABLE_AUTOMATIC_SUBSCRIPTION_DEFAULT);

final EncodingParameters newEncodingParameters = getEncodingParameters();


if (localVideoTrack == null && call_type.equals("video_call")) {

if(cameraCapturerCompat==null)
cameraCapturerCompat = new com.brain.chat.Video_Calling.util.CameraCapturerCompat(this, getAvailableCameraSource());


localVideoTrack = LocalVideoTrack.create(this,
true,
cameraCapturerCompat.getVideoCapturer(),
LOCAL_VIDEO_TRACK_NAME);

localVideoTrack.addRenderer(localVideoView);


if (localParticipant != null) {
localParticipant.publishTrack(localVideoTrack);

if (!newEncodingParameters.equals(encodingParameters)) {
localParticipant.setEncodingParameters(newEncodingParameters);
}
}
}


encodingParameters = newEncodingParameters;

audioManager.setSpeakerphoneOn(isSpeakerPhoneEnabled);

if (room != null) {
reconnectingProgressBar.setVisibility((room.getState() != Room.State.RECONNECTING) ?
View.GONE :
View.VISIBLE);
videoStatusTextView.setText(getString(R.string.connected_to) +" "+ caller_name);
}

super.onStart();

}





@Override
protected void onStop() {


if (localVideoTrack != null) {

if (localParticipant != null) {
localParticipant.unpublishTrack(localVideoTrack);
}

localVideoTrack.release();
localVideoTrack = null;
}
super.onStop();

}



@Override
protected void onDestroy() {

is_calling_activity_open=false;

configureAudio(false);

if (ringtoneSound != null && ringtoneSound.isPlaying()) {
ringtoneSound.stop();
}

if (room != null && room.getState() != Room.State.DISCONNECTED) {
room.disconnect();
disconnectedFromOnDestroy = true;
}


if (localAudioTrack != null) {
localAudioTrack.release();
localAudioTrack = null;
}

if (localVideoTrack != null) {
localVideoTrack.release();
localVideoTrack = null;
}

Stop_limit_timer();
super.onDestroy();
}


private void createAudioAndVideoTracks() {
try {

localAudioTrack = LocalAudioTrack.create(this, true, LOCAL_AUDIO_TRACK_NAME);

if(call_type.equals("video_call")){
cameraCapturerCompat = new CameraCapturerCompat(this, getAvailableCameraSource());
localVideoTrack = LocalVideoTrack.create(this,
true,
cameraCapturerCompat.getVideoCapturer(),
LOCAL_VIDEO_TRACK_NAME);

primaryVideoView.setMirror(true);

if(localVideoTrack!=null){
localVideoTrack.addRenderer(primaryVideoView);
localVideoView = primaryVideoView;
}

}

}catch (Exception e){
Toast.makeText(this, e.toString(), Toast.LENGTH_SHORT).show();
}
}

private CameraSource getAvailableCameraSource() {
return (CameraCapturer.isSourceAvailable(CameraSource.FRONT_CAMERA)) ?
(CameraSource.FRONT_CAMERA) :
(CameraSource.BACK_CAMERA);
}


private void connectToRoom(String roomName) {
configureAudio(true);
ConnectOptions.Builder connectOptionsBuilder = new ConnectOptions.Builder(accessToken)
.roomName(roomName);


if (localAudioTrack != null) {
connectOptionsBuilder
.audioTracks(Collections.singletonList(localAudioTrack));
}


if (localVideoTrack != null && call_type.equals("video_call")) {
connectOptionsBuilder.videoTracks(Collections.singletonList(localVideoTrack));
}


connectOptionsBuilder.preferAudioCodecs(Collections.singletonList(audioCodec));

if(call_type.equals("video_call"))
connectOptionsBuilder.preferVideoCodecs(Collections.singletonList(videoCodec));


connectOptionsBuilder.encodingParameters(encodingParameters);
connectOptionsBuilder.enableAutomaticSubscription(enableAutomaticSubscription);

room = Video.connect(this, connectOptionsBuilder.build(), roomListener());
setDisconnectAction();
}


private void intializeUI() {
connectActionFab.show();
switchCameraActionFab.show();
switchCameraActionFab.setOnClickListener(switchCameraClickListener());
localVideoActionFab.show();
localVideoActionFab.setOnClickListener(localVideoClickListener());
muteActionFab.show();
muteActionFab.setOnClickListener(muteClickListener());
speaker_action_fab.show();
speaker_action_fab.setOnClickListener(speakerClickListener());

}


private AudioCodec getAudioCodecPreference(String key, String defaultValue) {
final String audioCodecName = default_preferences.getString(key, defaultValue);

switch (audioCodecName) {
case IsacCodec.NAME:
return new IsacCodec();
case OpusCodec.NAME:
return new OpusCodec();
case PcmaCodec.NAME:
return new PcmaCodec();
case PcmuCodec.NAME:
return new PcmuCodec();
case G722Codec.NAME:
return new G722Codec();
default:
return new OpusCodec();
}
}

private VideoCodec getVideoCodecPreference(String key, String defaultValue) {
final String videoCodecName = default_preferences.getString(key, defaultValue);

switch (videoCodecName) {
case Vp8Codec.NAME:
boolean simulcast = default_preferences.getBoolean(TwilioSettings.PREF_VP8_SIMULCAST,
TwilioSettings.PREF_VP8_SIMULCAST_DEFAULT);
return new Vp8Codec(simulcast);
case H264Codec.NAME:
return new H264Codec();
case Vp9Codec.NAME:
return new Vp9Codec();
default:
return new Vp8Codec();
}
}

private boolean getAutomaticSubscriptionPreference(String key, boolean defaultValue) {
return default_preferences.getBoolean(key, defaultValue);
}

private EncodingParameters getEncodingParameters() {
final int maxAudioBitrate = Integer.parseInt(
default_preferences.getString(TwilioSettings.PREF_SENDER_MAX_AUDIO_BITRATE,
TwilioSettings.PREF_SENDER_MAX_AUDIO_BITRATE_DEFAULT));
final int maxVideoBitrate = Integer.parseInt(
default_preferences.getString(TwilioSettings.PREF_SENDER_MAX_VIDEO_BITRATE,
TwilioSettings.PREF_SENDER_MAX_VIDEO_BITRATE_DEFAULT));

return new EncodingParameters(maxAudioBitrate, maxVideoBitrate);
}


private void setDisconnectAction() {
connectActionFab.show();
connectActionFab.setOnClickListener(disconnectClickListener());
}




private void addRemoteParticipant(RemoteParticipant remoteParticipant) {
/*
* This app only displays video for one additional participant per Room
*/
if (thumbnailVideoView.getVisibility() == View.VISIBLE) {
Snackbar.make(connectActionFab,
"Multiple participants are not currently support in this UI",
Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
return;
}
remoteParticipantIdentity = remoteParticipant.getIdentity();
videoStatusTextView.setText(caller_name +" "+ getString(R.string.joined));

/*
* Add remote participant renderer
*/
if (remoteParticipant.getRemoteVideoTracks().size() > 0) {
RemoteVideoTrackPublication remoteVideoTrackPublication =
remoteParticipant.getRemoteVideoTracks().get(0);

/*
* Only render video tracks that are subscribed to
*/
if (remoteVideoTrackPublication.isTrackSubscribed()) {
addRemoteParticipantVideo(remoteVideoTrackPublication.getRemoteVideoTrack());
}
}

/*
* Start listening for participant events
*/
remoteParticipant.setListener(remoteParticipantListener());
}


private void addRemoteParticipantVideo(VideoTrack videoTrack) {
moveLocalVideoToThumbnailView();
primaryVideoView.setMirror(false);
videoTrack.addRenderer(primaryVideoView);
}

private void moveLocalVideoToThumbnailView() {
if (thumbnailVideoView.getVisibility() == View.GONE) {
thumbnailVideoView.setVisibility(View.VISIBLE);
localVideoTrack.removeRenderer(primaryVideoView);
localVideoTrack.addRenderer(thumbnailVideoView);
localVideoView = thumbnailVideoView;
thumbnailVideoView.setMirror(cameraCapturerCompat.getCameraSource() ==
CameraSource.FRONT_CAMERA);
}
}


private void removeRemoteParticipant(RemoteParticipant remoteParticipant) {
videoStatusTextView.setText(caller_name +" left.");
if (!remoteParticipant.getIdentity().equals(remoteParticipantIdentity)) {
return;
}

/*
* Remove remote participant renderer
*/
if (!remoteParticipant.getRemoteVideoTracks().isEmpty()) {
RemoteVideoTrackPublication remoteVideoTrackPublication =
remoteParticipant.getRemoteVideoTracks().get(0);

/*
* Remove video only if subscribed to participant track
*/
if (remoteVideoTrackPublication.isTrackSubscribed()) {
removeParticipantVideo(remoteVideoTrackPublication.getRemoteVideoTrack());
}
}
moveLocalVideoToPrimaryView();

if(remoteParticipant.getIdentity().contains(caller_id)){
Toast.makeText(this, caller_name+" hang out the call", Toast.LENGTH_SHORT).show();
finish();
}

}

private void removeParticipantVideo(VideoTrack videoTrack) {
videoTrack.removeRenderer(primaryVideoView);
}

private void moveLocalVideoToPrimaryView() {
if (thumbnailVideoView.getVisibility() == View.VISIBLE) {
thumbnailVideoView.setVisibility(View.GONE);
if (localVideoTrack != null) {
localVideoTrack.removeRenderer(thumbnailVideoView);
localVideoTrack.addRenderer(primaryVideoView);
}
localVideoView = primaryVideoView;
primaryVideoView.setMirror(cameraCapturerCompat.getCameraSource() ==
CameraSource.FRONT_CAMERA);
}
}


private Room.Listener roomListener() {
return new Room.Listener() {
@Override
public void onConnected(Room room) {
localParticipant = room.getLocalParticipant();
videoStatusTextView.setText(getString(R.string.connected_to)+" "+ caller_name);
calling_status_txt.setText(getString(R.string.connected));

setTitle(room.getName());

Start_limit_Timer();

for (RemoteParticipant remoteParticipant : room.getRemoteParticipants()) {
addRemoteParticipant(remoteParticipant);
break;
}
}

@Override
public void onReconnecting(@NonNull Room room, @NonNull TwilioException twilioException) {
videoStatusTextView.setText(getString(R.string.reconnecting_to) +caller_name);
calling_status_txt.setText(R.string.reconnecting);
reconnectingProgressBar.setVisibility(View.VISIBLE);
}

@Override
public void onReconnected(@NonNull Room room) {
videoStatusTextView.setText(getString(R.string.connected_to) + room.getName());
calling_status_txt.setText(R.string.connected);
reconnectingProgressBar.setVisibility(View.GONE);
}

@Override
public void onConnectFailure(Room room, TwilioException e) {
videoStatusTextView.setText(R.string.failed_to_connect);
calling_status_txt.setText(R.string.disconnected);
configureAudio(false);
intializeUI();
}

@Override
public void onDisconnected(Room room, TwilioException e) {
localParticipant = null;
videoStatusTextView.setText(getString(R.string.disconnected_from) +caller_name);
reconnectingProgressBar.setVisibility(View.GONE);
VideoActivity.this.room = null;
// Only reinitialize the UI if disconnect was not called from onDestroy()
if (!disconnectedFromOnDestroy) {
configureAudio(false);
intializeUI();
moveLocalVideoToPrimaryView();
}

Stop_limit_timer();
}

@Override
public void onParticipantConnected(Room room, RemoteParticipant remoteParticipant) {
addRemoteParticipant(remoteParticipant);

}

@Override
public void onParticipantDisconnected(Room room, RemoteParticipant remoteParticipant) {
removeRemoteParticipant(remoteParticipant);
}

@Override
public void onRecordingStarted(Room room) {

Log.d(TAG, "onRecordingStarted");
}

@Override
public void onRecordingStopped(Room room) {

Log.d(TAG, "onRecordingStopped");
}
};
}

private RemoteParticipant.Listener remoteParticipantListener() {
return new RemoteParticipant.Listener() {
@Override
public void onAudioTrackPublished(RemoteParticipant remoteParticipant,
RemoteAudioTrackPublication remoteAudioTrackPublication) {
Log.i(TAG, String.format("onAudioTrackPublished: " +
"[RemoteParticipant: identity=%s], " +
"[RemoteAudioTrackPublication: sid=%s, enabled=%b, " +
"subscribed=%b, name=%s]",
remoteParticipant.getIdentity(),
remoteAudioTrackPublication.getTrackSid(),
remoteAudioTrackPublication.isTrackEnabled(),
remoteAudioTrackPublication.isTrackSubscribed(),
remoteAudioTrackPublication.getTrackName()));
videoStatusTextView.setText(R.string.audio_connected);
}

@Override
public void onAudioTrackUnpublished(RemoteParticipant remoteParticipant,
RemoteAudioTrackPublication remoteAudioTrackPublication) {
Log.i(TAG, String.format("onAudioTrackUnpublished: " +
"[RemoteParticipant: identity=%s], " +
"[RemoteAudioTrackPublication: sid=%s, enabled=%b, " +
"subscribed=%b, name=%s]",
remoteParticipant.getIdentity(),
remoteAudioTrackPublication.getTrackSid(),
remoteAudioTrackPublication.isTrackEnabled(),
remoteAudioTrackPublication.isTrackSubscribed(),
remoteAudioTrackPublication.getTrackName()));
videoStatusTextView.setText(R.string.audio_unpublished);
}

@Override
public void onDataTrackPublished(RemoteParticipant remoteParticipant,
RemoteDataTrackPublication remoteDataTrackPublication) {
Log.i(TAG, String.format("onDataTrackPublished: " +
"[RemoteParticipant: identity=%s], " +
"[RemoteDataTrackPublication: sid=%s, enabled=%b, " +
"subscribed=%b, name=%s]",
remoteParticipant.getIdentity(),
remoteDataTrackPublication.getTrackSid(),
remoteDataTrackPublication.isTrackEnabled(),
remoteDataTrackPublication.isTrackSubscribed(),
remoteDataTrackPublication.getTrackName()));

}

@Override
public void onDataTrackUnpublished(RemoteParticipant remoteParticipant,
RemoteDataTrackPublication remoteDataTrackPublication) {
Log.i(TAG, String.format("onDataTrackUnpublished: " +
"[RemoteParticipant: identity=%s], " +
"[RemoteDataTrackPublication: sid=%s, enabled=%b, " +
"subscribed=%b, name=%s]",
remoteParticipant.getIdentity(),
remoteDataTrackPublication.getTrackSid(),
remoteDataTrackPublication.isTrackEnabled(),
remoteDataTrackPublication.isTrackSubscribed(),
remoteDataTrackPublication.getTrackName()));

}

@Override
public void onVideoTrackPublished(RemoteParticipant remoteParticipant,
RemoteVideoTrackPublication remoteVideoTrackPublication) {
Log.i(TAG, String.format("onVideoTrackPublished: " +
"[RemoteParticipant: identity=%s], " +
"[RemoteVideoTrackPublication: sid=%s, enabled=%b, " +
"subscribed=%b, name=%s]",
remoteParticipant.getIdentity(),
remoteVideoTrackPublication.getTrackSid(),
remoteVideoTrackPublication.isTrackEnabled(),
remoteVideoTrackPublication.isTrackSubscribed(),
remoteVideoTrackPublication.getTrackName()));
videoStatusTextView.setText(R.string.video_connected);
}

@Override
public void onVideoTrackUnpublished(RemoteParticipant remoteParticipant,
RemoteVideoTrackPublication remoteVideoTrackPublication) {
Log.i(TAG, String.format("onVideoTrackUnpublished: " +
"[RemoteParticipant: identity=%s], " +
"[RemoteVideoTrackPublication: sid=%s, enabled=%b, " +
"subscribed=%b, name=%s]",
remoteParticipant.getIdentity(),
remoteVideoTrackPublication.getTrackSid(),
remoteVideoTrackPublication.isTrackEnabled(),
remoteVideoTrackPublication.isTrackSubscribed(),
remoteVideoTrackPublication.getTrackName()));
videoStatusTextView.setText(R.string.video_unpublished);
}

@Override
public void onAudioTrackSubscribed(RemoteParticipant remoteParticipant,
RemoteAudioTrackPublication remoteAudioTrackPublication,
RemoteAudioTrack remoteAudioTrack) {
Log.i(TAG, String.format("onAudioTrackSubscribed: " +
"[RemoteParticipant: identity=%s], " +
"[RemoteAudioTrack: enabled=%b, playbackEnabled=%b, name=%s]",
remoteParticipant.getIdentity(),
remoteAudioTrack.isEnabled(),
remoteAudioTrack.isPlaybackEnabled(),
remoteAudioTrack.getName()));
videoStatusTextView.setText(R.string.audio_subscribed);
}

@Override
public void onAudioTrackUnsubscribed(RemoteParticipant remoteParticipant,
RemoteAudioTrackPublication remoteAudioTrackPublication,
RemoteAudioTrack remoteAudioTrack) {
Log.i(TAG, String.format("onAudioTrackUnsubscribed: " +
"[RemoteParticipant: identity=%s], " +
"[RemoteAudioTrack: enabled=%b, playbackEnabled=%b, name=%s]",
remoteParticipant.getIdentity(),
remoteAudioTrack.isEnabled(),
remoteAudioTrack.isPlaybackEnabled(),
remoteAudioTrack.getName()));
videoStatusTextView.setText(R.string.audio_unsubscribed);
}

@Override
public void onAudioTrackSubscriptionFailed(RemoteParticipant remoteParticipant,
RemoteAudioTrackPublication remoteAudioTrackPublication,
TwilioException twilioException) {
Log.i(TAG, String.format("onAudioTrackSubscriptionFailed: " +
"[RemoteParticipant: identity=%s], " +
"[RemoteAudioTrackPublication: sid=%b, name=%s]" +
"[TwilioException: code=%d, message=%s]",
remoteParticipant.getIdentity(),
remoteAudioTrackPublication.getTrackSid(),
remoteAudioTrackPublication.getTrackName(),
twilioException.getCode(),
twilioException.getMessage()));
videoStatusTextView.setText(R.string.audio_subscription_failed);
}

@Override
public void onDataTrackSubscribed(RemoteParticipant remoteParticipant,
RemoteDataTrackPublication remoteDataTrackPublication,
RemoteDataTrack remoteDataTrack) {
Log.i(TAG, String.format("onDataTrackSubscribed: " +
"[RemoteParticipant: identity=%s], " +
"[RemoteDataTrack: enabled=%b, name=%s]",
remoteParticipant.getIdentity(),
remoteDataTrack.isEnabled(),
remoteDataTrack.getName()));

}

@Override
public void onDataTrackUnsubscribed(RemoteParticipant remoteParticipant,
RemoteDataTrackPublication remoteDataTrackPublication,
RemoteDataTrack remoteDataTrack) {
Log.i(TAG, String.format("onDataTrackUnsubscribed: " +
"[RemoteParticipant: identity=%s], " +
"[RemoteDataTrack: enabled=%b, name=%s]",
remoteParticipant.getIdentity(),
remoteDataTrack.isEnabled(),
remoteDataTrack.getName()));

}

@Override
public void onDataTrackSubscriptionFailed(RemoteParticipant remoteParticipant,
RemoteDataTrackPublication remoteDataTrackPublication,
TwilioException twilioException) {
Log.i(TAG, String.format("onDataTrackSubscriptionFailed: " +
"[RemoteParticipant: identity=%s], " +
"[RemoteDataTrackPublication: sid=%b, name=%s]" +
"[TwilioException: code=%d, message=%s]",
remoteParticipant.getIdentity(),
remoteDataTrackPublication.getTrackSid(),
remoteDataTrackPublication.getTrackName(),
twilioException.getCode(),
twilioException.getMessage()));

}

@Override
public void onVideoTrackSubscribed(RemoteParticipant remoteParticipant,
RemoteVideoTrackPublication remoteVideoTrackPublication,
RemoteVideoTrack remoteVideoTrack) {
Log.i(TAG, String.format("onVideoTrackSubscribed: " +
"[RemoteParticipant: identity=%s], " +
"[RemoteVideoTrack: enabled=%b, name=%s]",
remoteParticipant.getIdentity(),
remoteVideoTrack.isEnabled(),
remoteVideoTrack.getName()));
videoStatusTextView.setText(R.string.video_subscribed);
addRemoteParticipantVideo(remoteVideoTrack);
}

@Override
public void onVideoTrackUnsubscribed(RemoteParticipant remoteParticipant,
RemoteVideoTrackPublication remoteVideoTrackPublication,
RemoteVideoTrack remoteVideoTrack) {
Log.i(TAG, String.format("onVideoTrackUnsubscribed: " +
"[RemoteParticipant: identity=%s], " +
"[RemoteVideoTrack: enabled=%b, name=%s]",
remoteParticipant.getIdentity(),
remoteVideoTrack.isEnabled(),
remoteVideoTrack.getName()));
videoStatusTextView.setText(R.string.video_unsubscribed);
removeParticipantVideo(remoteVideoTrack);
}

@Override
public void onVideoTrackSubscriptionFailed(RemoteParticipant remoteParticipant,
RemoteVideoTrackPublication remoteVideoTrackPublication,
TwilioException twilioException) {
Log.i(TAG, String.format("onVideoTrackSubscriptionFailed: " +
"[RemoteParticipant: identity=%s], " +
"[RemoteVideoTrackPublication: sid=%b, name=%s]" +
"[TwilioException: code=%d, message=%s]",
remoteParticipant.getIdentity(),
remoteVideoTrackPublication.getTrackSid(),
remoteVideoTrackPublication.getTrackName(),
twilioException.getCode(),
twilioException.getMessage()));
videoStatusTextView.setText(R.string.video_subscription_failed);
Snackbar.make(connectActionFab,
String.format("Failed to subscribe to %s video track",
remoteParticipant.getIdentity()),
Snackbar.LENGTH_LONG)
.show();
}

@Override
public void onAudioTrackEnabled(RemoteParticipant remoteParticipant,
RemoteAudioTrackPublication remoteAudioTrackPublication) {

}

@Override
public void onAudioTrackDisabled(RemoteParticipant remoteParticipant,
RemoteAudioTrackPublication remoteAudioTrackPublication) {

}

@Override
public void onVideoTrackEnabled(RemoteParticipant remoteParticipant,
RemoteVideoTrackPublication remoteVideoTrackPublication) {

}

@Override
public void onVideoTrackDisabled(RemoteParticipant remoteParticipant,
RemoteVideoTrackPublication remoteVideoTrackPublication) {

}
};
}



private View.OnClickListener disconnectClickListener() {
return new View.OnClickListener() {
@Override
public void onClick(View v) {

if (room != null) {
room.disconnect();
}
VideoActivity.this.intializeUI();
finish();
}
};
}

private View.OnClickListener switchCameraClickListener() {
return new View.OnClickListener() {
@Override
public void onClick(View v) {
if (cameraCapturerCompat != null) {
CameraSource cameraSource = cameraCapturerCompat.getCameraSource();
cameraCapturerCompat.switchCamera();
if (thumbnailVideoView.getVisibility() == View.VISIBLE) {
thumbnailVideoView.setMirror(cameraSource == CameraSource.BACK_CAMERA);
} else {
primaryVideoView.setMirror(cameraSource == CameraSource.BACK_CAMERA);
}
}
}
};
}

private View.OnClickListener localVideoClickListener() {
return new View.OnClickListener() {
@Override
public void onClick(View v) {
/*
* Enable/disable the local video track
*/
if (localVideoTrack != null) {
boolean enable = !localVideoTrack.isEnabled();
localVideoTrack.enable(enable);
int icon;
if (enable) {
icon = R.drawable.ic_videocam_white_24dp;
switchCameraActionFab.show();
} else {
icon = R.drawable.ic_videocam_off_black_24dp;
switchCameraActionFab.hide();
}
localVideoActionFab.setImageDrawable(
ContextCompat.getDrawable(VideoActivity.this, icon));
}
}
};
}

private View.OnClickListener muteClickListener() {
return new View.OnClickListener() {
@Override
public void onClick(View v) {
/*
* Enable/disable the local audio track. The results of this operation are
* signaled to other Participants in the same Room. When an audio track is
* disabled, the audio is muted.
*/
if (localAudioTrack != null) {
boolean enable = !localAudioTrack.isEnabled();
localAudioTrack.enable(enable);
int icon = enable ?
R.drawable.ic_mic_white_24dp : R.drawable.ic_mic_off_black_24dp;
muteActionFab.setImageDrawable(ContextCompat.getDrawable(
VideoActivity.this, icon));
}
}
};
}


private View.OnClickListener speakerClickListener() {
return new View.OnClickListener() {
@Override
public void onClick(View v) {

if (audioManager.isSpeakerphoneOn()) {
audioManager.setSpeakerphoneOn(false);
speaker_action_fab.setImageResource(R.drawable.ic_volume_mute_black_24dp);
isSpeakerPhoneEnabled = false;
} else {
audioManager.setSpeakerphoneOn(true);
speaker_action_fab.setImageResource(R.drawable.ic_volume_up_white_24dp);
isSpeakerPhoneEnabled = true;
}

}
};
}






private void retrieveAccessTokenfromServer() {

StringRequest postRequest = new StringRequest(Request.Method.GET,
Variables.TWILIO_ACCESS_TOKEN_SERVER +identity+"?roomname="+roomname,
new Response.Listener<String>()
{
@Override
public void onResponse(String response) {

Log.d("resp",response);
try {
JSONObject jsonObject=new JSONObject(response);
String token=jsonObject.optString("token");

VideoActivity.this.accessToken = token;

} catch (JSONException e) {
e.printStackTrace();
}


}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error) {

}
}
) ;
RequestQueue requestQueue = Volley.newRequestQueue(this);
postRequest.setRetryPolicy(new DefaultRetryPolicy(30000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
requestQueue.getCache().clear();
requestQueue.add(postRequest);


}

private void configureAudio(boolean enable) {
if (enable) {
previousAudioMode = audioManager.getMode();
// Request audio focus before making any device switch
requestAudioFocus();
/*
* Use MODE_IN_COMMUNICATION as the default audio mode. It is required
* to be in this mode when playout and/or recording starts for the best
* possible VoIP performance. Some devices have difficulties with
* speaker mode if this is not set.
*/
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
/*
* Always disable microphone mute during a WebRTC call.
*/
previousMicrophoneMute = audioManager.isMicrophoneMute();
audioManager.setMicrophoneMute(false);
} else {
audioManager.setMode(previousAudioMode);
audioManager.abandonAudioFocus(null);
audioManager.setMicrophoneMute(previousMicrophoneMute);
}
}

private void requestAudioFocus() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
AudioAttributes playbackAttributes = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
.setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
.build();
AudioFocusRequest focusRequest =
new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT)
.setAudioAttributes(playbackAttributes)
.setAcceptsDelayedFocusGain(true)
.setOnAudioFocusChangeListener(
new AudioManager.OnAudioFocusChangeListener() {
@Override
public void onAudioFocusChange(int i) {
}
})
.build();
audioManager.requestAudioFocus(focusRequest);
} else {
audioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL,
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
}
}




public void Send_notification(String call_status, String message){

String name = sharedPreferences.getString(Variables.f_name,"")+" "+sharedPreferences.getString(Variables.l_name,"");

JSONObject json = new JSONObject();
try {

json.put("to", caller_token);
JSONObject info = new JSONObject();

info.put("senderId",identity );
info.put("senderImage","");
info.put("title", name);
info.put("body", message);
info.put("type",call_type);
info.put("action",call_status);
info.put("message",roomname);

JSONObject ttl=new JSONObject();
ttl.put("ttl","5s");

json.put("notification", info);
json.put("data",info);
json.put("android",ttl);


} catch (JSONException e) {
e.printStackTrace();
}

ApiRequest.Send_Notification(this, json, new Callback() {
@Override
public void Responce(String resp) {

}
});

}




CountDownTimer limit_countDownTimer;
public void Start_limit_Timer(){
if(sharedPreferences.getBoolean(Variables.ispuduct_puchase,false) || !Variables.calling_limit) {
}
else
limit_countDownTimer = new CountDownTimer(Variables.max_video_calling_time, 1000) {

public void onTick(long millisUntilFinished) {
if (call_type.equals("video_call")) {
int call_time = sharedPreferences.getInt(Variables.video_calling_used_time, 0);
sharedPreferences.edit().putInt(Variables.video_calling_used_time, call_time + 1000).commit();
if (call_time > Variables.max_video_calling_time) {
connectActionFab.performClick();
}
} else {
int call_time = sharedPreferences.getInt(Variables.voice_calling_used_time, 0);
sharedPreferences.edit().putInt(Variables.voice_calling_used_time, call_time + 1000).commit();
if (call_time > Variables.max_voice_calling_time) {
connectActionFab.performClick();
}
}
}

public void onFinish() {
connectActionFab.performClick();
}
}.start();


}

public void Stop_limit_timer(){


if(limit_countDownTimer!=null){
limit_countDownTimer.cancel();
}
}

}
[/CODE]


Build.gradle:

[CODE lang="java" title="Build.gradle:app"]plugins {

id 'com.android.application'

id 'com.google.gms.google-services'

}



android {

compileSdkVersion 30

buildToolsVersion "30.0.3"

compileOptions {

sourceCompatibility 1.8

targetCompatibility 1.8

}



defaultConfig {

applicationId "com.brain.chat"

minSdkVersion 22

targetSdkVersion 30

versionCode 1

versionName "1.0"



testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}

buildTypes {

release {

minifyEnabled false

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

}

}



compileOptions {

sourceCompatibility JavaVersion.VERSION_1_8

targetCompatibility JavaVersion.VERSION_1_8

}



lintOptions {

checkReleaseBuilds false

abortOnError false

}



}

dependencies {

implementation fileTree(include: ['*.jar'], dir: 'libs')

//noinspection GradleCompatible

implementation 'androidx.appcompat:appcompat:1.2.0'

implementation 'androidx.constraintlayout:constraintlayout:2.0.1'

implementation 'androidx.exifinterface:exifinterface:1.3.0'

testImplementation 'junit:junit:4.12'

implementation 'androidx.legacy:legacy-support-v4:1.0.0'



implementation 'androidx.multidex:multidex:2.0.1'



implementation project(':DragRecylerView')



implementation 'com.yuyakaido.android:card-stack-view:1.0.0-beta9'

implementation 'de.hdodenhof:circleimageview:2.1.0'

implementation 'com.makeramen:roundedimageview:2.3.0'

implementation 'com.daimajia.easing:library:2.0@aar'

implementation 'com.daimajia.androidanimations:library:2.3@aar'

implementation 'com.daimajia.slider:library:1.1.5@aar'

implementation 'com.nineoldandroids:library:2.4.0'

implementation 'com.squareup.picasso:picasso:2.5.2'

implementation 'com.github.yesterselga:country-picker-android:1.0'

implementation 'com.google.android.material:material:1.2.1'

implementation 'androidx.cardview:cardview:1.0.0'

implementation 'androidx.percentlayout:percentlayout:1.0.0'

implementation 'com.mindorks.android:prdownloader:0.6.0'

implementation 'com.anjlab.android.iab.v3:library:1.0.44'

implementation 'com.chauthai.overscroll:eek:verscroll-bouncy:0.1.1'

implementation 'pl.bclogic:pulsator4droid:1.0.3'

implementation 'me.everything:eek:verscroll-decor-android:1.0.4'

implementation 'com.labo.kaji:fragmentanimations:0.1.1'

implementation 'com.mcxiaoke.volley:library-aar:1.0.0'

implementation 'com.makeramen:roundedimageview:2.3.0'

implementation 'com.github.florent37:shapeofview:1.4.5'

implementation 'com.facebook.android:facebook-android-sdk:5.15.3'

implementation 'com.gmail.samehadar:iosdialog:1.0'



implementation('com.giphy.sdk:core:1.0.2@aar') {

transitive = true

}



implementation 'com.github.bumptech.glide:glide:4.9.0'

annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'



implementation 'com.github.channguyen:rsv:1.0.1'

implementation 'com.zhouyou:signseekbar:1.0.6'



implementation 'net.the4thdimension:audio-wife:1.0.3'

implementation 'org.jsoup:jsoup:1.11.3'



implementation 'com.github.aakira:expandable-layout:1.6.0@aar'



implementation 'com.appyvet:materialrangebar:1.4.8'



implementation 'com.facebook.fresco:fresco:2.1.0'



implementation 'com.mikhaellopez:circularprogressbar:3.0.3'



implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.+'



implementation 'com.twilio:video-android-ktx:6.1.0'

implementation 'com.twilio:video-android:6.1.0'



//noinspection GradleCompatible

implementation 'com.google.android.gms:play-services-gcm:17.0.0'

implementation 'com.google.android.gms:play-services-maps:17.0.0'

implementation 'com.google.android.gms:play-services-location:18.0.0'

implementation 'com.google.android.gms:play-services-places:17.0.0'

implementation 'com.google.android.gms:play-services-auth:19.0.0'

implementation 'com.google.firebase:firebase-database:19.7.0'

implementation 'com.google.firebase:firebase-messaging:21.0.1'

implementation 'com.google.firebase:firebase-auth:20.0.4'

implementation 'com.google.firebase:firebase-core:18.0.2'

implementation 'com.google.firebase:firebase-storage:19.2.2'

implementation 'com.google.android.gms:play-services-ads:20.0.0'



implementation 'cat.ereza:customactivityoncrash:2.3.0'



androidTestImplementation 'androidx.test:runner:1.3.0'

androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

implementation group: 'com.wonshinhyo', name: 'dragrecyclerview', version: '1.0.0'

implementation project(':DragRecylerView')

implementation 'org.webrtc:google-webrtc:1.0.+'



}

apply plugin: 'com.google.gms.google-services'[/CODE]


Wäre sehr dankbar wenn mir jemand helfen kann.
 

Brainscrubb

Mitglied
[CODE lang="java" title="Ich verzweifel hierbei! ich bekomme immer die meldung 'Enter Correct Number' warum??"] private String phoneVerificationId;
private PhoneAuthProvider.OnVerificationStateChangedCallbacks
verificationCallbacks;
private PhoneAuthProvider.ForceResendingToken resendToken;
private FirebaseAuth fbAuth;
EditText phoneText,digit1,digit2,digit3,digit4,digit5,digit6;
TextView countrytxt,countrycodetxt,sendtotxt;
RelativeLayout select_country;
ViewFlipper viewFlipper;
String phoneNumber;

SharedPreferences sharedPreferences;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_phone);
fbAuth = FirebaseAuth.getInstance();

fbAuth.setLanguageCode("en");

sharedPreferences=getSharedPreferences(Variables.pref_name,MODE_PRIVATE);

phoneText=findViewById(R.id.phonetxt);

select_country=findViewById(R.id.select_country);
select_country.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Opencountry();
}
});

countrytxt =findViewById(R.id.countrytxt);
countrycodetxt=findViewById(R.id.countrycodetxt);

sendtotxt=findViewById(R.id.sendtotxt);

viewFlipper=findViewById(R.id.viewfillper);

codefill();

}

//message code fill in edittext and change focus in android
public void codefill(){

digit1=findViewById(R.id.digitone);
digit2=findViewById(R.id.digittwo);
digit3=findViewById(R.id.digitthree);
digit4=findViewById(R.id.digitfour);
digit5=findViewById(R.id.digitfive);
digit6=findViewById(R.id.digitsix);

digit1.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
if(digit1.getText().toString().length()==0){
digit2.requestFocus();
}
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override
public void afterTextChanged(Editable s) {

}
});

digit2.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
if(digit2.getText().toString().length()==0){
digit3.requestFocus();
}
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override
public void afterTextChanged(Editable s) {

}
});

digit3.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
if(digit3.getText().toString().length()==0){
digit4.requestFocus();
}
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override
public void afterTextChanged(Editable s) {

}
});

digit4.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
if(digit4.getText().toString().length()==0){
digit5.requestFocus();
}

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override
public void afterTextChanged(Editable s) {

}
});

digit5.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
if(digit5.getText().toString().length()==0){
digit6.requestFocus();
}

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override
public void afterTextChanged(Editable s) {

}
});

}

String country_iso_code="US";
@SuppressLint("WrongConstant")
public void Opencountry(){

final CountryPicker picker = CountryPicker.newInstance("Select Country");
picker.setListener(new CountryPickerListener() {
@Override
public void onSelectCountry(String name, String code, String dialCode, int flagDrawableResID) {
// Implement your code here
countrytxt.setText(name);
countrycodetxt.setText(dialCode);
picker.dismiss();
country_iso_code=code;
}
});
picker.setStyle(R.style.countrypicker_style,R.style.countrypicker_style);
picker.show(getSupportFragmentManager(), "Select Country");

}

public void Nextbtn(View view) {

phoneNumber=countrycodetxt.getText().toString()+phoneText.getText().toString();
Send_Number_tofirebase(phoneNumber);

}


public void Send_Number_tofirebase(String phoneNumber){
setUpVerificatonCallbacks();
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
verificationCallbacks);
}

private void setUpVerificatonCallbacks() {
Functions.Show_loader(this,false,true);
verificationCallbacks =
new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {

@Override
public void onVerificationCompleted(PhoneAuthCredential credential) {

Functions.cancel_loader();
signInWithPhoneAuthCredential(credential);

}

@Override
public void onVerificationFailed(FirebaseException e) {
Functions.cancel_loader();

Log.d("responce",e.toString());
Toast.makeText(Login_Phone_A.this, "Enter Correct Number.", Toast.LENGTH_SHORT).show();
if (e instanceof FirebaseAuthInvalidCredentialsException) {
// Invalid request
} else if (e instanceof FirebaseTooManyRequestsException) {
// SMS quota exceeded
}
}

@Override
public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingToken token) {

Functions.cancel_loader();

phoneVerificationId = verificationId;
resendToken = token;
sendtotxt.setText("Send to ( "+phoneNumber+" )");
viewFlipper.setInAnimation(Login_Phone_A.this, R.anim.in_from_right);
viewFlipper.setOutAnimation(Login_Phone_A.this, R.anim.out_to_left);
viewFlipper.setDisplayedChild(1);

}
};
}


public void verifyCode(View view) {
String code=""+digit1.getText().toString()+digit2.getText().toString()+digit3.getText().toString()+digit4.getText().toString()+digit5.getText().toString()+digit6.getText().toString();
if(!code.equals("")){
Functions.Show_loader(this,false,true);
PhoneAuthCredential credential =
PhoneAuthProvider.getCredential(phoneVerificationId, code);
signInWithPhoneAuthCredential(credential);
}else {
Toast.makeText(this, "Enter the Correct varification Code", Toast.LENGTH_SHORT).show();
}


}


private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
fbAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {

// get the user info to know that user is already login or not
Get_User_info();

} else {
if (task.getException() instanceof
FirebaseAuthInvalidCredentialsException) {
Functions.cancel_loader();
}
}
}
});
}


public void resendCode(View view) {

String phoneNumber = phoneText.getText().toString();

setUpVerificatonCallbacks();

PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber,
60,
TimeUnit.SECONDS,
this,
verificationCallbacks,
resendToken);
}


public void Goback_1(View view) {
finish();
}

public void Goback(View view) {
viewFlipper.setInAnimation(Login_Phone_A.this, R.anim.in_from_left);
viewFlipper.setOutAnimation(Login_Phone_A.this, R.anim.out_to_right);
viewFlipper.setDisplayedChild(0);
}


private void Get_User_info() {

final String phone_no=phoneNumber.replace("+","");
JSONObject parameters = new JSONObject();
try {
parameters.put("fb_id", phone_no);

} catch (JSONException e) {
e.printStackTrace();
}

Functions.Show_loader(this,false,true);
ApiRequest.Call_Api(this, Variables.getUserInfo, parameters, new Callback() {
@Override
public void Responce(String resp) {
Functions.cancel_loader();
try {
JSONObject jsonObject=new JSONObject(resp);
String code=jsonObject.optString("code");
if(code.equals("200")){

// if user is already logedin then we will save the user data and go to the enable location screen
JSONArray msg=jsonObject.getJSONArray("msg");
JSONObject userdata=msg.getJSONObject(0);

SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putString(Variables.uid,phone_no);
editor.putString(Variables.f_name,userdata.optString("first_name"));
editor.putString(Variables.l_name,userdata.optString("last_name"));
editor.putString(Variables.birth_day,userdata.optString("age"));
editor.putString(Variables.gender,userdata.optString("gender"));
editor.putString(Variables.u_pic,userdata.optString("image1"));
editor.putBoolean(Variables.islogin,true);
editor.commit();

// after all things done we will move the user to enable location screen
enable_location();


}else {
// if user is first time login then we will get the usser picture and name
Intent intent=new Intent(Login_Phone_A.this, Get_User_Info_A.class);
intent.putExtra("id",phone_no);
startActivity(intent);
overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
finish();

}

}catch (JSONException e) {

e.printStackTrace();
}

}
});

}


private void enable_location() {
// will move the user for enable location screen
startActivity(new Intent(this, Enable_location_A.class));
overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
finishAffinity();

}[/CODE]
 
Zuletzt bearbeitet von einem Moderator:

mrBrown

Super-Moderator
Mitarbeiter
Guck dir einfach mal die Exception an, "Enter Correct Number" gibst du immer aus, egal was der eigentliche Fehler ist.
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
M Android Studio - Configuration fehlt Android & Cross-Platform Mobile Apps 20
Kazudemruzo Android API/Library für externe Entwickler zur Verfügung stellen Android & Cross-Platform Mobile Apps 7
C Consent für Admob mit ump / funding choices Android & Cross-Platform Mobile Apps 6
J SharedPreferences für User-Session Android & Cross-Platform Mobile Apps 2
M Barrierefreie Appentwicklung für Android - Suche Codebeispiele Android & Cross-Platform Mobile Apps 8
I App für Fire HD entwickeln Android & Cross-Platform Mobile Apps 3
T Bringen mir die Java-Basics irgendetwas für die Android-Programmierung Android & Cross-Platform Mobile Apps 4
L Textfeld für Dezimalzahl mit Vorzeichen Android & Cross-Platform Mobile Apps 2
J Android Datenbank Klasse nur für CRUD-Operation, oder auch mehr ? Android & Cross-Platform Mobile Apps 8
B Android Projekt für Android und IOS erstellen? Android & Cross-Platform Mobile Apps 5
J Impressumspflicht für App, wenn ich kein Unternehmer bin? Android & Cross-Platform Mobile Apps 13
T Android Equalizer für Android Android & Cross-Platform Mobile Apps 3
L Zeitstempel für Sensordaten bekommen Android & Cross-Platform Mobile Apps 3
L Android Texterkennung für Android? Android & Cross-Platform Mobile Apps 1
L Android Chart API für Android Android & Cross-Platform Mobile Apps 0
T Android Datenbankverbindung in Service für Push Notification Android & Cross-Platform Mobile Apps 0
R Android USB Treiber für Huawei Android & Cross-Platform Mobile Apps 1
M Hilfe bei App Programmierung für Android Android & Cross-Platform Mobile Apps 1
B Script für Android Android & Cross-Platform Mobile Apps 1
H Datenprotokoll für Graphview Android & Cross-Platform Mobile Apps 2
M Android Obfuscation für Strings Android & Cross-Platform Mobile Apps 8
S Bilder mit fester grösse für verschiedene Android Endgeräte Android & Cross-Platform Mobile Apps 2
D Android Layout für alle Geräte Android & Cross-Platform Mobile Apps 4
A String[] für Lisadapter Android & Cross-Platform Mobile Apps 4
D Lib für (Desktop-)Java und Android schreiben Android & Cross-Platform Mobile Apps 7
J MySQL Simulation für Android App Android & Cross-Platform Mobile Apps 2
kaoZ Tutorial .xml Layouting für z.B ListView elemente Android & Cross-Platform Mobile Apps 7
W Java Editor für Android +Emulator Android & Cross-Platform Mobile Apps 7
M 20 Image Button für jede Auflösung positionieren Android & Cross-Platform Mobile Apps 3
L Android ActionBar mit unterschiedlichen Farben für Tabs Android & Cross-Platform Mobile Apps 3
S Voraussetzungen für Android-Apps Android & Cross-Platform Mobile Apps 7
R Sinnvoller Ablageort für Leveldaten Android & Cross-Platform Mobile Apps 8
B App bei Play-Store für bestimmte auflösungen anbieten? Android & Cross-Platform Mobile Apps 3
G extends Activity für Berechnungen? Android & Cross-Platform Mobile Apps 7
H Progrämmchen für Symbian Android & Cross-Platform Mobile Apps 4
G wiederkehrenden Wert für Design in XML ablegen Android & Cross-Platform Mobile Apps 2
L Android SearchBox für Custom Listview Android & Cross-Platform Mobile Apps 5
T Android KontrollApp für Nitrado Server Android & Cross-Platform Mobile Apps 2
L Android Eine Kleinigkeit für Profis Android & Cross-Platform Mobile Apps 2
G Android C++ Quellcode für Android Geräte compilieren Android & Cross-Platform Mobile Apps 2
T Zeit in zwei Zahlen für Widget zerlegen Android & Cross-Platform Mobile Apps 2
J Apps für Android programmieren - Android Handy notwendig oder reicht Simulator? Android & Cross-Platform Mobile Apps 3
A Android SimpleDateFormat gibt für Date unter android anderes Datum zurück als in Std. Java Android & Cross-Platform Mobile Apps 2
H Android Landscape Modus für App dektivieren Android & Cross-Platform Mobile Apps 3
M Frage zu Java Programm für Windows Mobile 6.5 Android & Cross-Platform Mobile Apps 2
H Welches JDK für Huawei G7002? Android & Cross-Platform Mobile Apps 6
C Panel/View für Android Android & Cross-Platform Mobile Apps 3
C Sanke für Android Android & Cross-Platform Mobile Apps 3
Kukulkan Welche Mindestanforderungen (JDK) für Android und BB? Android & Cross-Platform Mobile Apps 8
G Views für verschiedenen Bildschirmgroeßen Android & Cross-Platform Mobile Apps 2
thE_29 Widget für verpasste Anruf + SMS Android & Cross-Platform Mobile Apps 2
A Android Android Parameter für VM Android & Cross-Platform Mobile Apps 7
O Entwickler für Java Anwendungen auf Handy gesucht! Android & Cross-Platform Mobile Apps 3
S JButton in GUI für Handys? Android & Cross-Platform Mobile Apps 3
M Welche Datenbank für J2ME? Android & Cross-Platform Mobile Apps 5
D Event für Tastensperre? Android & Cross-Platform Mobile Apps 3
G WTK für Nokia Android & Cross-Platform Mobile Apps 2
P bestimmte API für XDA ORBIT2 Android & Cross-Platform Mobile Apps 3
S Idee gesucht für ein kleines Programm Android & Cross-Platform Mobile Apps 3
M ein image pixel für pixel aufbauen : setPixel() ? Android & Cross-Platform Mobile Apps 1
M Handyprogramm für U-Bahn-Fahrplan für Siemens SK65 Android & Cross-Platform Mobile Apps 2
J Empfehlungen für ME-Anfänger Android & Cross-Platform Mobile Apps 2
K Anwendung für Handy programmieren Android & Cross-Platform Mobile Apps 1
P Java für PDA DELL Axim 51 Android & Cross-Platform Mobile Apps 4
M Virtuelle Machiene für PDA Android & Cross-Platform Mobile Apps 8
B Programm für NokiaComunicator erstellen Android & Cross-Platform Mobile Apps 2
K Programme für Handy erstellen Android & Cross-Platform Mobile Apps 3
M Java-Programme für Handy auf Desktop-PC ausführen Android & Cross-Platform Mobile Apps 4
T Für Handy Game die Sprache umschreiben? Android & Cross-Platform Mobile Apps 24
M java game für handy mit grahi. oberfläche Android & Cross-Platform Mobile Apps 1
D java.security.MessageDigest (für ME?) Android & Cross-Platform Mobile Apps 1
N Unser Team such Coder für Spieleprojekte Android & Cross-Platform Mobile Apps 8
B WTK für Sony Ericsson? Android & Cross-Platform Mobile Apps 7
S JAVA für java-mobiltelefone Android & Cross-Platform Mobile Apps 14

Ähnliche Java Themen

Neue Themen


Oben