Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 获取联系人照片_Android_Contacts_Rawcontacts - Fatal编程技术网

Android 获取联系人照片

Android 获取联系人照片,android,contacts,rawcontacts,Android,Contacts,Rawcontacts,我知道可以通过以下方式获取联系人的照片: public InputStream getContactPhotoInputStream() throws IOException { Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(mContactId)); InputStream is = ContactsContract.Contacts.op

我知道可以通过以下方式获取联系人的照片:

public InputStream getContactPhotoInputStream() throws IOException {
        Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(mContactId));
        InputStream is = ContactsContract.Contacts.openContactPhotoInputStream(contentResolver, uri);

        return is;
}
但现在我需要访问RawContact的所有照片(有照片的那张)。但我不能。 从文档中,照片保存为文件,缩略图保存为
Data
表中的
Blob
。我可以通过对数据库的简单查询获得缩略照片,并检索
Blob
,但现在我需要原始大小的照片,我找不到获取它的方法。我在android文档和谷歌上都找不到任何信息

我尝试了这个方法(改编自保存照片文件)来获取照片文件,但没有成功

public InputStream getRawContactPhotoInputStream() throws IOException
    {
        Uri rawContactPhotoUri = Uri.withAppendedPath(
                ContentUris.withAppendedId(RawContacts.CONTENT_URI, Long.parseLong(mRawContactId)),
                RawContacts.DisplayPhoto.CONTENT_DIRECTORY);

        AssetFileDescriptor fd = contentResolver.openAssetFileDescriptor(rawContactPhotoUri, "rw");
        InputStream is = fd.createInputStream();

        fd.close();

        return is;

    }
我在LogCat上看到这个:

