2011-07-17 6 views
0

ListActivity에 의해 호출되는 BroadcastReceiver에서 일부 데이터를 수신하려고합니다. 그것은 호출되었지만 getExtras는 항상 NULL을 반환합니다.ListActivity의 getExtras가 Android에서 NULL입니다. BroadcastReceiver

이 내 ListActivity의 흥미로운 부분입니다 :

public boolean onContextItemSelected(MenuItem item) { 
    Intent distIntent = new Intent(); 
    distIntent.setAction(Intent.ACTION_SEND); 
    distIntent.putExtra("fileName", new File("Test").getName()); 
    sendBroadcast(distIntent); 
} 

이 내 브로드 캐스트 리시버의 해당 부분 :

public void onReceive(Context c, Intent intent){ 
    String b = intent.getStringExtra("fileName"); 
    if(b != null) 
     Log.e(logTag, "File Name: "+b); 
} 

파일이 그 이름이 의도를 제대로 추가되고, 존재하지만 웬일인지 그것이 나의 수신기에 전파되지 않고 있었다.

감사합니다.

답변

1

new File("Test").getName()이 null이 아닌 값을 반환하면 위의 코드가 작동해야합니다.

onReceive 메서드가 전혀 호출되지 않습니까?

<receiver android:name=".TestReceiver"> 
     <intent-filter> 
      <action android:name="android.intent.action.SEND" /> 
     </intent-filter> 
</receiver> 

그리고 대신 getName 메소드 호출의 일부 정적 문자열을하며 일 : 내 매니페스트 XML에 다음 <receiver> 블록 코드를 시도했다.

+0

감사의 말 많은 도움을 주셔서 감사합니다. 다른 조치로 테스트했기 때문에 잘못된 의도 필터 (사용자 정의 인 텐트 필터링)를 사용함을 알았습니다. – Stefan