Saturday, December 17, 2011

Simple SMS Scheduler

Few weeks ago, I attended a seminar in a university. It was about gathering student resources to start a business. The club provides information about how to get fundings, mentors, etc. It also have a section about creating mobile apps. One of the guys there was talking about an SMS scheduler to send messages to his girlfriend. I found it simple and interesting.

I built the following part time:

App Name: Simple SMS Scheduler
Market Link: https://market.android.com/details?id=com.ignitesms.android

Description:

Simple SMS Scheduler is a clean and simple tool for sending automatic messages at a chosen time. 
Features:
  • Can choose recipients from contact list
  • Sent SMS shows up on default android messaging app
  • Optional delivery and sent reporting via status bar notification
  • Delivery and error history

Screenshots:





Feel free to try it out at https://market.android.com/details?id=com.ignitesms.android.

Feel free to let me know what you think. Feedback, criticisms are always welcomed.

Friday, December 16, 2011

Using javascript in webview to call native code

We will define two js functions in android

  • goToHome
  • showToast

for javacript calls from the webview.

You would call the functions like
<script type="text/javascript">
  window.jsinterface.goToHome()
  window.jsinterface.showToast()
</script>
Define the following in your android activity as an inner class.
public class JSInterface {
public void goToHome() {
Intent i = new Intent(getApplicationContext(), Home.class);
startActivity(i);
}
public void showToast(final String msg) { Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
}
}
In your onCreate function, intialize the webview similar to below:
WebView mWebView = (WebView) findViewById(R.id.webview);
mWebView.setVisibility(View.GONE);
mWebView.addJavascriptInterface(new JSInterface(), "jsinterface");
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int progress) {
Logger.v("webview", String.format("progress changed: %d", progress));
if (progress == 100) {
// webpage loaded completely
} else {
// webpage is loading
}
}
//@Override
public boolean onJsAlert(WebView view, String url,
String message, JsResult result) {
// if you do js alerts, this will show them as toast
Toast.makeText(getBaseContext(), message, Toast.LENGTH_SHORT).show();
result.confirm();
return true;
}
});

Basicly, that's it!

Android soft keyboard not showing on webview

Sometimes your webview may not show the soft keyboard.  This has to do with the focus and the timing that the webview is rendered.

If the soft keyboard does not show up, try to add the following to your webview:

mWebView.requestFocus(View.FOCUS_DOWN);
mWebView.setOnTouchListener(new View.OnTouchListener() {
       @Override
       public boolean onTouch(View v, MotionEvent event) {
           switch (event.getAction()) {
               case MotionEvent.ACTION_DOWN:
               case MotionEvent.ACTION_UP:
                   if (!v.hasFocus()) {
                       v.requestFocus();
                   }
                   break;
           }
           return false;
       }
   });