android 广播,manifest.xml注册,代码编写

来源:互联网 发布:瓜子二手车 知乎 编辑:程序博客网 时间:2024/04/30 09:26

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>

0 0
原创粉丝点击