android保存图片成功的广播,android保存一张图片sendBroadcast代码

android保存图片后加了以下代码就可以了

sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri

.parse("file://" + _file)));

那么这个sendBroadcast到底是做什么的呢?广播,相当于iOS中NSNotificationCenter的postNotificationName。不过比iOS更加强大,iOS中只是app内适用,在android中发送一条广播其他app都可以收到,然后进行相应的处理。

发送广播比较

android

Intent it = new Intent("someNotification");

it.putExtra("some argv", "abcd");

sendBroadcast(it);

iOS

[[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingTaskDidCompleteNotification object:task userInfo:userInfo];

接收广播比较

android

private BroadcastReceiver br = new BroadcastReceiver() {

@Override

public void onReceive(Context context, Intent intent) {

String someargv = intent.getStringExtra("some argv");

}

};

IntentFilter ifilter = new IntentFilter("someNotification");

registerReceiver(br, ifilter);

iOS

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkRequestDidFinish:) name:AFNetworkingTaskDidCompleteNotification object:nil];

- (void)networkRequestDidFinish:(NSNotification *)notification {

NSDictionary * userDic = [notification userInfo];

//some code

}

取消接收广播比较

android

registerReceiver(br, ifilter);

iOS

[[NSNotificationCenter defaultCenter] removeObserver:self];

总结

附app效果图

3441ae6b326af5d19f62e844b1c87b05.png

(责任编辑:最模板)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值