Webview içerisinde canlı yayın izleme
09.09.2017 - 03:10
Merhaba arkadaşlar. Basit bir webview uygulaması oluşturdum. Bu uyugulama basit olarak bir web sitesini çağırıyor. bunda hiç bir sorun yok. fakat site içerisinde bir video linkine tıkladığımda (uygulama içerisinde yeni sayfaya geçiyor) ekran geliyor fakat yükleniyor olarak kalıyor ve gösterim yapmıyor.
bunu sağlayabilmek adına MainActivity de webview.setWebChromeClient (new WebChromeClient()); satırını ekleyip java script enable ı "true" olarak ayarladım
mainfest kısmında ise android:hardwareAccelerated="true" olarak ayarladım.
Bunun dışında ne yapmak gerekiyor.
örneğin basit bir webview uygulamasında https://fox.com.tr/canli-yayin nasıl çalıştırılır. (webview fox.com.tr 'yi açacak. canlı yayına biz tıklayacağız)
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.CookieManager;
import android.webkit.JsPromptResult;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.CookieSyncManager;
import com.google.firebase.analytics.FirebaseAnalytics;
import java.util.logging.Handler;
public class MainActivity extends AppCompatActivity {
WebView wv ;
private FirebaseAnalytics mFirebaseAnalytics;
@Override
public void onBackPressed(){
if (wv.canGoBack()) {
wv.goBack();
}else {
super.onBackPressed();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Context context = MainActivity.this;
SharedPreferences sharedPreferences;
boolean isAppInstalled = false;
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
CookieManager.getInstance().setAcceptCookie(true);
CookieSyncManager.createInstance(this);
CookieSyncManager.getInstance().startSync();
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
isAppInstalled= sharedPreferences.getBoolean("isAppInstalled", false);
if(isAppInstalled==false) {
Intent intent1 = new Intent(getApplicationContext(), MainActivity.class);
intent1.setAction(Intent.ACTION_MAIN);
Intent intent2 = new Intent();
intent2.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent1);
intent2.putExtra(Intent.EXTRA_SHORTCUT_NAME, "FOX");
intent2.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher));
intent2.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(intent2);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("isAppInstalled", true);
editor.commit();
}
wv = (WebView) findViewById(R.id.wv);
wv.setWebViewClient(new WebViewClient());
wv.setScrollbarFadingEnabled(true);
wv.setVerticalScrollBarEnabled(false);
wv.setHorizontalScrollBarEnabled(false);
wv.getSettings().setAllowFileAccess(true);
wv.getSettings().setAllowContentAccess(true);
wv.getSettings().setBuiltInZoomControls(false);
wv.getSettings().setUseWideViewPort(false);
wv.getSettings().setGeolocationEnabled(true);
wv.getSettings().getUserAgentString();
wv.getSettings().setDatabaseEnabled(true);
wv.getSettings().setSaveFormData(true);
wv.getSettings().setSavePassword(true);
wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
wv.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
wv.getSettings().setLightTouchEnabled(true);
wv.getSettings().setAllowFileAccessFromFileURLs(true);
wv.getSettings().setAllowUniversalAccessFromFileURLs(true);
wv.getSettings().setPluginState(WebSettings.PluginState.ON);
wv.getSettings().setJavaScriptEnabled(true);
wv.setFocusable(true);
wv.setFocusableInTouchMode(true);
wv.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
wv.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
wv.getSettings().setDomStorageEnabled(true);
wv.getSettings().setDomStorageEnabled(true);
wv.getSettings().setAppCacheEnabled(true);
wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
wv.setWebChromeClient(new WebChromeClient());
wv.loadUrl("https://www.fox.com.tr/canli-yayin");
}
}
18
Görüntülenme
0 Beğeni