title: Android Calendar Content Provider query keeps crashing
body: <p>I have a PhoneGap Application and I want to access the Android Calendar via the Content Provider. My PhoneGap JavaScript function can successfully call and return Java functions however I just haven't been able to get Content Provider calls to work. The app compiles without issues and run, but as soon as I call the related Content Provider function it hangs for a while and crashes. Below is a modified version of a Content Provider function I found:
      package com.george.myapp;</p>
  
  <pre><code>import java.util.Calendar;
  import java.util.Date;
  import java.util.GregorianCalendar;
  import java.util.TimeZone;
  
  import android.app.Activity;
  import android.content.ContentValues;
  import android.database.Cursor;
  import android.net.Uri;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  
  public class EventsInCalender extends Activity {
      //@Override
      public void onCreate() {
      //public void onCreate(Bundle savedInstanceState) {
          //super.onCreate(savedInstanceState);
          //setContentView(R.layout.event);       
      }
  
      public String getCal()
      {
          String cal_name = "createdstring";
          Cursor cursor = getContentResolver().query(Uri.parse("content://com.android.calendar/calendars"),new String[] { "_id", "displayName" }, "selected=1", null, null);
          if (cursor != null &amp;&amp; cursor.moveToFirst()) {
               String[] calNames = new String[cursor.getCount()];
               int[] calIds = new int[cursor.getCount()];
               for (int i = 0; i &lt; calNames.length; i++) {
                    // retrieve the calendar names and ids                 
                    calIds[i] = cursor.getInt(0);
                    calNames[i] = cursor.getString(1);
                    cursor.moveToNext();
                }
                cal_name = calNames[0];
                cursor.close();
          }
          return cal_name;
      }
  }
  </code></pre>