InputStream and Contact.Photo

I use the 4.6.0 9000 Simulator. Here is the code I use:

static final class GetPhoto extends Thread {
            public GetPhoto(){}

            public void run(){
                StreamConnection s;
                String person = "http://somewebsite";
                try{
                    s = (StreamConnection)Connector.open(person + (String)cvals.get("CNUM"), Connector.READ, true);
                    HttpConnection httpConn = (HttpConnection)s;
                    int status = httpConn.getResponseCode();
                    if (status == HttpConnection.HTTP_OK){
                        InputStream input = s.openInputStream();
                        byte[] data2 = new byte[input.available()];
                        input.read(data2, 0, input.available());
                        byte[] photoEncoded = Base64OutputStream.encode(data2, 0, data2.length, false, false);
                        if (c.countValues(Contact.PHOTO) > 0) {
                            c.setBinary(Contact.PHOTO, 0, PIMItem.ATTR_NONE, photoEncoded,
                                0, data2.length);
                        } else {
                            c.addBinary(Contact.PHOTO, PIMItem.ATTR_NONE, photoEncoded,
                                0, data2.length);
                        }

                        // if record is modified, commit
                        if (c.isModified()){
                            try{
                                c.commit();
                            } catch (PIMException e){
                                errMessage = "Error in getPhoto commit. Error:" + e.getMessage();
                                errCnt++;
                            }
                        }
                        s.close();
                    }
                } catch (IOException e){
                    errMessage = "Error in getPhoto. Error:" + e.getMessage();
                    errCnt++;
                }
                photoCont = true;
            }
        }

I used this code to upload photos and it works fine until I came across one that seems to be bigger than the norm. I have tested on one that works and the gross size returned was 7965 bytes and coded was 10620 bytes. When I try that largest is raw still 7965 but fails after that. It only returns the part of the photo and the other part is blurred.

Yes, there is a lot that is returned when you use InputStream.available () and I don't have to put it in some kind of loop to get the entire photo? If this is not the case, why then is it is blurred. I used Java on the desktop to get the photo from the same web site and it works fine so I know that the photo is not damaged. I use different methods of retruning photography on the side of the desktop.

Thank you.

byte[] chunk = new byte[4 * 1024];
ByteArrayOutputStream read2Buf = new ByteArrayOutputStream();
int chunkLength;
while ((chunkLength = input.read(chunk)) != -1) {
  read2Buf.write(chunk, 0, chunkLength);
}
byte[] read2 = read2Buf.toByteArray(); 

You must run a loop on InputStream.read to read the entire stream (see contract InputStream.read in J2SE/J2ME Javadocs).

OR specific BB:

byte[] read2 = IOUtilities.stream2Bytes(input);

Tags: BlackBerry Developers

