Service Leaked Error - java

hi guys im getting this error in my log cat and i dont know how to fix..
android.app.ServiceConnectionLeaked: Activity com.example.harrops.h20droidapp.webstreamsListview has leaked ServiceConnection azy#236e1451 that was originally bound here
i have a list view that when an item is clicked it opens a webview for that item. i also have a webclient set up for this as i need the webpage have its own custom loading dialog and also if it opens certain links it will open them in the factory browser. any help or incite into what is going on would be greatly appreciated
this is my webstreamsListview
#Override
public void onSaveInstanceState(Bundle outState) {
wv.saveState(outState);
}
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webstreams_listview);
if (savedInstanceState == null) {
mAdView = (AdView) findViewById(R.id.webstreams_adview);
mAdView2 = (AdView) findViewById(R.id.webstreams_adview1);
lv = (ListView) findViewById(R.id.lvWebstreamingSites);
lv.setScrollbarFadingEnabled(false);
lv.setAdapter(new webStreamsAdapter(this));
wv = (WebView) findViewById(R.id.wvWebStreamingSites);
final AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
mAdView.loadAd(adRequest);
lv.setOnItemClickListener(new CastingOnitemListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position) {
case 0:
wv.setScrollbarFadingEnabled(false);
wv.getSettings().setJavaScriptEnabled(true);
wv.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
wv.getSettings().setRenderPriority(WebSettings.RenderPriority.NORMAL);
wv.getSettings().setLoadsImagesAutomatically(true);
wv.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
if (Build.VERSION.SDK_INT >= 19) {
// chromium, enable hardware acceleration
wv.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else {
// older android version, disable hardware acceleration
wv.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
wv.canGoBackOrForward(1);
wv.getSettings().setLoadWithOverviewMode(true);
wv.getSettings().setUseWideViewPort(true);
wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
wv.setPadding(0, 0, 0, 0);
wv.setWebViewClient(new webclient1(dialog, c));
wv.loadUrl(MY URL);
break;
and this is my webclient class
public class webclient1 extends WebViewClient {
View v;
ProgressDialog dg;
public webclient1(ProgressDialog dialog, Context c) {
this.dg = dialog;
dg = new ProgressDialog(c,R.style.CustomDialog);
dg.setTitle("H20 its an app thing ...");
dg.setIcon(R.drawable.h20_dialog_logo);
dg.setMessage("Please wait...");
}
#Override
public boolean shouldOverrideUrlLoading(WebView webView, String urlNewString) {
webView.getSettings().setSupportMultipleWindows(true);
webView.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(urlNewString)));
return true;
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
view.setVisibility(View.GONE);
dg.show();
}
#Override
public void onPageFinished(WebView view, String url) {
view.setVisibility(View.VISIBLE);
dg.dismiss();
}
}

ok guys i think it was because of my custom webclient still passing services after the webview was closed this is how ive fixed it.
i did this void method in my webstreamslistview class which clears everything once the webpage is destroyed
#Override
protected void onDestroy() {
super.onDestroy();
wv.removeAllViews();
wv.clearHistory();
wv.clearCache(true);
wv.clearView();
wv.destroy();
wv= null;
}

Related

How to remove Nav from WebView, when I Navigate one page to another page in Android Studio?

//Declaration
public class DealerLoginActivity extends AppCompatActivity {
WebView webView;
ProgressBar progressBar;
AdView mAdView;
String url = "http://farmech.bih.nic.in/FMNEW/MDealerLoginNew.aspx";
// Initialization
#SuppressLint("SetJavaScriptEnabled")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dealer_login);
webView = findViewById(R.id.web_views);
new MyAsynTask().execute();
progressBar = findViewById(R.id.progress_login);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("ca-app-pub-7657536360406007/9152366791");
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
// Using Jsoup library for removing Header, Nav and Footer.
#SuppressLint("StaticFieldLeak")
private class MyAsynTask extends AsyncTask<Void, Void, Document> {
#Override
protected Document doInBackground(Void... voids) {
Document document = null;
try {
document = Jsoup.connect(url).get();
document.getElementsByTag("header").remove();
document.getElementsByTag("nav").remove();
document.getElementsByTag("footer").remove();
} catch (IOException e) {
e.printStackTrace();
}
return document;
}
//After background task Success post Execute show all the data.
#Override
protected void onPostExecute(final Document document) {
super.onPostExecute(document);
webView.loadDataWithBaseURL(url, document.toString(), "text/html", "utf-8", "");
webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
}
});
}
}
}
// This code works fine for opening Url, didn't show any footer,header and nav,(https://i.stack.imgur.com/j3ZIp.jpg ) but after clicking on submit or any other link which are available in WebView(url) then it will show header,nav and footer ( https://i.stack.imgur.com/ByAgz.jpg ) how can i fix this .....how to remove permanent remove from webview
Probably an approach could be override onPageFinished method and inject javascript in order to remove these html elements.
#Override
public void onPageFinished(WebView view, String url) {
view.loadUrl("javascript:var footer = document.getElementById(\"footer\"); footer.parentNode.removeChild(footer); var header = document.getElementById(\"header\"); header.parentNode.removeChild(header);");
}
And make sure you have enable javascript
webSettings.setJavaScriptEnabled(true);

