I got help from android: how to register my app as "camera app" but still it's not properly working
I have tried with my Contact App to add photo to my existing saved Contact, whom URI will be generated like below
content://com.google.android.contacts.files/my_cache/ContactPhoto-IMG_20170412_123034.jpg but I can not access to that Contact app's directory, so I can not save photo over that URI and if I do I will get 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 Menifest is
<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 is
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 same functionality is achieved by default Camera App
will anybody has suggestion how to resolve this issue
Thanks,
1 Answers
Answers 1
The problem is that your app does not have the required security privileges to directly override the file (contact photo) that is externally managed by the contacts app.
What you can do to achieve the desired result is:
a. Add the necessary permissions to read/write Contacts 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 on interacting with Contacts data via the Android Developer
b. Identify the ID of the contact you want to update with the new photo
c. Update the contact's photo through it's ContentResolver API
There's this example open-source project on github that does just that
0 comments:
Post a Comment