Register my app as a camera app in Android

I got help from android: how to register my application as a “camera application” , but still it doesn’t work properly

I tried using my Contact App to add a photo to an existing saved contact with which the URI will be created, as shown below

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

but I can’t access this contact directory, so I can’t save the photo above this URI, and if I do, I will get a 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 

Manovism

 <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) 

but the same functionality is achieved by default Camera App

anybody suggest how to solve this problem

Thanks,

+1
source share
2 answers

The problem is that your application does not have the necessary security rights to directly override the file (contact photo) that is externally controlled by the contact application.

What can you do to achieve the desired result:

but. Add the necessary permissions to read / write contact data through the ContentResolver API

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

You can find more information about interacting with contact data through the Android developer .

b. Determine the identifier of the contact you want to update with the new photo

from. Update contact photo with ContentResolver API

Here is an example open source github project that does just that

+2
source

Do not use File , use getContentResolver().openOutputStream(uri) to get just OutputStream .

+1
source

All Articles