How to create a class or method for multiple instance of webview

I have 3 fragments with their 3 layouts in tablayout. All three layout have their individual webview, swipeRefreshLayout and a progress bar. Currently I copy paste the same code in all three fragments . I want to make a class or a single method such that the changes i make in it will reflect on all three webview setting in the fragment
Below is my fragment, I just copy and paste the code below in all three fragments & only change the url.
public class Yahoo extends Fragment {
final String url = "http://www.yahoo.com/";
private WebView webView;
private ProgressBar progressBar1;
private SwipeRefreshLayout mSwipeRefreshLayout1;
public Yahoo() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_tab13, container, false);
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
progressBar1 = (ProgressBar) view.findViewById(R.id.progressBar1);
webView = (WebView) view.findViewById(R.id.website_detail_1);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
progressBar1.setProgress(progress);
if (progress == 100) {
progressBar1.setVisibility(View.GONE);
if (mSwipeRefreshLayout1.isRefreshing()) {
mSwipeRefreshLayout1.setRefreshing(false);
}
} else {
progressBar1.setVisibility(View.VISIBLE);
}
}
});
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webView.loadUrl(url);
mSwipeRefreshLayout1 = (SwipeRefreshLayout) view.findViewById(R.id.swipe1);
mSwipeRefreshLayout1.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
webView.loadUrl(url);
}
});
webView.setOnKeyListener(new View.OnKeyListener() {
#Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
webView.goBack();
return true;
}
return false;
}
});
}
#Override
public void onDestroy() {
super.onDestroy();
// Log.d("Yahoo webview", "destroy");
if (webView != null) {
webView.removeAllViews();
webView.destroy();
}
webView = null;
}
}
Could you help me out as how to create a class and and handle objects like webview , progress bar & swipeRefreshLayout such that I dont have to duplicate the same code in all three fragments ?
One thing I can suggest is that you create a single Fragment class, then create 3 instances of it using different urls.
So you will have one fragment class and one layout for it. And then you just instantiate them with different urls (if url is the only difference between them)

one webView for multiple classes

