Hi, I am desesperate 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 no 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:
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);
}
}