Problem is that last week Google Sign-in button worked, but i deleted whole project and started all over again.
Only thing in code what i changed was that i used <ImageButton> instead of <Button>. Can that be the reason or is there something else? When i debug project with my own device via USB, it doesn't even make "click" noise when ImageButton is clicked.
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">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="false"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/Theme.Askola"
tools:targetApi="31">
<activity
android:name=".feature.homepage.MainActivity"
android:exported="false" />
<activity
android:name=".feature.auth.LoginActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
login_activity.xml
<?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"
android:background="@color/wine"
tools:context=".feature.auth.LoginActivity">
<ImageView
android:id="@+id/askolaimg"
android:contentDescription="@string/app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/askolanega"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/loginBtn"
android:layout_width="273dp"
android:layout_height="73dp"
android:backgroundTint="@color/wine"
android:contentDescription="@string/btnTxt"
android:scaleType="fitCenter"
android:src="@drawable/google_sign"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/askolaimg"
app:layout_constraintVertical_bias="0.556" />
LoginActivity.java
public class LoginActivity extends AppCompatActivity {
SignInClient oneTapClient;
BeginSignInRequest signInRequest;
ImageButton button;
private static final int REQ_ONE_TAP = 2; // Can be any integer unique to the Activity.
private boolean showOneTapUI = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
button = findViewById(R.id.loginBtn);
oneTapClient = Identity.getSignInClient(this);
signInRequest = BeginSignInRequest.builder()
.setGoogleIdTokenRequestOptions(BeginSignInRequest.GoogleIdTokenRequestOptions.builder()
.setSupported(true)
// Your server's client ID, not your Android client ID.
.setServerClientId(getString(R.string.web_client_id))
// Only show accounts previously used to sign in.
.setFilterByAuthorizedAccounts(true)
.build())
// Automatically sign in when exactly one credential is retrieved.
.build();
ActivityResultLauncher<IntentSenderRequest> activityResultLauncher =
registerForActivityResult(new ActivityResultContracts.StartIntentSenderForResult(), new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if (result.getResultCode() == Activity.RESULT_OK){
try {
SignInCredential credential = oneTapClient.getSignInCredentialFromIntent(result.getData());
String idToken = credential.getGoogleIdToken();
if (idToken != null) {
String email = credential.getId();
Toast.makeText(getApplicationContext(), "Email: "+email, Toast.LENGTH_SHORT).show();
}
} catch (ApiException e) {
e.printStackTrace();
}
}
}
});
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
oneTapClient.beginSignIn(signInRequest)
.addOnSuccessListener(LoginActivity.this, new OnSuccessListener<BeginSignInResult>() {
@Override
public void onSuccess(BeginSignInResult result) {
IntentSenderRequest intentSenderRequest =
new IntentSenderRequest.Builder(result.getPendingIntent().getIntentSender()).build();
activityResultLauncher.launch(intentSenderRequest);
}
})
.addOnFailureListener(LoginActivity.this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// No Google Accounts found. Just continue presenting the signed-out UI.
Log.d("TAG", e.getLocalizedMessage());
}
});
}
});
}
}
Tried to set intent filters .LAUNCHER and .DEFAULT, android.intent.action.(different commands). Thank you, appreciate already!