i have loads of links that open specific webpages. at the moment they are opening in browser.They are in many different classes, what i want to do is have one web View i can inflate or run that will respond to which ever activity i am running. ie so i can open downloads.class webpages, tutorials.class webpages. all from one web View. instead of a web view for every class. i think im explaining my self correctly but i am unsure of how to even start doing this my self. hoped you guys could help thanks
this is some of the code im using so far. but because its a fragment i cant do a public constructor. i want to be able to use the String url init to change the Url from another class
public class WebViewFragment extends Fragment {
private String curURL;
public void init(String url) {
curURL = url;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View view = inflater
.inflate(R.layout.webviewlayout, container, false);
init("http://www.mediafire.com/download/ezbkyava2qz44b5/AllCast.apk");
if (curURL != null) {
WebView webview = (WebView) view.findViewById(R.id.DownloadWebNav);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new webClient());
webview.loadUrl(curURL);
webview.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
}
return view;
}
private class webClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
}
}
you can achieve this with a simple java enum technique.Lets say you have three web views that you wish to trigger from the same activity one at a time.
public enum MenuType {
ABOUTUS, FAQS, TERMSANDCONDITION
}
Activity/fragment having three buttons that launches the webview
// in OnCreate
Button mClickButton1 = (Button)findViewById(R.id.clickButton1);
mClickButton1.setOnClickListener(this);
Button mClickButton2 = (Button)findViewById(R.id.clickButton2);
mClickButton2.setOnClickListener(this);
Button mClickButton3 = (Button)findViewById(R.id.clickButton3);
mClickButton3.setOnClickListener(this);
// somewhere else in your code
public void onClick(View v) {
switch (v.getId()) {
case R.id.clickButton1: {
// launch ABOUT US webview.
startWebViewActivity(MenuType.ABOUTUS);
break;
}
case R.id.clickButton2: {
// launch FAQS webview.
startWebViewActivity(MenuType.FAQS);
break;
}
case R.id.clickButton3: {
// launch TERMSANDCONDITION webview.
startWebViewActivity(MenuType.TERMSANDCONDITION);
break;
}
default:
break;
}
// method triggered when button clicked
private void startWebViewActivity(MenuType menuType) {
Intent intent = new Intent(this, WebViewActivity.class);
intent.putExtra(WebViewActivity.INTENT_MENUTYPE, menuType);
startActivity(intent);
}
WebViewActivity.java class
public class WebViewActivity extends AppCompactActivity {
public static final String INTENT_MENUTYPE = "intent_menu_type";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* webview layout with <Framelayout> as a child having id =container
that gets replaced by a fragment at run time.
[make your own layout here]
*/
setContentView(R.layout.activity_webview);
Bundle bundle = getIntent().getExtras();
if (bundle != null && bundle.containsKey(INTENT_MENUTYPE)) {
MenuType menuType = (MenuType) bundle.getSerializable(INTENT_MENUTYPE);
openFragment(WebViewFragment.newInstance(menuType));
}
}
public void openFragment(Fragment fragment) {
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
ft.replace(R.id.container,
fragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.addToBackStack(null);
ft.commitAllowingStateLoss();
}
}
WebViewFragment.java
public class WebViewFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
private static final String TAG = WebViewFragment.class.getSimpleName();
WebView mWebView;
private MenuType mMenuType;
private String mUrl;
SwipeRefreshLayout mPullToLoad;
public static WebViewFragment newInstance(MenuType menuType) {
WebViewFragment fragment = new WebViewFragment();
fragment.setMenuType(menuType);
return fragment;
}
public void setMenuType(MenuType menuType) {
this.mMenuType = menuType;
}
public WebViewFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
if (mMenuType == MenuType.ABOUTUS) {
mUrl = " valid about us url";
} else if (mMenuType == MenuType.FAQS) {
mUrl = " valid FAQS url";
} else if (mMenuType == MenuType.TERMSANDCONDITION) {
mUrl = "valid terms and conditions url";
}
View view = inflater.inflate(R.layout.fragment_webview,
container, false);
// initialize views here.
int progressColor1 = ContextCompat.getColor(mContext, R.color.primary_color);
int progressColor2 = ContextCompat.getColor(mContext, R.color.primary_color_dark);
int progressColor3 = ContextCompat.getColor(mContext, R.color.dark_blue);
int progressColor4 = ContextCompat.getColor(mContext, R.color.light_orange);
mPullToLoad.setColorSchemeColors(progressColor2,progressColor3,progressColor4,progressColor1);
mPullToLoad.setOnRefreshListener(this);
return view;
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDisplayZoomControls(true);
webSettings.setSupportZoom(true);
webSettings.setUseWideViewPort(true);
webSettings.setBuiltInZoomControls(true);
mWebView.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
showRefreshDialog();
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
dismissRefreshDialog();
}
});
mWebView.loadUrl(mUrl);
}
#Override
public void onRefresh() {
if(mWebView !=null) {
mWebView.loadUrl(mUrl);
}
}
public void showRefreshDialog() {
mPullToLoad.post(new Runnable() {
#Override
public void run() {
if(mPullToLoad != null)
mPullToLoad.setRefreshing(true);
}
});
}
public void dismissRefreshDialog() {
if(mPullToLoad!=null && mPullToLoad.isShown() )
mPullToLoad.setRefreshing(false);
}
}
fragment_webview.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/pull_to_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
hope this helps!!

