Note that there are some explanatory texts on larger screens.

plurals
  1. POSelect first SMS on Android database inbox
    primarykey
    data
    text
    <p>I am desperate to find the solution so I ask for help! I am a new french programmer. My objective is to create a widget able to show SMS. My problem is that I don't know how create a cursor which select the first SMS in content://sms/inbox Excuse my bad English, I hope you will able to understand my wich. Thank you for your answer. this is my code:</p> <pre><code>package sfeir.monwidget; import android.R.string; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.net.Uri; import android.widget.RemoteViews; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.widget.ArrayAdapter; public class MonWidget extends AppWidgetProvider { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { Uri uri = Uri.parse("content://sms/inbox"); // returns all the results. Cursor c= getContentResolver().query(uri, null, null ,null,null); // called by the Activity. startManagingCursor(c); String body = null; String number = null; if(c.moveToFirst()) { // move cursor to first row // retrieves the body and number of the SMS body = c.getString(c.getColumnIndexOrThrow("body")).toString(); number = c.getString(c.getColumnIndexOrThrow("address")).toString(); } // when your done, close the cursor. c.close(); RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout); updateViews.setTextColor(R.id.text, 0xFF000000); updateViews.setTextViewText(R.id.text, (CharSequence) body); ComponentName thisWidget = new ComponentName(context, MonWidget.class); appWidgetManager.updateAppWidget(thisWidget, updateViews); } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload