You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将自定义相机录制的视频返回至Messenger应用

Got it, let's walk through how to set up your camera app to return the recorded video file/Uri to apps like Messenger or Telegram using EXTRA_OUTPUT:

1. Confirm Your Manifest Intent Filter

First, make sure your camera app's Activity has the correct intent filter to respond to video capture requests. You already have the right base setup—here's the properly formatted version:

<?xml version="1.0" encoding="utf-8"?>
<intent-filter>
    <action android:name="android.media.action.VIDEO_CAPTURE"/>
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

This tells Android that your app can handle video capture intents from other apps.

2. Handle the Incoming Intent and Return the Video

Next, in your camera Activity, you need to do three key things:

  • Grab the EXTRA_OUTPUT Uri that the calling app (like Messenger) sends
  • Save your recorded video directly to that Uri
  • Send the Uri back to the calling app once recording is done

Here's a simplified example of how to implement this logic:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera);

    // Retrieve the output Uri from the incoming intent
    Uri outputUri = getIntent().getParcelableExtra(MediaStore.EXTRA_OUTPUT);

    // When recording finishes (e.g., user taps "Save"):
    // Assume you've successfully saved the video to outputUri
    Intent resultIntent = new Intent();
    resultIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputUri);
    setResult(RESULT_OK, resultIntent);
    finish();
}

Note: Don’t forget to handle cases where outputUri is null—some apps might not send it, so you’ll need a fallback save location for those scenarios.

3. Reference: How Apps Like Messenger Call the Camera

As you suspected, calling apps use a pattern similar to this (adjusted for video capture instead of photos):

File videoFile = new File(getExternalFilesDir(Environment.DIRECTORY_MOVIES), "temp_video.mp4");
Uri videoUri = FileProvider.getUriForFile(this, "com.your.package.fileprovider", videoFile);

Intent captureVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
captureVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri);
startActivityForResult(captureVideoIntent, REQUEST_CODE_VIDEO_CAPTURE);

They specify their desired save location via EXTRA_OUTPUT, then wait for your app to send that Uri back in the result.

内容的提问来源于stack exchange,提问作者mrneumann888

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 07:20:24