onBackPressed() crashes my webview app

I am new to android development, I have tried to override onBackPress() to implement webView.GoBack(). But on pressing back key my apps getting crashed. Here is my MainActivity.java code. Am I doing something wrong ??
public class MainActivity extends AppCompatActivity {
private WebView webview;
/** Called when the activity is first created. */
public void onBackPressed (){
if (webview.isFocused() && webview.canGoBack()) {
webview.goBack();
}
else {
super.onBackPressed();
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView view = (WebView) findViewById(R.id.webView);
view.getSettings().setJavaScriptEnabled(true);
view.setWebViewClient(new MyCustomWebViewClient());
view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
view.loadUrl("http://url");
}
private class MyCustomWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
//hide loading image
findViewById(R.id.imageLoading1).setVisibility(View.GONE);
//show webview
findViewById(R.id.webView).setVisibility(View.VISIBLE);
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
if (view.canGoBack()) {
view.goBack();
} else {
view.loadUrl("file:///android_asset/index.html");
}
Toast.makeText(getBaseContext(), description, Toast.LENGTH_LONG).show();
}
}
}
Just because your webView is null. You are not referencing it anywhere. Modified your code.
public class MainActivity extends AppCompatActivity {
private WebView view;
/** Called when the activity is first created. */
public void onBackPressed (){
if (view.isFocused() && view.canGoBack()) {
view.goBack();
}
else {
super.onBackPressed();
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
view = (WebView) findViewById(R.id.webView);
view.getSettings().setJavaScriptEnabled(true);
view.setWebViewClient(new MyCustomWebViewClient());
view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
view.loadUrl("http://url");
}
private class MyCustomWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
//hide loading image
findViewById(R.id.imageLoading1).setVisibility(View.GONE);
//show webview
findViewById(R.id.webView).setVisibility(View.VISIBLE);
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
if (view.canGoBack()) {
view.goBack();
} else {
view.loadUrl("file:///android_asset/index.html");
}
Toast.makeText(getBaseContext(), description, Toast.LENGTH_LONG).show();
}
}
}
In onCreate you have:
WebView view = (WebView) findViewById(R.id.webView);
The WebView you have defined at the top has not been initialized, and is the one being used by the onBackPressed method, to fix this all you need to do is remove WebView before initializing the variable in onCreate:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
view = (WebView) findViewById(R.id.webView);
view.getSettings().setJavaScriptEnabled(true);
view.setWebViewClient(new MyCustomWebViewClient());
view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
view.loadUrl("http://url");
}
Actually you can not do directly inside the fragment. The onBackPressed can be overridden in the FragmentActivity. What you can do is:
1.Override the onBackPressed inside the activity.
2.When the onBackPressed is called, check if the instance of the current fragment is the instance showing the webview.
3.If it is, ask the fragment if the webview can go back.
4.If it is not, call the super or whatever you need
#Override
public void onBackPressed() {
Fragment webview = getSupportFragmentManager().findFragmentByTag("webview");
if (webview instanceof MyWebViewFragment) {
boolean goback = ((MyWebViewFragment)webview).canGoBack();
if (!goback)
super.onBackPressed();
}
}

