🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / Android / webview oluşturma full screen yapma ve shortcut ayarlama

1-) Android - webview oluşturma 5

 

 

kaynak kodları indirme linki : https://drive.google.com/open?id=1zMZOMcAiqzPfQ6iQRbJh3EH4dIPj8QRO

 

 

manifest.xml

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<
uses-permission android:name="android.permission.INTERNET" />

 

<application
    
android:theme="@style/Theme.Design.NoActionBar"
    
android:usesCleartextTraffic="true"

... >

 

<activity android:name="com.ramazan.roketnot.MainActivity"  android:configChanges="orientation|screenSize">
    <
intent-filter>

 

-----build.grandle (module)

 

dependencies {
    
implementation 'com.github.RachitShah02:Webview-Video-Fullscreen:1.0.2'

...

}

 

-----build.grandle (project)

 

allprojects {
    
repositories {
        
google()
        jcenter()
        maven
{ url 'https://jitpack.io' }
    }
}

 

 

 

MainActivity.java

 

package com.ramazan.roketnot;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.webkit.WebViewClient;
import androidx.appcompat.app.AppCompatActivity;
import com.gurudev.fullscreenvideowebview.FullScreenVideoWebView;

public class MainActivity extends AppCompatActivity {
    
FullScreenVideoWebView webview;

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

        
appSettings = getSharedPreferences("APP_NAME", MODE_PRIVATE);
        
// Make sure you only run addShortcut() once, not to create duplicate shortcuts.
        
if(!appSettings.getBoolean("shortcut", false)) {
            addShortcut();
        }

        
webview =  findViewById(R.id.webview);
        
webview.getSettings().setJavaScriptEnabled(true);

        
if (savedInstanceState == null)
        {
            
webview.loadUrl("https://www.roketnot.com/");

        }

        

//webview.setWebViewClient(new WebViewClient());
webview.setWebViewClient(new WebViewClient() {
    
@Override
    
public boolean shouldOverrideUrlLoading(WebView view, String url) {
        
if(url != null && url.startsWith("whatsapp://"))
        {
            view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW,Uri.parse(url)));
            
return true;
        }
else if(url.startsWith("tel:")){
            
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
            startActivity(
intent);
            view.reload();
            
return true;
        }
        
else
        
{
            
return false;
        }
    }
});


    }

    
@Override
    
protected void onSaveInstanceState(Bundle outState )
    {
        
super.onSaveInstanceState(outState);
        
webview.saveState(outState);
    }

    
@Override
    
protected void onRestoreInstanceState(Bundle savedInstanceState)
    {
        
super.onRestoreInstanceState(savedInstanceState);
        
webview.restoreState(savedInstanceState);
    }


    
@Override
    
public void onBackPressed() {
        
if (webview.canGoBack()) {
            
webview.goBack();
        }
else {
            
super.onBackPressed();
        }
    }

    
private SharedPreferences appSettings;
    
private void addShortcut() {
        
//Adding shortcut for MainActivity
        //on Home screen
        
Intent shortcutIntent = new Intent(getApplicationContext(), MainActivity.class);
        
shortcutIntent.setAction(Intent.ACTION_MAIN);

        
Intent addIntent = new Intent();
        
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Roket Not");
        
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
                        
R.mipmap.ic_launcher));
        
addIntent.putExtra("duplicate", false);
        
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        getApplicationContext().sendBroadcast(
addIntent);

        
SharedPreferences.Editor prefEditor = appSettings.edit();
        
prefEditor.putBoolean("shortcut", true);
        
prefEditor.commit();
    }

}

 

activity_main.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"
    
tools:context=".MainActivity">

<!--    <WebView-->
<!--        android:id="@+id/webview"-->
<!--        android:layout_width="match_parent"-->
<!--        android:layout_height="match_parent" />-->

    
<com.gurudev.fullscreenvideowebview.FullScreenVideoWebView
        
android:id="@+id/webview"
        
android:layout_width="match_parent"
        
android:layout_height="match_parent" />

</
androidx.constraintlayout.widget.ConstraintLayout>

 

 

 

 

 

 

 

 

 

 

 

 2021 Kasım 26 Cuma
 548