android - 在 Android 中将我的应用程序注册为相机应用程序

标签 android

我从 android: how to register my app as "camera app" 得到了帮助但它仍然不能正常工作

我已经尝试使用我的联系人应用将照片添加到我现有的已保存联系人中,其 URI 将生成如下所示

content://com.google.android.contacts.files/my_cache/ContactPhoto-IMG_20170412_123034.jpg

但我无法访问该联系人应用程序的目录,因此我无法通过该 URI 保存照片,如果我这样做,我将得到 FIleNotFoundException

Uri saveUri = (Uri) getIntent().getExtras().getParcelable(MediaStore.EXTRA_OUTPUT);

if (saveUri != null)
{
    // Save the bitmap to the specified URI (use a try/catch block)
    outputStream = getContentResolver().openOutputStream(saveUri); <-----File Not Found Exception 

list 是

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

 <activity
            android:name=".CameraSelfieActivity"
            android:clearTaskOnLaunch="true"
            android:icon="@drawable/icon_chooser_selfie"
            android:label="My Camera"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.media.action.IMAGE_CAPTURE" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
</activity>

Logcat 是

java.io.FileNotFoundException: /my_cache/ContactPhoto-IMG_20170417_205819.jpg: open failed: ENOENT (No such file or directory)
    at libcore.io.IoBridge.open(IoBridge.java:452)
    at java.io.FileInputStream.<init>(FileInputStream.java:76)
    at com.example.CameraSelfieBaseHelper.copyFileToUri(CameraSelfieBaseHelper.java:391)
    at com.example.CameraSelfieBaseHelper.processImageReady(CameraSelfieBaseHelper.java:364)
    at com.example.CameraSelfieBaseHelper.onImageReady(CameraSelfieBaseHelper.java:266)
    at com.example.captureImage(CmGLSV.java:50)
    at com.example.surface.CmGLSV.onDrawFrame(CmGLSV.java:135)
    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1535)
    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
    at libcore.io.Posix.open(Native Method)
    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
    at libcore.io.IoBridge.open(IoBridge.java:438)

但相同的功能是默认相机应用实现的

有没有人建议如何解决这个问题

谢谢,

最佳答案

问题是您的应用没有直接覆盖由联系人应用外部管理的文件(联系人照片)所需的安全权限。

为了达到预期的结果,您可以做的是:

一个。添加必要的权限以通过 ContentResolver API 读取/写入联系人数据

<uses-spermission
                android:name="android.permission.WRITE_CONTACTS" />

<uses-permission
            android:name="android.permission.READ_CONTACTS" />

你可以找到more information on interacting with Contacts data via the Android Developer

确定要使用新照片更新的联系人的 ID

通过 ContentResolver API 更新联系人的照片

There's this example open-source project on github that does just that

关于android - 在 Android 中将我的应用程序注册为相机应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43362604/

相关文章:

java - 在重新启动 Activity 之前延迟动画

Android设置椭圆形按钮只能在图像上点击

android - 在 ScrollView 中添加固定按钮,即使在滚动时也可见

java - 什么是 Matrix.frustumM(mProjMatrix, 0, -ratio, ratio, -1, 1, 3, 7);在 OpenGL ES 20 中?

android - 时间戳:如何识别CPU命令到达声卡的时间?

android - 我可以包含一个自动完成和跨平台(iOS/Android)的字符串文件吗?

android - E/SQLiteLog﹕ (1) near "TABLEaccount": syntax error

java - 从位图android的边缘创建路径

Android:手动缩放 View

java - 如何在 Appium 中使用 Xpath 获取最后一个元素