I want to implement a solution where I want to catch the android.intent.action.DOWNLOAD_COMPLETED
intents from the Android Market App i.e after the download of the app. The android Market app uses the default Download Manager and the download manager on the completion of the download sends such an intent, however I have not been able to capture it,I followed this tutorial and please refer to this to have more details on how market app uses Download Manager and for more information on Download Manager refer to this. Please do suggest me a way to catch those intents.
EDIT This is what I am using for my Broadcast Reciever
<uses-permission android:name="android.permission.ACCESS_开发者_Go百科DOWNLOAD_MANAGER">
</uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<receiver
android:name=".DownloadReceiver"
android:permission="android.permission.SEND_DOWNLOAD_COMPLETED_INTENTS"
android:exported="true">
<intent-filter>
<action
android:name="android.intent.action.DOWNLOAD_COMPLETED">
</action>
</intent-filter>
</receiver>
</application>
You've got everything right except the name of the action in the intent filter. Note the DOWNLOAD_COMPLETE
instead of DOWNLOAD_COMPLETED
<receiver
android:name=".DownloadReceiver"
android:exported="true"
android:icon="@drawable/download_icon" >
<intent-filter>
<action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
</intent-filter>
</receiver>
This worked for me. You do not need to register the receiver in code, this will listen even when your app isn't running.
First register the reciever
registerReceiver(onComplete,
new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
And set a BroadcastReciever to capture the event.
BroadcastReceiver onComplete=new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
// run your action here
}
};
Probabily your receiver is declared with lower priority than the registered for the Market application. Try to use IntentFilter.setPriority() or declare the priority on XML here
精彩评论