android 广播,manifest.xml注册,代码编写
1.种
private void downloadBr(File file) {
// 广播出去,由广播接收器来处理下载完成的文件
Intent sendIntent = new Intent("com.test.downloadComplete");
// 把下载好的文件的保存地址加进Intent
sendIntent.putExtra("downloadFile", file.getPath());
sendBroadcast(sendIntent);
}
<receiver android:name="com.yuxin.mhealth.ui.dbmanager.DownLoadBR" >
<intent-filter>
<action android:name="com.test.downloadComplete" >
</action>
</intent-filter>
</receiver>
2种
public static void start(Context context,String fileUrl,String name){
Intent downloadIntent = new Intent(context, DownloadFileService.class);
Bundle bundle = new Bundle();
bundle.putString("url", fileUrl);
bundle.putString("fileName", name);
downloadIntent.putExtras(bundle);
context.startService(downloadIntent);
}
<service android:name="com.yuxin.mhealth.ui.dbmanager.DownloadFileService" >
</service>