错误接收广播意图通知

时间:2014-03-19 09:52:25

标签: java android android-intent android-broadcast

当我收到通知时,我在log cat中收到此错误但并非总是如此。似乎有时我想要传递的字符串并在吐司中显示结果null但并非总是如此。错误是从标题:

java.lang.RuntimeException: Error receiving broadcast Intent { act=it.dd.notification flg=0x10 (has extras) }
--
--
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f04006b
--
at it.dd.notification.Main$2.onReceive(Main.java:417)
--

我无法发布所有logCat,因为我在这里没有Eclipse。我记得这些部分是我需要理解的问题。 我在MainActivity中首先声明了这些:

//private String dir;
protected MyReceiver mReceiver = new MyReceiver();
    public static String INTENT_ACTION_NOTIFICATION = "it.dd.notification";
    private String titoloNoti;
    private String contenutoNoti;
    //

总是在MainActivity我有这个BroadcastReceiver:

public class MyReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {

            if (intent != null) {
                Bundle extras = intent.getExtras();
                String notificationTitle = extras.getString(Notification.EXTRA_TITLE);
                CharSequence notificationText = extras.getCharSequence(Notification.EXTRA_TEXT);

                contenutoNoti = notificationText.toString(); //Line 417

                Toast loc = Toast.makeText(getApplicationContext(), contenutoNoti, Toast.LENGTH_SHORT);
                loc.show();

            }

        }
    }

因此,当我拦截通知时,它会崩溃。但是,我重申,并非总是如此。有时当它想要它并且它如此令人沮丧!你有什么想法吗?

0 个答案:

没有答案