02-18 23:44:27.195: D/PhotoRestlet(8984): Representation1 size < 1
02-18 23:44:27.207: W/System.err(8984): 2014-02-18  23:44:27    10.17.1.54  -   -   8080    GET /contact/photo/6    -   200 -   0   35  http://10.17.1.72:8080  Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36   -
02-18 23:44:27.226: W/System.err(8984): Unable to read the entity
02-18 23:44:27.226: W/System.err(8984): java.io.IOException: read failed: EBADF (Bad file number)
02-18 23:44:27.226: W/System.err(8984):     at java.nio.FileChannelImpl.readImpl(FileChannelImpl.java:315)
02-18 23:44:27.226: W/System.err(8984):     at java.nio.FileChannelImpl.read(FileChannelImpl.java:287)
02-18 23:44:27.226: W/System.err(8984):     at org.restlet.engine.io.ReadableChunkingChannel.read(ReadableChunkingChannel.java:137)
02-18 23:44:27.226: W/System.err(8984):     at org.restlet.engine.io.Buffer.fill(Buffer.java:395)
02-18 23:44:27.226: W/System.err(8984):     at org.restlet.engine.connector.OutboundWay.onFill(OutboundWay.java:388)
02-18 23:44:27.226: W/System.err(8984):     at org.restlet.engine.io.Buffer.process(Buffer.java:601)
02-18 23:44:27.226: W/System.err(8984):     at org.restlet.engine.connector.Way.processIoBuffer(Way.java:503)
02-18 23:44:27.226: W/System.err(8984):     at org.restlet.engine.connector.OutboundWay.processIoBuffer(OutboundWay.java:463)
02-18 23:44:27.226: W/System.err(8984):     at org.restlet.engine.connector.Way.onSelected(Way.java:456)
02-18 23:44:27.230: W/System.err(8984):     at org.restlet.util.SelectionRegistration.onSelected(SelectionRegistration.java:325)
02-18 23:44:27.230: W/System.err(8984):     at org.restlet.engine.connector.Connection.onSelected(Connection.java:617)
02-18 23:44:27.230: W/System.err(8984):     at org.restlet.util.SelectionRegistration.onSelected(SelectionRegistration.java:325)
02-18 23:44:27.230: W/System.err(8984):     at org.restlet.engine.connector.ConnectionController.onSelected(ConnectionController.java:219)
02-18 23:44:27.230: W/System.err(8984):     at org.restlet.engine.connector.ServerConnectionController.onSelected(ServerConnectionController.java:99)
02-18 23:44:27.230: W/System.err(8984):     at org.restlet.engine.connector.ConnectionController.selectKeys(ConnectionController.java:308)
02-18 23:44:27.230: W/System.err(8984):     at org.restlet.engine.connector.ConnectionController.doRun(ConnectionController.java:171)
02-18 23:44:27.230: W/System.err(8984):     at org.restlet.engine.connector.Controller.run(Controller.java:159)
02-18 23:44:27.230: W/System.err(8984):     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
02-18 23:44:27.230: W/System.err(8984):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
02-18 23:44:27.230: W/System.err(8984):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-18 23:44:27.230: W/System.err(8984):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-18 23:44:27.230: W/System.err(8984):     at java.lang.Thread.run(Thread.java:841)
02-18 23:44:27.230: W/System.err(8984): Caused by: libcore.io.ErrnoException: read failed: EBADF (Bad file number)
02-18 23:44:27.230: W/System.err(8984):     at libcore.io.Posix.readBytes(Native Method)
02-18 23:44:27.230: W/System.err(8984):     at libcore.io.Posix.read(Posix.java:123)
02-18 23:44:27.230: W/System.err(8984):     at libcore.io.BlockGuardOs.read(BlockGuardOs.java:144)
02-18 23:44:27.230: W/System.err(8984):     at java.nio.FileChannelImpl.readImpl(FileChannelImpl.java:303)
02-18 23:44:27.230: W/System.err(8984):     ... 21 more
02-18 23:44:27.250: D/PhotoRestlet(8984): Representation1 size < 1
02-18 23:44:27.250: W/System.err(8984): 2014-02-18  23:44:27    10.17.1.54  -   -   8080    GET /contact/photo/6    -   1001    -   0   17  http://10.17.1.72:8080  Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36   -
02-18 23:44:27.269: D/PhotoRestlet(8984): Representation1 size < 1
02-18 23:44:27.273: W/System.err(8984): 2014-02-18  23:44:27    10.17.1.54  -   -   8080    GET /contact/photo/6    -   1001    -   0   19  http://10.17.1.72:8080  Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36   -
02-18 23:44:27.308: D/skia(1925): --- SkImageDecoder::Factory returned null
02-18 23:44:27.308: D/skia(1925): --- SkImageDecoder::Factory returned null
02-18 23:44:27.316: D/skia(1925): --- SkImageDecoder::Factory returned null
02-18 23:44:27.195:D/PhotoRestlet(8984):表示1大小<1
02-18 23:44:27.207:W/System.err(8984):2014-02-18 23:44:27 10.17.1.54--8080 GET/contact/photo/6-200-035http://10.17.1.72:8080  Mozilla/5.0(Windows NT 6.1;WOW64)AppleWebKit/537.36(KHTML,类似Gecko)Chrome/32.0.1700.107 Safari/537.36-
02-18 23:44:27.226:W/System.err(8984):无法读取实体
02-18 23:44:27.226:W/System.err(8984):java.io.IOException:读取失败:EBADF(错误的文件号)
02-18 23:44:27.226:W/System.err(8984):位于java.nio.FileChannelImpl.readImpl(FileChannelImpl.java:315)
02-18 23:44:27.226:W/System.err(8984):位于java.nio.FileChannelImpl.read(FileChannelImpl.java:287)
02-18 23:44:27.226:W/System.err(8984):位于org.restlet.engine.io.ReadableChunkingChannel.read(ReadableChunkingChannel.java:137)
02-18 23:44:27.226:W/System.err(8984):位于org.restlet.engine.io.Buffer.fill(Buffer.java:395)
02-18 23:44:27.226:W/System.err(8984):位于org.restlet.engine.connector.OutboundWay.onFill(OutboundWay.java:388)
02-18 23:44:27.226:W/System.err(8984):位于org.restlet.engine.io.Buffer.process(Buffer.java:601)
02-18 23:44:27.226:W/System.err(8984):位于org.restlet.engine.connector.Way.processIoBuffer(Way.java:503)
02-18 23:44:27.226:W/System.err(8984):位于org.restlet.engine.connector.OutboundWay.processIoBuffer(OutboundWay.java:463)
02-18 23:44:27.226:W/System.err(8984):位于org.restlet.engine.connector.Way.onSelected(Way.java:456)
02-18 23:44:27.230:W/System.err(8984):位于org.restlet.util.SelectionRegistration.onSelected(SelectionRegistration.java:325)
02-18 23:44:27.230:W/System.err(8984):位于org.restlet.engine.connector.Connection.onSelected(Connection.java:617)
02-18 23:44:27.230:W/System.err(8984):位于org.restlet.util.SelectionRegistration.onSelected(SelectionRegistration.java:325)
02-18 23:44:27.230:W/System.err(8984):位于org.restlet.engine.connector.ConnectionController.onSelected(ConnectionController.java:219)
02-18 23:44:27.230:W/System.err(8984):位于org.restlet.engine.connector.ServerConnectionController.onSelected(ServerConnectionController.java:99)
02-18 23:44:27.230:W/System.err(8984):位于org.restlet.engine.connector.ConnectionController.selectKeys(ConnectionController.java:308)
02-18 23:44:27.230:W/System.err(8984):位于org.restlet.engine.connector.ConnectionController.doRun(ConnectionController.java:171)
02-18 23:44:27.230:W/System.err(8984):位于org.restlet.engine.connector.Controller.run(Controller.java:159)
02-18 23:44:27.230:W/System.err(8984):位于java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
02-18 23:44:27.230:W/System.err(8984):在java.util.concurrent.FutureTask.run(FutureTask.java:237)
02-18 23:44:27.230:W/System.err(8984):位于java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-18 23:44:27.230:W/System.err(8984):位于java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-18 23:44:27.230:W/System.err(8984):at java.lang.Thread.run(Thread.java:841)
02-18 23:44:27.230:W/System.err(8984):原因:libcore.io.ErrnoException:读取失败:EBADF(错误的文件号)
02-18 23:44:27.230:W/System.err(8984):位于libcore.io.Posix.readBytes(本机方法)
02-18 23:44:27.230:W/System.err(8984):位于libcore.io.Posix.read(Posix.java:123)
02-18 23:44:27.230:W/System.err(8984):位于libcore.io.BlockGuardOs.read(BlockGuardOs.java:144)
02-18 23:44:27.230:W/System.err(8984):位于java.nio.FileChannelImpl.readImpl(FileChannelImpl.java:303)
02-18 23:44:27.230:W/系统错误(8984):。。。还有21个
02-18 23:44:27.250:D/Photostret(8984):表示1大小<1
02-18 23:44:27.250:W/System.err(8984):2014-02-18 23:44:27 10.17.1.54--8080 GET/contact/photo/6-1001-0 17http://10.17.1.72:8080  Mozilla/5.0(Windows NT 6.1;WOW64)AppleWebKit/537.36(KHTML,类似Gecko)Chrome/32.0.1700.107 Safari/537.36-
02-18 23:44:27.269:D/Photostret(8984):表示1大小<1
02-18 23:44:27.273:W/System.err(8984):2014-02-18 23:44:27 10.17.1.54--8080 GET/contact/photo/6-1001-0 19http://10.17.1.72:8080  Mozilla/5.0(Windows NT 6.1;WOW64)AppleWebKit/537.36(KHTML,类似Gecko)Chrome/32.0.1700.107 Safari/537.36-
02-18 23:44:27.308:D/skia(1925):---SkImageDecoder::工厂返回空值
02-18 23:44:27.308:D/skia(1925):---SkImageDecoder::工厂返回空值
02-18 23:44:27.316:D/skia(1925):---SkImageDecoder::工厂返回空值

经过大量的挖掘,仔细查看android的源代码,我找到了一种从原始联系人获取图像的方法

使用Android的本地代码来获取它,我做了自己的解决方案(我的问题是获取原始联系人的图像URI,我找不到获取它的方法)。因此,我从这里开始:

public InputStream getBitmapFromUri(String rawContactId) throws FileNotFoundException {

        final Uri photoUri = Uri.withAppendedPath(
                ContentUris.withAppendedId(RawContacts.CONTENT_URI, Long.valueOf(rawContactId)), RawContacts.DisplayPhoto.CONTENT_DIRECTORY);
        final InputStream imageStream = contentResolver.openInputStream(photoUri);

        return imageStream;
}
这就是如何获取原始联系人的照片