用于检测从内置的摄像头与放大器新媒体的Andr​​oid API; MIC放大器、摄像头、媒体、Andr

由网友(单身求解放)分享简介:有用于检测新媒体时,它被写入设备在Android API中的任何优雅的方式?我主要感兴趣的相机拍摄的照片,视频拍摄的摄像头和音频麦克风记录下来。Is there any elegant way in the Android API for detecting new media when it is written...

有用于检测新媒体时,它被写入设备在Android API中的任何优雅的方式?我主要感兴趣的相机拍摄的照片,视频拍摄的摄像头和音频麦克风记录下来。

Is there any elegant way in the Android API for detecting new media when it is written to the device? I’m mainly interested in photos taken by the camera, video taken by the camera and audio recorded from the mic.

我目前的想法是定期扫描每个媒体内容提供商和过滤基于上次扫描时间。

My current thinking is to periodically scan each media content provider and filter based on last scan time.

我只是想知道,如果有一些服务,我可以挂接到获取实时通知。

I’m just wondering if there is some service I can hook into to get realtime notifications.

推荐答案

有一个特殊的广播意图,应该得到所谓的每一个应用程序写入任何新的媒体存储时间:

There's a special broadcast Intent that should get called every time an application writes anything new to the Media Store:

Intent.ACTION_MEDIA_SCANNER_SCAN_FILE

该广播意图包括路径到新的文件,通过 Intent.getDataString()方法访问。

要听它,只需要创建一个的BroadcastReceiver ,并使用其注册的的IntentFilter 如下图所示:

To listen for it, just create a BroadcastReceiver and register it using an IntentFilter as shown below:

registerReceiver(new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
      String newFileURL = intent.getDataString();
      // TODO React to new Media here.  
    }    
  }, new IntentFilter(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE));

这将只对文件插入到媒体商店内容提供商之一。此外,它取决于多数民众赞成把它有广播的意图,所有本地(谷歌)的应用程序做申请。

This will only work for files being inserted into one of the Media Store Content Providers. Also, it depends on the application that's putting it there broadcasting the intent, which all the native (Google) application do.

阅读全文

相关推荐

最新文章