2

android.intent.action.DOWNLOAD_COMPLETEに登録されている受信者があります。android.intent.action.DOWNLOAD_COMPLETEは、ダウンロードに失敗した場合には受信しません。

のAndroidManifest.xml

 <uses-permission android:name="android.permission.INTERNET" /> 
     <receiver 
      android:name="com.myapp.listener.DownloadListenerService" 
      android:exported="true" 
      android:enabled="true"> 
      <intent-filter> 
       <action android:name="android.intent.action.DOWNLOAD_COMPLETE" /> 
      </intent-filter> 
     </receiver> 

そして、それは私のDownloadListenerService.java reciverです:

package com.myapp.listener; 

import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 

public class DownloadListenerService extends BroadcastReceiver { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     Log.d("MYAPP","Start DownloadListenerService"); 
     //some code 
    } 
} 

と私は、ダウンロードが完了した場合にのみ、logcatメッセージ "スタートDownloadListenerService" でご覧ください。しかし、ダウンロードマネージャでダウンロードが失敗した場合、私はlogcatにメッセージが表示されません。ダウンロードがダウンロードされていないことをどのように把握できますか?

答えて

0

を増やしてみてくださいif else声明

public void onReceive(Context context, Intent intent) { 
    if (context != null){ 
     Log.d("MYAPP","Start DownloadListenerService"); 
     //some code 
    }else{ 
     Log.d("MYAPP","Fail DownloadListenerService"); 
     //some code 
    } 
return; 
} 

編集:私はこれはあなたのダウンロードに失敗した場合でも、trueを返すだろうと思い、ので、多分何か他のものと(context != null)を代用?たぶん(file != null)

+0

ダウンロードが失敗したときにonReceiveがまったく呼び出されないという問題があります。 – Anton111111

+0

@ Anton111111サービスの開始方法に関するコードを投稿できますか?おそらくそこには私たちがあなたを助けることができるものがあります –

関連する問題