您的位置:首页 > 移动开发 > Android开发

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

2014-11-27 17:40 387 查看
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: