Please help with viewing web page

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Please help with viewing web page

Postby dreamdelerium » Tue Feb 09, 2010 12:25 am

can anyone tell me why this works for android 1.1 but anything above it doesnt work:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class Help extends Activity
  3.  
  4. {
  5.  
  6.         WebView webview;
  7.  
  8.     /** Called when the activity is first created. */
  9.  
  10.     @Override
  11.  
  12.     public void onCreate(Bundle savedInstanceState)
  13.  
  14.     {
  15.  
  16.         super.onCreate(savedInstanceState);
  17.  
  18.         setContentView(R.layout.help);
  19.  
  20.  
  21.  
  22.         webview = (WebView) findViewById(R.id.webview);
  23.  
  24.        webview.getSettings().setJavaScriptEnabled(true);
  25.  
  26.         webview.loadUrl("file:///android_asset/help.html");
  27.  
  28.  
  29.  
  30.  
  31.  
  32.     }
  33.  
  34.    
  35.  
  36.     public boolean onCreateOptionsMenu(Menu menu)
  37.  
  38.     {
  39.  
  40.         super.onCreateOptionsMenu(menu);
  41.  
  42.         MenuItem item = menu.add("Return To Game");
  43.  
  44.        
  45.  
  46.  
  47.  
  48.         return true;
  49.  
  50.     }
  51.  
  52.     public boolean onOptionsItemSelected(MenuItem item)
  53.  
  54.     {  
  55.  
  56.       if (item.hasSubMenu() == false)
  57.  
  58.       {
  59.  
  60.           if (item.getTitle() == "Return To Game")
  61.  
  62.           {
  63.  
  64.    
  65.  
  66.                   Intent intent = new Intent();
  67.  
  68.               setResult(RESULT_OK, intent);
  69.  
  70.               finish();
  71.  
  72.                  
  73.  
  74.           }
  75.  
  76.        
  77.  
  78.    
  79.  
  80.       }
  81.  
  82.        
  83.  
  84.      return true;
  85.  
  86.     }
  87.  
  88. }
  89.  
  90.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
dreamdelerium
Developer
Developer
 
Posts: 30
Joined: Fri Jan 01, 2010 11:19 pm

Top

Postby mitutitu » Tue Feb 09, 2010 8:09 am

Hi dreamdelerium, I think your code is okay. But the problem is for another reason. If you built your apk with sdk 1.1 then it will not work for other versions. The reason is the minSdkVersion number of your menifest file. For more info about it you should go through these links :

What is API level?
What is Versioning?
Uses Sdk

This is important:
If a android:minSdkVersion attribute is declared, its value must be less than or equal to the system's API Level integer. If not declared, the system assumes that the application requires API Level 1.


Hoping it'll help you.

Regards,
mitu
User avatar
mitutitu
Senior Developer
Senior Developer
 
Posts: 113
Joined: Tue Jun 09, 2009 7:40 am
Location: St. John's, NL, Canada

thanks

Postby dreamdelerium » Tue Feb 09, 2010 4:33 pm

thank you for your reply. Im not sure, then, I understand what minSdkVersion means? i assumed it was the minimum level required to run, anything above would work ok. (ie, if you declare it to be 1 than subsequent versions would work but if you declared it 3, than anything above would work but not below). also, the app works fine, its just not that activity that works. I did find another example and used that, and it seems to work. heres what i did:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class Help extends Activity {
  3.  
  4.  
  5.  
  6.     private static final String LOG_TAG = "WebViewDemo";
  7.  
  8.  
  9.  
  10.     private WebView mWebView;
  11.  
  12.  
  13.  
  14.     private Handler mHandler = new Handler();
  15.  
  16.  
  17.  
  18.     @Override
  19.  
  20.     public void onCreate(Bundle icicle) {
  21.  
  22.         super.onCreate(icicle);
  23.  
  24.         setContentView(R.layout.main);
  25.  
  26.         mWebView = (WebView) findViewById(R.id.webview);
  27.  
  28.  
  29.  
  30.         WebSettings webSettings = mWebView.getSettings();
  31.  
  32.         webSettings.setSavePassword(false);
  33.  
  34.         webSettings.setSaveFormData(false);
  35.  
  36.         webSettings.setJavaScriptEnabled(true);
  37.  
  38.         webSettings.setSupportZoom(false);
  39.  
  40.  
  41.  
  42.         mWebView.setWebChromeClient(new MyWebChromeClient());
  43.  
  44.  
  45.  
  46.         mWebView.addJavascriptInterface(new DemoJavaScriptInterface(), "demo");
  47.  
  48.  
  49.  
  50.         mWebView.loadUrl("file:///android_asset/help.html");
  51.  
  52.     }
  53.  
  54.  
  55.  
  56.     final class DemoJavaScriptInterface {
  57.  
  58.  
  59.  
  60.         DemoJavaScriptInterface() {
  61.  
  62.         }
  63.  
  64.  
  65.  
  66.         /**
  67.  
  68.          * This is not called on the UI thread. Post a runnable to invoke
  69.  
  70.          * loadUrl on the UI thread.
  71.  
  72.          */
  73.  
  74.         public void clickOnAndroid() {
  75.  
  76.             mHandler.post(new Runnable() {
  77.  
  78.                 public void run() {
  79.  
  80.                     mWebView.loadUrl("javascript:wave()");
  81.  
  82.                 }
  83.  
  84.             });
  85.  
  86.  
  87.  
  88.         }
  89.  
  90.     }
  91.  
  92.  
  93.  
  94.     /**
  95.  
  96.      * Provides a hook for calling "alert" from javascript. Useful for
  97.  
  98.      * debugging your javascript.
  99.  
  100.      */
  101.  
  102.     final class MyWebChromeClient extends WebChromeClient {
  103.  
  104.         @Override
  105.  
  106.         public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
  107.  
  108.             Log.d(LOG_TAG, message);
  109.  
  110.             result.confirm();
  111.  
  112.             return true;
  113.  
  114.         }
  115.  
  116.     }
  117.  
  118. }
  119.  
  120.  
  121.  
  122.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


I'd still like to know why, though
dreamdelerium
Developer
Developer
 
Posts: 30
Joined: Fri Jan 01, 2010 11:19 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 7 guests