1 /* 2 * Copyright 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.example.androidx.webkit; 18 19 import android.app.Activity; 20 import android.os.Bundle; 21 import android.webkit.WebView; 22 import android.webkit.WebViewClient; 23 import android.widget.TextView; 24 25 import androidx.appcompat.app.AppCompatActivity; 26 import androidx.webkit.ProcessGlobalConfig; 27 import androidx.webkit.WebViewFeature; 28 29 import org.jspecify.annotations.Nullable; 30 31 /** 32 * An {@link Activity} which makes use of 33 * {@link androidx.webkit.ProcessGlobalConfig#setDataDirectorySuffix(Context, String)}. 34 */ 35 public class DataDirectorySuffixActivity extends AppCompatActivity { 36 @Override onCreate(@ullable Bundle savedInstanceState)37 protected void onCreate(@Nullable Bundle savedInstanceState) { 38 super.onCreate(savedInstanceState); 39 setTitle(R.string.data_directory_suffix_activity_title); 40 WebkitHelpers.appendWebViewVersionToTitle(this); 41 42 if (!WebViewFeature.isStartupFeatureSupported(this, 43 WebViewFeature.STARTUP_FEATURE_SET_DATA_DIRECTORY_SUFFIX)) { 44 WebkitHelpers.showMessageInActivity(this, R.string.webkit_api_not_available); 45 return; 46 } 47 ProcessGlobalConfig config = new ProcessGlobalConfig(); 48 config.setDataDirectorySuffix(this, 49 "data_directory_suffix_activity_suffix"); 50 ProcessGlobalConfig.apply(config); 51 setContentView(R.layout.activity_data_directory_config); 52 WebView wv = findViewById(R.id.data_directory_config_webview); 53 wv.getSettings().setJavaScriptEnabled(true); 54 wv.setWebViewClient(new WebViewClient()); 55 wv.loadUrl("www.google.com"); 56 TextView tv = findViewById(R.id.data_directory_config_textview); 57 tv.setText("WebView Loaded!"); 58 } 59 } 60