getExtras from ListActivity are NULL in Android BroadcastReceiver
I'm trying to receive some data in my BroadcastReceiver which is called by a ListActivity. It is called, I've tested it, but getExtras always returns NULL.
This is the i开发者_运维问答nteresting part of my ListActivity:
public boolean onContextItemSelected(MenuItem item) {
Intent distIntent = new Intent();
distIntent.setAction(Intent.ACTION_SEND);
distIntent.putExtra("fileName", new File("Test").getName());
sendBroadcast(distIntent);
}
This is the corresponding part of my BroadcastReceiver:
public void onReceive(Context c, Intent intent){
String b = intent.getStringExtra("fileName");
if(b != null)
Log.e(logTag, "File Name: "+b);
}
The file exists, its name is added properly to the intent, but for some reason it's not propagated to my receiver.
Any advice appreciated!
The code above should work if the new File("Test").getName()
returns a not null value.
Is the onReceive
method called at all? I tried the code with the following <receiver>
block in my manifest XML:
<receiver android:name=".TestReceiver">
<intent-filter>
<action android:name="android.intent.action.SEND" />
</intent-filter>
</receiver>
And some static string instead of the getName method call and it worked.
精彩评论