Android
 Computer >> コンピューター >  >> プログラミング >> Android

AndroidでWebビューセッションストレージを有効にする方法は?


この例は、AndroidでWebビューセッションストレージを有効にする方法について示しています。

ステップ1 − Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力します。

ステップ2 −次のコードをres / layout/activity_main.xmlに追加します。

<?xml version = "1.0" encoding = "utf-8"?>
<LinearLayout xmlns:android = "https://schemas.android.com/apk/res/android"
   xmlns:app = "https://schemas.android.com/apk/res-auto"
   xmlns:tools = "https://schemas.android.com/tools"
   android:layout_width = "match_parent"
   android:gravity = "center"
   android:layout_height = "match_parent"
   tools:context = ".MainActivity"
   android:orientation = "vertical">
   <WebView
      android:id = "@+id/web_view"
      android:layout_width = "match_parent"
      android:layout_height = "match_parent" />
</LinearLayout>

上記のコードでは、tutorialspoint.comを表示するためにWebビューを使用しています。

ステップ3 −次のコードをsrc / MainActivity.java

に追加します
package com.example.myapplication;
import android.app.ProgressDialog;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
   @RequiresApi(api = Build.VERSION_CODES.P)
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      final ProgressDialog progressDialog = new ProgressDialog(this);
      progressDialog.setMessage("Loading Data...");
      progressDialog.setCancelable(false);
      WebView web_view = findViewById(R.id.web_view);
      web_view.requestFocus();
      web_view.getSettings().setLightTouchEnabled(true);
      web_view.getSettings().setJavaScriptEnabled(true);
      web_view.getSettings().setGeolocationEnabled(true);
      web_view.setSoundEffectsEnabled(true);
      web_view.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
      web_view.getSettings().setUseWideViewPort(true);
      // enable Web Storage: localStorage, sessionStorage
      web_view.getSettings().setDomStorageEnabled(true);
      web_view.loadUrl("https://www.tutorialspoint.com/");
      web_view.setWebChromeClient(new WebChromeClient() {
         public void onProgressChanged(WebView view, int progress) {
            if (progress < 100) {
               progressDialog.show();
            }
            if (progress = = 100) {
               progressDialog.dismiss();
            }
         }
      });
   }
}

ステップ4 −次のコードをAndroidManifest.xmlに追加します

<?xml version = "1.0" encoding = "utf-8"?>
<manifest xmlns:android = "https://schemas.android.com/apk/res/android"
   package = "com.example.myapplication">
   <uses-permission android:name = "android.permission.INTERNET"/>
   <application
      android:allowBackup = "true"
      android:icon = "@mipmap/ic_launcher"
      android:label = "@string/app_name"
      android:roundIcon = "@mipmap/ic_launcher_round"
      android:supportsRtl = "true"
      android:theme = "@style/AppTheme">
      <activity android:name = ".MainActivity">
         <intent-filter>
            <action android:name = "android.intent.action.MAIN" />
            <category android:name = "android.intent.category.LAUNCHER" />
         </intent-filter>
      </activity>
   </application>
</manifest>

アプリケーションを実行してみましょう。実際のAndroidモバイルデバイスをコンピューターに接続していると思います。 android studioからアプリを実行するには、プロジェクトのアクティビティファイルの1つを開き、ツールバーの[実行]アイコンをクリックします。オプションとしてモバイルデバイスを選択し、デフォルトの画面を表示するモバイルデバイスを確認します–

AndroidでWebビューセッションストレージを有効にする方法は?


  1. Android でグレースケール モードを有効にする方法

    Android 10 は最近、非常にクールなダーク モードをリリースし、すぐに多くのユーザーの心をつかみました。見栄えが良いだけでなく、バ​​ッテリーの節約にもなります。反転したカラー テーマにより、ほとんどのアプリの背景にある威圧的な空白が黒に置き換えられました。これにより、画面を構成するピクセルの色と光度が大幅に低下するため、消費電力が大幅に削減されます。このため、誰もが Android デバイスをダーク モードに切り替えたいと考えています。特に、屋内や夜間にデバイスを使用する場合はそうです。 Facebook や Instagram などの人気アプリはすべて、アプリ インターフェースのダ

  2. Always On Display Android を有効にする方法

    Android デバイスには、リリースされるまで必要とは考えられなかった新機能が続々と搭載されています。この伝統を引き継いで、Android は Always-on を導入しました。 特徴。ただし、最初はSamsungデバイス用にリリースされましたが、現在ではほとんどのAndroidスマートフォンに対応しています.この機能を使用すると、画面を常にオンにして、時間やその他の重要な通知を表示できます。 Always On Screen の背景は黒く、非常に暗いため、バッテリーの消費を最小限に抑えます。簡単なガイドを読み、Always on display Android を有効にする方法を学びまし