webview uygulama hatası

Rapor et
Soru

Bu soru rapor edilmelidir hissediyorum neden kısaca açıklayınız.

Rapor et
İptal

Bir video izleyerek webview uygulaması yapmaya çalıştım, aşağıda belirttiğim kodlar hata veriyor. En azından neyden kaynaklandığı hakkında bir fikir verebilir misiniz ?

Hatalı kısımları büyük harfle yazdım:

 final ProgressDialog progressDialog = ProgressDialog.SHOW(CONTEXT: this, getResources().getString(R.string.app_name),
                getResources().getString(R.string.yukleniyor), İNDETERMİNATE: true);
@OVERRİDE
                public void onPageStarted(WebView view, String url, Bitmap bitmap) {
                    super.ONPAGESTARTED(view, url, bitmap);
@OVERRIDE
                public void onPageFinished(WebView webView, String url) {
                    super.ONPAGEFINISHED(webView, url);
                    progressDialog.dismiss();
@OVERRIDE
                public void onLoadResource(WebView webView, String url) {

                    super.ONLOADRESOURCE(myWebView, url);
@OVERRIDE
                public boolean shouldOverrideUrlLoading(WebView webView, String url) {

                    frameLayout.setVisibility(View.VISIBLE);
                    myWebView.loadUrl(url);
                    return true;

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context=".MainActivity">

    <WebView

        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <FrameLayout
            android:layout_height="match_parent"
            android:layout_width="match_parent">
            android:id="@+id/framelayout"
            android:layout_width="match_parent"
            android:layout_height="3dp"
            android:background="tranparent">

            <ProgressBar
                android:id="@+id/progress_horizontal"
                android:layout_width="match_parent"
                android:layout_height="10dp"
                style="?android:attr/progressBarStyleHorizontal"
                android:layout_gravity="top"
                android:progress="20"
                android:background="@android:color/transparent"
                android:progressDrawable="@drawable/custom_progress" />



        </FrameLayout>


    </LinearLayout>

</RelativeLayout>

MainActivity.java

package com.example.enwacwebview;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.ProgressBar;
import android.widget.Toast;

import java.util.Objects;

public class MainActivity extends AppCompatActivity {

    String url;
    WebView myWebView;
    Boolean connected = false;

    private ProgressBar mProgressBar;
            private FrameLayout frameLayout;


    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        url = getResources().getString(R.string.url);

        ActionBar actionBar = getSupportActionBar();
        assert actionBar != null;
        actionBar.hide();


        final ProgressDialog progressDialog = ProgressDialog.show(context: this, getResources().getString(R.string.app_name),
                getResources().getString(R.string.yukleniyor), indeterminate: true);

        frameLayout = findViewById(R.id.framelayout);
        mProgressBar = findViewById(R.id.progress_horizontal);
        mProgressBar.setMax(100);

        myWebView = findViewById(R.id.webview);

        myWebView.setWebChromeClient(new WebChromeClient() {

            public void onProgressChanged(WebView webView, int progress) {

                frameLayout.setVisibility(View.VISIBLE);
                mProgressBar.setProgress(progress);

                setTitle("Yükleniyor");

                if (progress == 100) {

                    frameLayout.setVisibility(View.GONE);
                    setTitle(webView.getTitle());

                }

                super.onProgressChanged(webView,progress);
            }

        });


        ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

        assert connectivityManager != null;
        connected = Objects.requireNonNull(connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)).getState() == NetworkInfo.State.CONNECTED || connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED;

        if (connected) {

            myWebView.setWebChromeClient(new WebChromeClient());
            myWebView.loadUrl(url);
            myWebView.getSettings().setJavaScriptEnabled(true);
            mProgressBar.setProgress(0);
            progressDialog.show();

            myWebView.setWebChromeClient(new WebChromeClient() {


                @Override
                public void onPageStarted(WebView view, String url, Bitmap bitmap) {
                    super.onPageStarted(view, url, bitmap);

                }

                @Override
                public void onPageFinished(WebView webView, String url) {
                    super.onPageFinished(webView, url);
                    progressDialog.dismiss();
                }

                @Override
                public void onLoadResource(WebView webView, String url) {

                    super.onLoadResource(myWebView, url);


                }

                @Override
                public boolean shouldOverrideUrlLoading(WebView webView, String url) {

                    frameLayout.setVisibility(View.VISIBLE);
                    myWebView.loadUrl(url);
                    return true;


                }
            });

        }

            if (!connected) {

                final Toast toast = Toast.makeText(getApplicationContext(), resid: "Lütfen internet bağlantınızı kontrol ediniz", Toast.LENGTH_LONG).show();
            }

        }
    }


AndroidManifest.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"
    package="com.example.enwacwebview">

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:allowBackup="true"
        android:fullBackupContent="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="AllowBackup">
        <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>
0
Android 5 ay 0 Cevap 167 görüntüleme Intern 2

Yazar HakkındaIntern

Cevap bırak

Gözat

KOD PAYLAŞIRKEN DİKKAT!!!!

HTML kod paylaşmak için

<pre class="html">HTML KOD</pre>
XML kod paylaşmak için
<pre class="xml">XML KOD</pre>
Diğer dillerde(php,java,android,javasvript,c# vs..) kod paylaşmak için
<pre>KOD</pre>
tagları arasında paylaşmayı unutmayın.