Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1023223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:35:02+00:00 2026-05-16T11:35:02+00:00

I was reading over http://android-developers.blogspot.com/2009/04/backward-compatibility-for-android.html But I’m really not grasping how to ignore certain

  • 0

I was reading over http://android-developers.blogspot.com/2009/04/backward-compatibility-for-android.html But I’m really not grasping how to ignore certain lines of code. I have this Activity (posted below) and it’s a simple webview. However, I want to have geolocation enabled(even if it is only for 2.0 and up phones), since these methods weren’t introduced until SDK 5 (android 2.0) and I would like the webview to be able to at the very least be able to load on a 1.5 phone rather than just crashing. Could someone possibly show me how to take this code and make it ignore the lines of code that i pointed out with the starred comments when the users phone SDK is LESS than SDK 5?

package com.my.app;

import com.facebook.android.R;
//NEEDS TO BE IGNORED**********************************************************
import android.webkit.GeolocationPermissions;
import android.webkit.GeolocationPermissions.Callback;
//END**************************************************************************
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent; 
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.webkit.CookieSyncManager;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

//GeolocationPermissionsCallback NEEDS TO BE IGNORED**********************************************************
public class Places extends Activity implements GeolocationPermissions.Callback{ 
        private ProgressDialog progressBar;
        public WebView webview;

        private static final String TAG = "Main";


        String geoWebsiteURL = "http://google.com";

        @Override 
         public void onStart()
        {
           super.onStart();


           CookieSyncManager.getInstance().sync();

        }




    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main);
        CookieSyncManager.createInstance(this);
        CookieSyncManager.getInstance().startSync();

        webview = (WebView) findViewById(R.id.webview);
        webview.setWebViewClient(new testClient());
        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setPluginsEnabled(true);
        webview.loadUrl("http://google.com");

        progressBar = ProgressDialog.show(Places.this, "", "Loading Page...");

        //THIS NEEDS TO BE IGNORED************************************************************
        webview.getSettings().setGeolocationEnabled(true);



        GeoClient geo = new GeoClient();
        webview.setWebChromeClient(geo);        

    }

    public void invoke(String origin, boolean allow, boolean remember) {

    }

    final class GeoClient extends WebChromeClient {


    @Override
    public void onGeolocationPermissionsShowPrompt(String origin,
    Callback callback) {
    super.onGeolocationPermissionsShowPrompt(origin, callback);
    callback.invoke(origin, true, false);
    }
//END OF CODE THAT NEEDS TO BE IGNORED************************************************
    }


    private class testClient extends WebViewClient { 
        @Override 
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Log.i(TAG, "Processing webview url click...");
            view.loadUrl(url);
            return true;  



        }





        public void onPageFinished(WebView view, String url) {
            Log.i(TAG, "Finished loading URL: " +url);
            if (progressBar.isShowing()) {
                progressBar.dismiss();
            }

            if (url.startsWith("mailto:") || url.startsWith("geo:") ||
                    url.startsWith("tel:")) {
                                                Intent intent = new Intent
                    (Intent.ACTION_VIEW, Uri.parse(url));
                                                startActivity(intent);
                    }
        }
    }



        public boolean onKeyDown(int keyCode, KeyEvent event) { 
            if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) { 
                webview.goBack(); 
                return true; 
            }
                if (keyCode == KeyEvent.KEYCODE_SEARCH) {

                    Intent z = new Intent(this, Search.class);
                    startActivity(z);

                  }  
            return super.onKeyDown(keyCode, event);  
            }




        public boolean onCreateOptionsMenu (Menu menu) {
            super.onCreateOptionsMenu(menu);
            MenuInflater inflater = getMenuInflater();
            inflater.inflate(R.menu.menu, menu);
            return true;
        }

    @Override
    public boolean onOptionsItemSelected (MenuItem item) {
            switch (item.getItemId()) {
            case R.id.home:
                Intent m = new Intent(this, Home.class);
                startActivity(m);
                return true;

            case R.id.refresh:
                webview.reload();
                Toast.makeText(this, "Refreshing...", Toast.LENGTH_SHORT).show();
                return true;


    }
    return false;
        }

    public void onStop()
    {
       super.onStop();

       CookieSyncManager.getInstance().sync();

        }




} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:35:02+00:00Added an answer on May 16, 2026 at 11:35 am

    There are (at least) two possible solutions for your problem:

    1. Different versions for different OS – create different builds of your software for different OS. This is a common approach, a lot of open source projects offer different builds for linux, windows, mac os. Your case is similiar, you could create different builds for android 1.5, 2.0, …

    2. One version for all Android OS – If you can find a way to detect the version of the OS at runtime, then you can redesign your code to run on different OS. You can add special classes for android 1.6 and 2.0 and make sure, that only the correct classes are loaded.

    A quick example for your code:

    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
    
        // ... 
    
        progressBar = ProgressDialog.show(Places.this, "", "Loading Page...");
    
        if (isGeolocationAvailable()) {
           Android20Util.enableGeolocation(webview);
        }        
    }
    

    Android20Util contains some static methods, like:

    public static void enableGeolocation(WebView webview) {
        webview.getSettings().setGeolocationEnabled(true);
        webview.setWebChromeClient(new GeoClient());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I was reading over something on this page ( http://gamedeveloperjourney.blogspot.com/2009/04/point-plane-collision-detection.html ) The author
I was reading this blog( http://googlepublicpolicy.blogspot.com/2009/06/https-security-for-web-applications.html ) posted by google on not enabling HTTPS
I was reading over the tutorial here: http://www.1keydata.com/sql/sql-running-totals.html and it all made sense until
I was reading over the documentation for query hints: http://msdn.microsoft.com/en-us/library/ms181714(SQL.90).aspx And noticed this: FAST
I was reading an article on Batch Processing in java over at JDJ http://java.sys-con.com/node/415321
I just finished reading Mike's awesome tutorial over at: http://www.mikesdotnetting.com/Article/150/Web-Pages-Efficient-Paging-Without-The-WebGrid and I am using
I was reading over at the Android development website about using reflections. But I'm
So I was reading over the MSDN docs and came across: http://msdn.microsoft.com/en-us/library/sf0df423.aspx What is
I've been reading over the perl doc, but I can't quite get my head
I have a simple web-API accessible over HTTP with some corresponding mobile apps reading

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.