سؤال

I´m new to android and i´m using the first time webview, fragment, drawer...

I have the problem that with my code after pressing fullscreen in the video my app is crashing. And i have no idea what is going wrong...

WebViewFragmentVideos

    public class WebViewFragmentVideos extends Fragment {
    WebView webView;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        // Retrieving the currently selected item number
        int position = getArguments().getInt("position");

        String url = getArguments().getString("url");

        // List of rivers
        String[] menus = getResources().getStringArray(R.array.Websitesenglish);

        // Creating view corresponding to the fragment
        View v = inflater.inflate(R.layout.fragment_layout, container, false);

        // Updating the action bar title
        getActivity().getActionBar().setTitle(menus[position]);

        //Initializing and loading url in webview
        webView = (WebView)v.findViewById(R.id.webView);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setLoadsImagesAutomatically(true);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.loadUrl(url);
        webView.setWebChromeClient(new MyChromeClient());

        webView.setWebViewClient(new WebViewClient(){


            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url){
              view.loadUrl(url);
              return true;
            }

        });
        return v;}

class MyChromeClient extends WebChromeClient {
    String url = getArguments().getString("url");
    @Override
    public void onShowCustomView(View view, CustomViewCallback callback) {

        Intent intent = new Intent(null, LandVideoAct.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra("video", url);
        startActivity(intent); 
}
    }
        }

and LandVideoAct

    public class LandVideoAct extends Activity {
    WebView webView, fullweb;
    String url = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setTheme(android.R.style.Theme_Light_NoTitleBar_Fullscreen);
        setContentView(R.layout.landfull);
        url = getIntent().getStringExtra("video") + "?fs=1";
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        webView = (WebView) findViewById(R.id.fullwebview);

        if (Build.VERSION.SDK_INT < 8) {
            webView.getSettings().setPluginsEnabled(true);
        } else {
            webView.getSettings().setPluginState(PluginState.ON);
        }
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onShowCustomView(View view, CustomViewCallback callback) {
                LandVideoAct.this.finish();
            }
        });
        webView.loadUrl(url);

}}

I hope you dudes can help me with my problem. Thank you!!

هل كانت مفيدة؟

المحلول

this piece of line of code is not allowed in android.

Intent intent = new Intent(null, LandVideoAct.class);

coming to your crash problem. Its mainly because of a above line of code. When full screen of video in webview is called , its gives call to android system ie onShowCustomView(View view, CustomViewCallback callback). Where you above line of code is failing. instead of that use activity context or application context

 Intent intent = new Intent(context, LandVideoAct.class);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top