Cupid-4-stupid is now for the Nook Color and Tablet!
After going throw the whole process established by Barnes & Nobel, we accomplish to modify our Android application so it can work on the Nook Color and Nook Tablet.
Cupid-4-stupid is now for the Nook Color and Tablet!
After going throw the whole process established by Barnes & Nobel, we accomplish to modify our Android application so it can work on the Nook Color and Nook Tablet.
In the application Cupid-4-Stupid that I and my partner David W. Corrigan developed, we notice that WebView stopped working properly.
When WebView stopped working as before, two important sections of our application were affected: Date Ideas and Panic Button.
I was getting exceptions such as NullPointerException produced by android.webkit.WebViewDatabase.getInstance() at WebViewDatabase.j
After fixing this issue, we encounter other exceptions produced by CookieSyncManager.createInstance(Context) and more.
However, after doing some research, we managed to pin point the issue and fixed.
The following is a tutorial about how to create your own browser using WebView and make it work:
We assume that the browser is going to be an activity that will be called from another activity; however, that doesn’t mean that it cannot be your main activity if you wish.
<uses-permission android:name='android.permission.INTERNET' />
<activity android:name='com.hourglass.applications.BrowserActivity' android:theme='@android:style/Theme.NoTitleBar'> <intent-filter> <action android:name='com.hourglass.applications.Browser' /> <action android:name='android.intent.action.VIEW' /> <category android:name='android.intent.category.DEFAULT' /> <data android:scheme='http' /> </intent-filter> </activity>
<?xml version='1.0' encoding='utf-8'?> <LinearLayout android:id='@+id/linearLayoutRootWebView' xmlns:android='http://schemas.android.com/apk/res/android' androidrientation='vertical' android:layout_height='fill_parent' android:layout_width='fill_parent' android:background='@android:color/white'> <WebView android:id='@+id/webview' android:layout_width='fill_parent' android:layout_height='fill_parent'></WebView> </LinearLayout>
CookieSyncManager.createInstance(this);
package com.hourglassapplications; import android.app.Activity; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.DialogInterface.OnCancelListener; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.webkit.CookieSyncManager; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Button; public class BrowserActivity extends ActivityWithMenu { private static final String TAG = 'BrowserActivity'; final Activity activity = this; private static ProgressDialog progressBar; private ViewGroup viewGroupRootWebView; private View viewToRemove; private WebView webview; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.getWindow().requestFeature(Window.FEATURE_PROGRESS); // Must be called before setContentView setContentView(R.layout.browser); setUpWebView(); loadUrl(getIntent().getData().toString()); } private void setUpWebView(){ // Identify the webview provided by the resources and replace it with a webview generated by code viewGroupRootWebView = (ViewGroup) this.findViewById(R.id.linearLayoutRootWebView); viewToRemove = viewGroupRootWebView.findViewById(R.id.webview); int indexView = viewGroupRootWebView.indexOfChild(viewToRemove); webview = new WebView(this); setUpWebViewSettings(); viewGroupRootWebView.removeView(viewToRemove); viewGroupRootWebView.addView(webview, indexView); } private void setUpWebViewSettings(){ webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setBuiltInZoomControls(true); webview.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY); webview.setWebViewClient(newWebViewClient()); webview.setWebChromeClient(newWebChromeClient()); } private WebChromeClient newWebChromeClient(){ return new WebChromeClient() { public void onProgressChanged(WebView view, int progress){ activity.setTitle('Loading...'); activity.setProgress(progress * 100); if(progress == 100){ activity.setTitle(R.string.app_name); } } }; } private WebViewClient newWebViewClient() { return new WebViewClient(){ @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){ Log.e(TAG, 'onReceivedError(..., ' + errorCode + ', ' + description + ', '+ failingUrl + ')'); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } @Override public void onPageFinished(WebView view, String url) { if (progressBar != null && progressBar.isShowing()) { progressBar.dismiss(); } } }; } private void loadUrl(String strUrl){ setUpProgressBar(); webview.loadUrl(strUrl); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // If there is a web page history, go to the previous page, else follow up the system behavior if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) { webview.goBack(); return true; } return super.onKeyDown(keyCode, event); } private void setUpProgressBar(){ progressBar = new ProgressDialog(this); progressBar.setCancelable(true); progressBar.setOnCancelListener(progressBarOnCancelListener); progressBar.setMessage('Loading...'); progressBar.show(); } private final OnCancelListener progressBarOnCancelListener = new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { if (progressBar != null && progressBar.isShowing()) { progressBar.dismiss(); } } }; @Override public void onResume(){ super.onResume(); CookieSyncManager.getInstance().startSync(); } @Override public void onStop(){ super.onStop(); CookieSyncManager.getInstance().stopSync(); } @Override public void onDestroy(){ super.onDestroy(); webview.destroy(); } }
Let me know if you encounter a problem.
Today, November 28 of 2011, we released a new update of Cupid-4-Stupid!
Some customers reported a bug that they were facing when trying to access content in Date Ideas and Panic Button sections.
This bug was produced after all the Android devices got updated.
After working around we found out what was the problem and solve it. Soon, we will release a more detail explanation of how we solve it.
Get Cupid-4-Stupid here:
https://market.android.com/details?id=com.hourglassapplications
We added BugSense after encounter an error with ACRA in which was crashing the application.
The code was failing when trying to initialize acra:
try{ ACRA.init(this); // The following line triggers the initialization of ACRA }catch(RuntimeException e){ android.util.Log.e(TAG, 'ACRA init crashes: ' + e.getMessage()); e.printStackTrace(); }
Getting the following error:
10-30 22:02:37.908: WARN/System.err(2709): java.lang.NullPointerException 10-30 22:02:37.918: WARN/System.err(2709): at org.acra.ErrorReporter.init(ErrorReporter.java:363) 10-30 22:02:37.918: WARN/System.err(2709): at org.acra.ACRA.initAcra(ACRA.java:297) 10-30 22:02:37.918: WARN/System.err(2709): at org.acra.ACRA.init(ACRA.java:238) 10-30 22:02:37.918: WARN/System.err(2709): at com.hourglass.applications.MyApplication.onCreate(MyApplication.java:40) 10-30 22:02:37.918: WARN/System.err(2709): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969) 10-30 22:02:37.928: WARN/System.err(2709): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4165) 10-30 22:02:37.928: WARN/System.err(2709): at android.app.ActivityThread.access$2900(ActivityThread.java:126) 10-30 22:02:37.928: WARN/System.err(2709): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1958) 10-30 22:02:37.928: WARN/System.err(2709): at android.os.Handler.dispatchMessage(Handler.java:99) 10-30 22:02:37.928: WARN/System.err(2709): at android.os.Looper.loop(Looper.java:123) 10-30 22:02:37.928: WARN/System.err(2709): at android.app.ActivityThread.main(ActivityThread.java:4568) 10-30 22:02:37.928: WARN/System.err(2709): at java.lang.reflect.Method.invokeNative(Native Method) 10-30 22:02:37.938: WARN/System.err(2709): at java.lang.reflect.Method.invoke(Method.java:521) 10-30 22:02:37.938: WARN/System.err(2709): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 10-30 22:02:37.938: WARN/System.err(2709): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 10-30 22:02:37.938: WARN/System.err(2709): at dalvik.system.NativeStart.main(Native Method)
After spending long hours I found how that the error was produced when ErrorReporter class was not initialized.
For some reason ACRA 4.2.3 doesn’t pass the reference of the class (this) to ErrorReporter.
To fix it just implement the following:
ErrorReporter.getInstance().init(this); // include before ACRA.init(this);