display Interstitial onclick or open url

i want to display Interstitial onclick or open url ..
in webview
plz help me
my ShowWebViev.java :
public class ShowWebView extends Activity {
//private Button button;
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_web_view);
AdView mAdView = (AdView) findViewById(R.id.adView );
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
//Get webview
webView = (WebView) findViewById(R.id.webView1);
startWebView("http://MYsite");
}
public class ShowWebView extends Activity {
private InterstitialAd interstitial;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_web_view);
// Create the interstitial.
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("ca-app-pub-555555555555555/12334567890");
// Create ad request.
AdRequest adRequest = new AdRequest.Builder().build();
// Begin loading your interstitial.
interstitial.loadAd(adRequest);
}
// Invoke displayInterstitial() when you are ready to display an interstitial.
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
}
private void startWebView(String url) {
//Create new webview Client to show progress dialog
//When opening a url or click on link
webView.setWebViewClient(new WebViewClient() {
ProgressDialog progressDialog;
//If you will not use this method url links are opeen in new brower not in webview
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("rtmp:") | url.endsWith(".m3u8") | url.startsWith("http://212.35.75.130")) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setComponent(new ComponentName("com.xmtvplayer.watch.live.streams", "org.zeipel.videoplayer.XMTVPlayer"));
intent.setData(Uri.parse(url));
intent.putExtra("secure_uri", true);
startActivity(intent);
return true;
} else{
Toast.makeText(getApplicationContext(), "tv", Toast.LENGTH_SHORT).show(); }
return false;
}
/*/Show loader on url load
public void onLoadResource (WebView view, String url) {
if (progressDialog == null) {
// in standard case YourActivity.this
progressDialog = new ProgressDialog(ShowWebView.this);
progressDialog.setMessage("Loading... plz download XMTV Player To Watch Channel");
progressDialog.show();
}
}*/
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
startWebView("file:///android_asset/myerrorpage.html");
}
public void onPageFinished(WebView view, String url) {
try{
if (progressDialog.isShowing()) {
progressDialog.dismiss();
progressDialog = null;
}
}catch(Exception exception){
exception.printStackTrace();
}
}
});
// Javascript inabled on webview
webView.getSettings().setJavaScriptEnabled(true);
// Other webview options
/*
webView.getSettings().setUseWideViewPort(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
webView.getSettings().setBuiltInZoomControls(true);
*/
/*
String summary = "<html><body>You scored <b>192</b> points.</body></html>";
webView.loadData(summary, "text/html", null);
*/
//Load url in webview
webView.loadUrl(url);
webView.clearHistory();
}
#Override
public boolean onCreateOptionsMenu (Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_main, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == R.id.ref){
webView.reload();
return true;
}
return super.onOptionsItemSelected(item);
}
Regarding docs of xmtv player, you can use startActivityForResult instead of startActivity. You can call your Interstitial Ad on event onActivityResult.
public void XMTVPlayerPlayUri(String Title,String uri){
// [String] adszone - get zone id after filling form.
// [Integer] adstime - how long ad will stay before user will able to close it, value is in seconds.
Bundle bnd = new Bundle();
bnd.putString("path", uri);
bnd.putString("name", Title);
bnd.putString("adszone", "15E56089-CB15-4AA7-8D1B-574E899DE009"); // change adszone with your own id.
bnd.putInt("adstime",30);
Intent intent = new Intent();
intent.setClassName("com.xmtvplayer.watch.live.streams","org.zeipel.videoplayer.XMTVPlayer");
intent.putExtras(bnd);
startActivityForResult(intent, 100);
}

Categories