
当用户使用默认相机应用程序拍照时,我正在尝试“收听”.我使用广播接收器解决方案如下
表现:
<receiver androID:name=".CameraEventReceiver" androID:enabled="true" > <intent-filter> <action androID:name="com.androID.camera.NEW_PICTURE" /> <action androID:name="androID.harDWare.action.NEW_PICTURE" /> <data androID:mimeType="image/*" /> </intent-filter> </receiver>收件人:
public class CameraEventReceiver extends broadcastReceiver {@OverrIDepublic voID onReceive(Context context, Intent intent) { Cursor cursor = context.getContentResolver().query(intent.getData(), null,null, null, null); cursor.movetoFirst(); String image_path = cursor.getString(cursor.getColumnIndex("_data")); Toast.makeText(context, "New Photo is Saved as : -" + image_path, Toast.LENGTH_SHORT).show(); Intent i = new Intent(context, MyAct.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); }问题是事件被多次触发(两次).我的断点在context.startActivity(i)被调用两次,并且都是动作androID.harDWare.action.NEW_PICTURE.
任何原因发生这种情况或如何预防?
谢谢
解决方法:
KitKat上的库存相机应用程序发送androID.harDWare.action.NEW_PICTURE和com.androID.camera.NEW_PICTURE广播(不知道旧版本),这可能是您的接收器被通知两次的原因.
如果您的应用仅适用于ICS,则可以从意图过滤器中删除com.androID.camera.NEW_PICTURE,因为它没有记录.
如果您仍想处理这个问题,您的接收器应该实现一些逻辑,以了解已经为其接收的数据处理了意图.此逻辑取决于您的应用程序以及您对接收的数据执行的 *** 作.
总结以上是内存溢出为你收集整理的android.hardware.action.NEW_PICTURE被触发两次全部内容,希望文章能够帮你解决android.hardware.action.NEW_PICTURE被触发两次所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)