Android 土司没有出现

Android 土司没有出现,android,broadcastreceiver,toast,Android,Broadcastreceiver,Toast,我已经制作了广播接收器。调用onReceive方法,并在控制台上显示Log.i,但Toast无论如何都不可见。 包com.example.broadcaster import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; import android.widget.Toast; public cl

我已经制作了
广播接收器
。调用
onReceive
方法,并在控制台上显示
Log.i
,但Toast无论如何都不可见。 包com.example.broadcaster

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

public class MyReceiver extends BroadcastReceiver {     
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i("STH happened", "STH HAPPENNED");
        Toast.makeText(context, "Intent caught\n" + intent.getExtras().getString("MESSAGE"), Toast.LENGTH_LONG);
    }
}
我在
Log.I
之后得到的日志是:

04-17 21:21:16.742: W/Bundle(1685): Key MESSAGE expected String but value was a android.text.SpannableString.  The default value <null> was returned.
04-17 21:21:16.742: W/Bundle(1685): Attempt to cast generated internal exception:
04-17 21:21:16.742: W/Bundle(1685): java.lang.ClassCastException: android.text.SpannableString cannot be cast to java.lang.String
04-17 21:21:16.742: W/Bundle(1685):     at android.os.Bundle.getString(Bundle.java:1121)
04-17 21:21:16.742: W/Bundle(1685):     at com.example.broadcaster.MyReceiver.onReceive(MyReceiver.java:15)
04-17 21:21:16.742: W/Bundle(1685):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2419)
04-17 21:21:16.742: W/Bundle(1685):     at android.app.ActivityThread.access$1700(ActivityThread.java:135)
04-17 21:21:16.742: W/Bundle(1685):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1272)
04-17 21:21:16.742: W/Bundle(1685):     at android.os.Handler.dispatchMessage(Handler.java:102)
04-17 21:21:16.742: W/Bundle(1685):     at android.os.Looper.loop(Looper.java:136)
04-17 21:21:16.742: W/Bundle(1685):     at android.app.ActivityThread.main(ActivityThread.java:5017)
04-17 21:21:16.742: W/Bundle(1685):     at java.lang.reflect.Method.invokeNative(Native Method)
04-17 21:21:16.742: W/Bundle(1685):     at java.lang.reflect.Method.invoke(Method.java:515)
04-17 21:21:16.742: W/Bundle(1685):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-17 21:21:16.742: W/Bundle(1685):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-17 21:21:16.742: W/Bundle(1685):     at dalvik.system.NativeStart.main(Native Method)
04-17 21:21:16.752: E/SoundPool(383): error loading /system/media/audio/ui/KeypressReturn.ogg
04-17 21:21:16.762: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressReturn.ogg
04-17 21:21:16.762: E/SoundPool(383): error loading /system/media/audio/ui/KeypressInvalid.ogg
04-17 21:21:16.762: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressInvalid.ogg
04-17 21:21:16.762: W/AudioService(383): onLoadSoundEffects(), Error -1 while loading samples

最后的消息为空。

确保您在日志猫中获得classCastException,并显示代码

您需要调用
show()
来显示祝酒词

Toast.makeText(context, "Intent caught\n" + intent.getExtras().getString("MESSAGE"), Toast.LENGTH_LONG).show();

确保在日志猫中获得classCastException,并显示代码

您需要调用
show()
来显示祝酒词

Toast.makeText(context, "Intent caught\n" + intent.getExtras().getString("MESSAGE"), Toast.LENGTH_LONG).show();

确保在日志猫中获得classCastException,并显示代码

您需要调用
show()
来显示祝酒词

Toast.makeText(context, "Intent caught\n" + intent.getExtras().getString("MESSAGE"), Toast.LENGTH_LONG).show();

确保在日志猫中获得classCastException,并显示代码

您需要调用
show()
来显示祝酒词

Toast.makeText(context, "Intent caught\n" + intent.getExtras().getString("MESSAGE"), Toast.LENGTH_LONG).show();

EditText上的
getText()
返回的是字符序列,而不是字符串。您可以在接收器中调用
getText().toString()
或使用
getExtras().getCharSequence()
,这取决于您是否希望保留跨度信息。

编辑文本上的
getText()
返回的是字符序列,而不是字符串。您可以在接收器中调用
getText().toString()
或使用
getExtras().getCharSequence()
,这取决于您是否希望保留跨度信息。

编辑文本上的
getText()
返回的是字符序列,而不是字符串。您可以在接收器中调用
getText().toString()
或使用
getExtras().getCharSequence()
,这取决于您是否希望保留跨度信息。

编辑文本上的
getText()
返回的是字符序列,而不是字符串。您可以在接收器中调用
getText().toString()
或使用
getExtras().getCharSequence()
,这取决于您是否希望保留跨度信息。

您需要在Toast上调用show()。

您需要在Toast上调用show()。

您需要在Toast上调用show()。

您需要在Toast上调用show())在Toast上。

谢谢,Toast现在显示,但是额外的是空的。请查看OP.
sendBroadcast(新意图(“com.example.MESSAGE_Intent”).putExtra(“MESSAGE”),((EditText)findViewById(R.id.textField)).getText().toString())谢谢,Toast现在显示,但额外值为空。请查看OP.
sendBroadcast(新意图(“com.example.MESSAGE_Intent”).putExtra(“MESSAGE”),((EditText)findViewById(R.id.textField)).getText().toString())谢谢,Toast现在显示,但额外值为空。请查看OP.
sendBroadcast(新意图(“com.example.MESSAGE_Intent”).putExtra(“MESSAGE”),((EditText)findViewById(R.id.textField)).getText().toString())谢谢,Toast现在显示,但额外值为空。请查看OP.
sendBroadcast(新意图(“com.example.MESSAGE_Intent”).putExtra(“MESSAGE”),((EditText)findViewById(R.id.textField)).getText().toString())