为什么ACTION_IMAGE_CAPTURE意图无法正常工作

时间:2016-11-06 11:41:41

标签: android image android-intent camera broadcastreceiver

我试图为新的图像捕捉制作广播接收器。

            specifyIntentFilterForBroadCastRecivers = new IntentFilter(MediaStore.ACTION_IMAGE_CAPTURE);
            startService(specifyIntentFilterForBroadCastRecivers,CameraImageCaptureBroadCastReciver.class);
            break;

我的startService方法:

private void startService(IntentFilter specifyIntentFilterForBroadCastRecivers, Class broadCastReciverClass){
    Intent serviceIntent = new Intent(context, BroadCastServices.class);
    serviceIntent.putExtra("IntentFilter", specifyIntentFilterForBroadCastRecivers);
    serviceIntent.putExtra("Class", broadCastReciverClass);
    context.startService(serviceIntent);
}

service onStartCommand:

 public int onStartCommand(Intent intent, int flags, int startId) {
    Bundle extras = intent.getExtras();
    IntentFilter intentFilter = (IntentFilter) extras.get("IntentFilter");
    Class broadCastReciverClass = (Class) extras.get("Class");
    Object broadCastReciver = null;
    try {
        broadCastReciver = broadCastReciverClass.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        e.printStackTrace();
    }
    registerReceiver((BroadcastReceiver) broadCastReciver, intentFilter);
    return super.onStartCommand(intent, flags, startId);
}

并播放onreceive

    @Override
public void onReceive(Context context, Intent intent) {
    Toast.makeText(context, "Image Captured", Toast.LENGTH_SHORT).show();
}

但似乎MediaStore.ACTION_IMAGE_CAPTURE不正确。我也有其他的intentfilters,如intent.battery_low / battery_ok,它的工作原理。 服务正常。 问题是我使用的是正确的意图吗?

0 个答案:

没有答案