Android 용 위젯에서 작업했습니다. 이를 위해 읽지 않은 메시지의 양과 현재 시간을 표시하려고합니다. 현재 시간은 정상적으로 작동하지만, 이제는로드하려고 할 때 충돌하는 메시지 부분을 추가했습니다. 이것은 내 코드입니다.Android에서 새 SMS 메시지 수신시 오류가 발생했습니다.
public class MyTime extends TimerTask {
RemoteViews remoteViews;
AppWidgetManager appWidgetManager;
ComponentName thisWidget;
Context context;
java.text.DateFormat format = SimpleDateFormat.getTimeInstance(
SimpleDateFormat.SHORT, Locale.getDefault());
public MyTime(Context context, AppWidgetManager appWidgetManager) {
this.appWidgetManager = appWidgetManager;
remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
thisWidget = new ComponentName(context, LeafClockWidget.class);
}
@Override
public void run() {
SimpleDateFormat sdf1 = new SimpleDateFormat("EEEE, MMMM dd");
Date d = new Date(System.currentTimeMillis());
String time1 = sdf1.format(d);
final Uri SMS_INBOX = Uri.parse("content://sms/inbox");
Cursor c = context.getContentResolver().query(SMS_INBOX, null, "read = 0", null, null);
int unreadMessagesCount = c.getCount();
c.deactivate();
remoteViews.setTextViewText(R.id.widget_textview3, "You have " + c + " unread SMS messages.");
remoteViews.setTextViewText(R.id.widget_textview1, time1);
remoteViews.setTextViewText(R.id.widget_textview2, "The time is "
+ format.format(new Date(System.currentTimeMillis())));
appWidgetManager.updateAppWidget(thisWidget, remoteViews);
}
}
오류 코드가 어디에 있는지 찾는 데 어려움이 있습니다. 그래서 사람들이 저를 도울 수 있기를 바랍니다.
당신이 오류의 종류를 알고 로그 고양이를 게시 할 수 없습니다 : -
빠른 팁, 당신은
try
사용할 수있는 코드에서 오류를 발견 할catch
및보고하여 여기LogCat
은 예입니다 너 점점? – Swayam