Similar Questions

  • Transfer photos and contact information for the razr of motorola (V3) to my computer using the usb connection

    I need instructions step by step to transfer my info and contacts, photo, and waiting for a cell phone motorola razr V3 I dropped and now the screen is white. I am on an acer inspire laptop which uses windows 7.

    I need instructions step by step to transfer my info and contacts, photo, and waiting for a cell phone motorola razr V3 I dropped and now the screen is white. I am on an acer inspire laptop which uses windows 7.

    Hi Trey

    If the phone is damaged, it is something you will need to contact the Motorola Support for the information you are looking for. Here is the link.  Motorola support
    I hope this helps.

    Thank you for using Windows 7

    Ronnie Vernon MVP
  • Me and my dad is from the same Apple ID and I want to set up his own, but how it will get all his contacts, photos etc from my Apple ID? Or he will lose all? or I could keep them saved for him and send more via an application any?

    Me and my dad is from the same Apple ID and I want to set up his own, but how it will get all his contacts, photos etc from my Apple ID? Or he will lose all? or I could keep them saved for him and send more via an application any? I don't know how to resolve this issue, if someone could point me in the right direction.

    Have him create a id Apple here- create and start using a Apple - Apple Support ID, and then both you can create an album-photo sharing Photo Sharing - Apple Support iCloud

  • My wife and I I have phones and a shared Ipad. We share the same I clouds account and contacts and photos.  The problem we have is that my phone thinks I'm him and when I get calls or texts others she also see / Gets the.  How can we

    My wife and I I have phones and an I Pad on his account.  The I-cloud and I-tunes are his accounts and we both use the same for the sharing of photos and contacts.  My phone thinks I'm him and when I get calls or texts of others she sees / get them.  Can put us in place so that we share our contacts, photos and saves account/billing but having our own identity on our phones etc?

    Stop sharing an account. Use home sharing and set up an ID for each of you

  • I have Windows XP Home Edition and use Outlook Express for my e-mail. Is there a way to copy/send e-mail, favorite contacts and my photos on a Flash key?

    Original title: copy files

    I have Windows XP Home Edition and use Outlook Express for my e-mail. Is there a way to copy/send e-mail, favorite contacts and my photos on a Flash key?

    Open the address book in the old identity and file | Export | Address book (wab) to any location on your HARD drive that is easy for you. The office is very well. Then drag that to the flash drive.

    In IE: File | Import and export | Export to a file. Check Favorites | Next | Next | Navigate to a folder or the desktop and export. Drag the folder in the flash player.

    For photos, just right-click on the folder and drag it to the USB and copy here.

  • I lost my music, photos and contacts from yahoo when I switch os from xp to vista, how can I recover these files

    I lost my music, photos and contacts yahoo when I changed the os from xp to vista how to make their comeback? I have run the utility backup while vista cd was in the crack help me please

    Find a windows.old folder, because we don't know exactly how you have installed.

    http://support.Microsoft.com/kb/932912

    How to recover files from an earlier version of Windows in Windows Vista

    Mick Murphy - Microsoft partner

  • sync the iPhone with iTunes but even different ical and contacts

    I would like to sync an iPhone to my mac, my wife and I share. Is it possible that I can connect on the same iTunes account to share our music, but keep our calendars, photos and contacts separate?  Currently, I have my own user account on the computer and I sync with iTunes, but it is not any music. If I put his music library in a shared folder that I have access on the two user accounts, can I delete everything on my phone to sync with the new iTunes library? I wouldn't delete all my apps and everything. Is there a better way to go about this? If it's important, we do not add music to our iTunes so it could be acceptable only for copying all music files once if it was the best way to ensure the rest of our things remain separated. Thanks for your help!

    Use the family sharing, as described here:

    Family shares - Apple Support

  • Contact photos are compressed/low quality

    I love my bike 360. But sometimes, when I get a message from den contact photo that appears as the background sounds, well, terrible. Ive tried to change the contact's photo on my phone at a better resolution photo, but it always looks bad. Its a nice watch and it's a shame the photos seem so compressed. I know that its possible to get beautiful surfaces of contact because of the demo seen in videos. In addition, Album art seems good too. Someone knows how to optimize photos contact on my phone so that they look good on the watch? Thank you.

    I've contacted the developers Android wear and got a little more information.

    It turns out that it is a problem with the application Google Hangouts is hard-coded. For those that care here is the answer I received from Wayne Piekarski:

    "The app Hangouts was previously using setLargeIcon since it is what the Notification API provided previously. Now that they have updated so that it uses setBackground() to Android, and a future update will push this. »

    Thus, it seems that we just have to wait and Hangouts team will take care of that with an update. Maybe it's something to talk to other developers if you notice the same error.

  • Contact photos not no projection in iMessage iPhone 6s

    I know that this issue is already several times. But no solid answers. Contact photos does not and iMessage. Parameters are the standard not zoom I tried everything everyone has tried. Is this a problem with Apple, or is there another solution. Nothing is clear at this point.

    To display pictures of contacts in messages, you must go to settings > Messages > then turn on "show the Photos of Contact."

  • How do I backup notes and contacts from iphone

    I can't figure out how to get Notes on my iPhone5c stored in iCloud.  It seems to get contacts, but not notes.

    My wife also has and iPhone5c and she cannot get contacts or notes of backup to her iCloud account.

    What are we not understand?  I searched and read all sorts of documents about iCloud doing and not from backup and can't really make much sense.  We just want to save all our Notes, Contacts and Photos and videos.  We get the Photos and videos because we have activated the feature that keeps in iCloud and puts only a proxy of it the picture of your phone; While we have.

    So the question is: How do save us our Notes and Contacts to iCloud?

    p.s., We are not going through iTunes for backup.  I guess it's called Syncing, right?  I don't want to do that because I don't like iTunes.

    You can activate the backup to iCloud by going to settings > iCloud > backup who light up. It backs up automatically when the phone is connected to food, locked and connected to wi - fi. Alternatively, you can trigger it manually by using the Back Up Now on this same screen. Note, however, that you will not see the backup content when you open a session https://www.icloud.com/

    Notes and Contacts that you can see in the https://www.icloud.com/ have nothing to do with a backup. They are synchronized and are (or should be) to the https://www.icloud.com/ if you have settings > iCloud > Contacts and settings > iCloud > Notes on and if iCloud is the default account for them. If they are not sync it, what follows has a number of things to review (including if iCloud is the default account): get help using Contacts iCloud - Apple Support

  • The contact photo sync if contact has Facebook account

    (1) the contact photo will not sync to Google on refuse if the contact has a Fcaebook account, even if there is no picture associated Facebook account. The generic image appears slightly larger and brighter that the generic image on contacts without a Facebook account. Is there a work around?

    (2) is there a way to stop denying it sync with Facebook contacts, far delete the account?


  • Why my photos and direct mail files shared in Media player and Live Photo Gallery and how to fix this?

    I have Windows XP Home Edition - & XP Pro Office, as Office 2007.

    I have windows Media Player 11.

    I use Windows Live

    My photos and e-mail acontacts are in the media and contacts of WL-photo library

    I'm sure that it is not necessary to have these memory eating files in two places, just as I don't want my contacts live mail in my Live Photo Gallery - why these programs share all these files with others and how to stop what is happening without losing the data all together?

    Hello

    I suggest you according to the question in this forum and check if that helps:

    http://windowslivehelp.com/product.aspx?ProductID=1

    It will be useful.

  • Upgrade to Windows Vista SP 2, will it delete or broken or delete my files, my program and my photos from my computer?

    Original title: question?

    1 i have windows vista service pack 1 orginal.if I download windows vista up to date service Pack2, will remove or broken or delete my files, my program and my photos in my pc?

    2 - my Windows Vista had product key but I remove my office 2010 and I want to download .do my product key work on office 2012 again?

    Hi Sayyed,

    Thanks for posting the question in the Microsoft Community!

    No, Service Pack (SP) of the upgrade to Windows Vista SP1 to SP2 will not lose or affect any kind of data on the computer.

    You can see the following article for more information on installing Windows Vista Service Pack 2:

    Learn how to install Windows Vista Service Pack 2 (SP2)

    http://Windows.Microsoft.com/en-us/Windows-Vista/learn-how-to-install-Windows-Vista-Service-Pack-2-SP2

     

    What's included in Windows Vista Service Pack 2 (SP2)

    http://Windows.Microsoft.com/en-us/Windows-Vista/whats-included-in-Windows-Vista-Service-Pack-2-SP2

     

    Answer your second question, I recommend you post your request in the Microsoft Office team community dedicated to better support on the issue.

    Microsoft Office community

    http://answers.Microsoft.com/en-us/Office/Forum/office_2010

    Hope the helps of information. For any other corresponding Windows help, do not hesitate to contact us and we will be happy to help you.

  • Z2: Contact Photos don't show up when you call

    After the sync of my new phone of z2 xperia with gmail, I see the contact photos in 'contacts' However, when I call someone, the picture does not show on the screen, it shows just the credits of 'head '.

    they are NOT sim or phone contacts, I changed all the contacts of the SIM to gmail contacts just for that purpose.

    why I don't see the contact pictures?

    EDIT: it seems to be a problem for some, but not all, contacts

    Open the directory > menu > settings > filter > uncheck all options > restart your phone > access to the filter, and then select only Gmail

  • Photo Gallery Windows-impossible to import and send photos

    I ve of the problems to import pictures. Recommended Windows Me Help Center to contact the company who sold the Internet connection for me. I Don t know what is the problem, it's the server, installation or configuration. When I opened the Windows Photo Gallery and click "Import", he doesn´t import. This company asked me to contact you to find the problem. I also always the answer that the work doesn´t HTTP-server.

    Could you please give me instructions for my concerns import and send photos.

    Best regards / Kari.

    Windows live photo gallery has a few errors with the features your speaking of, they say their work on a fix for the operations and reduced to a problem of live messenger.

    Check the thread for more up-to-date information and or ask your question

    http://windowslivehelp.com/forums.aspx?ProductID=20

