2014-03-31 32 views
0

我想在我的應用程序中充氣webview。當我點擊瀏覽器啓動,但應用程序崩潰: web視圖完成加載後,該應用程序崩潰點擊webview充氣崩潰

viewGroup = (ViewGroup)activity.findViewById(android.R.id.content); 

     activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 

     final TextView textViewCompteur ; 
     ImageView ic_close ; 

     final View inflater = activity.getLayoutInflater().inflate(R.layout.interstitial_ads, null, true); 

     webView = (WebView)inflater.findViewById(R.id.webViewSplashAds); 
     ic_close = (ImageView)inflater.findViewById(R.id.imageViewCloseSplashAds); 
     textViewCompteur = (TextView)inflater.findViewById(R.id.textViewSplashAds); 

     webView.setWebChromeClient(new WebChromeClient()); 
     webView.getSettings().setJavaScriptEnabled(true); 
     webView.setClickable(true); 

     webView.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT)); 

     AppehourTools.disableAdsScroll(webView); 

     // icone de fermeture 
     ic_close.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 

       viewGroup.removeView(inflater); 
       activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); 
       showBar(); 

      } 
     }); 

     webView.setBackgroundColor(Color.BLACK); 
     webView.loadData("<html><head><style type=\"text/css\">body{margin:0 auto;text-align:center;}</style></head><body>" 
       + array.get(0).getUrl() 
       + "</body></html>", "text/html", "utf8"); 
     Log.d("AppehourInterstitialAds", "showing ad"); 


     hideBar(); 

     webView.setWebViewClient(new WebViewClient() { 

      public void onPageFinished(WebView view, String url) { 

       int delayClose; 
       delayClose = Integer.valueOf(array.get(0).getValidDelay()); 
       viewGroup.addView(inflater); 


       new CountDownTimer(delayClose * 1000, 1000) { 

        public void onTick(long millisUntilFinished) { 

         textViewCompteur.setText(millisUntilFinished/1000 
           + " " 
           + context.getString(R.string.seconds_remaining)); 

        } 

        public void onFinish() { 

         viewGroup.removeView(inflater); 
         activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); 
         showBar(); 
        } 
       }.start(); 
      } 


      public boolean shouldOverrideUrlLoading(WebView view, String url) { 

       hideBar(); 
       viewGroup.removeView(inflater); 
       Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
       //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
       activity.startActivity(i); 

       return super.shouldOverrideUrlLoading(view, url); 

      } 
     }); 
    } 

和錯誤:

03-31 09:39:14.278: W/System.err(1825): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://details?id=air.com.goodgamestudios.empirefourkingdoms&referrer=mat_click_id=c5e82ec15ac735af3b-20140331-4066 } 

你能幫助我嗎? 謝謝

+0

您需要爲該網址安裝市場應用程序。 – Blackbelt

回答

2

如果您正在模擬器上運行此應用程序,該應用程序將崩潰,因爲未安裝「Play商店」應用程序。在運行此程序之前,請確保您的設備已安裝Play商店。

+0

感謝您在真實設備上的工作! – Flofloaud1034