#android #webview #android-webview #chrome-custom-tabs #android-customtabs
#Android #webview #android-webview #chrome-пользовательские вкладки #android-пользовательские вкладки
Вопрос:
Я довольно новичок в разработке Android и создаю простое демонстрационное приложение, чтобы опробовать функциональность пользовательских вкладок Android. Тем не менее, каким-то образом, когда я запустил приложение и протестировал его на виртуальном устройстве, я все еще вижу, что URL-адрес запускается с помощью WebView вместо пользовательских вкладок. Я что-то упустил? Большое спасибо!
* причина, по которой я пытаюсь обойти ограничение входа в Facebook / Google в настоящее время в webview
мой build.gradle
:
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.0"
defaultConfig {
applicationId "com.example.helloworld"
minSdkVersion 16
targetSdkVersion 30
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.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
testImplementation 'junit:junit:4. '
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "androidx.browser:browser:1.3.0"
}
Мой MainActivity.java:
package com.example.helloworld;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.browser.customtabs.CustomTabsIntent;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button loginBtn = findViewById(R.id.login);
loginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String loginUrl = "https://google.com";
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
customTabsIntent.launchUrl(getApplicationContext(), Uri.parse(loginUrl));
}
});
}
}
Ответ №1:
Используется PackageManager
для проверки браузера устройства в коде. https://developer.chrome.com/docs/android/custom-tabs/integration-guide /