Maybe you are looking for

  • Doesn't have a flash bios on Satellite U400-14 b

    I have a U400-14 b and recently flashed my bios upgrade to win 7 from xp,It crashed at half way through and I had to spend its take-off and now there is no display on the screen when I turn it on, the DVD drive seems to turn but that's all... Am feel

  • Sliver does not reach 300 ft

    Called Motorola this morning, sending the wick back, they make a range of 300 feet claim that the bull, that I can't get 20 feet of my phone, it connects and disconnects 20 times a day I talked to Motorola and told me that if they sent me a replaceme

  • Notification of 'removed USB storage device' persistent.

    Hello My motorcycle G shows after persistent notification. 'USB storage deleted '. Removed USB storage. Insert new media. " This notification is displayed after removing the Flash drive by removing it from settings-> storage and pulling the OTG with

  • Pavilion 15-p050ca: driver wifi can not install winner 8.1 hp Pavilion 15 - p050ca. Product G6U13A number

    WiFi does not work, install the driver wifi, I got this msg: update.cpp1205 "has occurred and Setup can not continue" How to solve the problem?

  • do a sequential 2D output

    Hi all I have to write a program that gives digital entries after calculations do some other digital outlets. These offers should illustrate in a table and Guthrie 2D but in every step when the user presses next step buttom labview should calculate t