Wednesday, July 13, 2011

HttpWebRequest and HttpWebResponse in Windows Phone 7 (wp7) Silverlight

I thought to add information regarding with HttpWebRequest / HttpWebResponse in Windows Phone 7. Though WebRequest and response in Windows Phone 7 is little bit different but it is easy. 
Here is code :

public
HttpWebRequest objRequest = null;
public static string myRequestData = string.Empty;
public String urlAddress = “Your URL”;


public void doSend()
{
objRequest = (HttpWebRequest)WebRequest.Create(urlAddress.ToString());
objRequest.ContentType ="application/x-www-form-urlencoded";
objRequest.Method = "POST";
//Adding headers
objRequest.Headers["Header"]= "Your Value";
objRequest.Headers["Content-Language"] = "en-US";

myRequestData = “Your Request data”;

//Begins the asynchronous request
objRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback),objRequest);


}
private static void GetRequestStreamCallback(IAsyncResult asyncResult)
  {
            HttpWebRequest objHttpWebRequest = (HttpWebRequest)asyncResult.AsyncState;
            // End the operation
            Stream postStream = objHttpWebRequest.EndGetRequestStream(asyncResult);
            // Convert the string into a byte array.
            byte[] byteArray = Encoding.UTF8.GetBytes(myRequestData);
            // Write to the request stream.
            postStream.Write(byteArray, 0, myRequestData.Length);
            postStream.Close();

            // Start the asynchronous operation to get the response
         request.BeginGetResponse(new AsyncCallback(GetResponseCallback), objHttpWebRequest );
   }

private static void GetResponseCallback(IAsyncResult asyncResult)
        {
            HttpWebRequest objHttpWebRequest = (HttpWebRequest)asyncResult.AsyncState;
            HttpWebResponse objHttpWebResponse = HttpWebResponse)request.EndGetResponse(asyncResult);
            Stream objStreamResponse = objHttpWebResponse .GetResponseStream();
            StreamReader objStreamReader = new StreamReader(objStreamResponse );
            string responseString =  objStreamReader.ReadToEnd();            // Got response here
             MessageBox.Show("RESPONSE :" + responseString);
            // Close the stream object
            objStreamResponse .Close();
             objStreamReader.Close();
            objHttpWebResponse.Close();
   }



Tuesday, June 28, 2011

Xperia ray and Xperia active Waterproof phones by Sony Ericsson


Sony Ericsson has announced two new Android smartphones the Xperia Ray, and  Xperia Active.


Xperia Active  runs on the latest Android 2.3 Gingerbread . It is a dust proof and water resistant Android smartphone  with 320x480 pixels of resolution and scratch-resistant display that tracks your fingers even when wet.  It is waterproof up to three feet (1m) for up to 30 minutes. It is having 5MP camera.




For more details visit
http://www.sonyericsson.com/cws/corporate/products/phoneportfolio/specification/xperia-active


Xperia Ray is aluminum-framed running Android 2.3 Gingerbread & comes with an 8.1 megapixel autofocus camera. You can expand memory up to 32 GB
It is good for those who want beautiful design, As it combines a slim 9.4mm form factor with a high quality aluminium frame and a 3.3” screen. & delivers speed along with stunning visuals and clarity,




For more details visit
http://www.sonyericsson.com/cws/corporate/products/phoneportfolio/specification/xperia-ray

Both devices are ready for release in the third quarter of the year.


Friday, June 17, 2011

Access PIM information (contacts) from Windows phone7

As a update to Windows phone , Mango SDK comes along with new set of API's that includes accessing PIM too. So we can access contacts easily using new API's
Now here is sample code below for accessing the contact information.

First we need to include namespace
using Microsoft.Phone.UserData;

 public MainPage()
        {
            InitializeComponent();
            Contacts myContacts = new Contacts();
            //   Sample Code to save contacts on phone.
            //SavePhoneNumberTask savePhoneNumberTask = new SavePhoneNumberTask();
            //savePhoneNumberTask.PhoneNumber = "1234567890"; 
            
            myContacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(myContacts_SearchCompleted);

            myContacts.SearchAsync(string.Empty, FilterKind.None, null);
        }

void myContacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
        {
            try
            {
                string strContacts = string.Empty;
                foreach (var result in e.Results)
                {
                  strContacts = strContacts + "Name : " + result.DisplayName + " ; Phone Number : " + result.PhoneNumbers.FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

Thursday, June 16, 2011

Windows Phone 8 (Apollo) & Updates, Nokia will launch WP8 in 2012

It is almost about a month before Microsoft has updated Windows Phone 7 with MANGO SDK.  Now according to latest news, next major updates after WP7.5 will be Windows Phone 8 code-named APOLLO

Nokia already planned 12 models for year 2012. & is about to adopt ST-Ericsson chips for some Windows Phone & expect them as WP8 devices. There are not more details available so it is better to wait and  see what will be the surprised , advanced features available for  both end-users & developers. 

Friday, June 10, 2011

News, How to check PF, EPF account balance details online from July 1


8th June , The Employees' Provident Fund Organisation (EPFO)  announced that from  July 1 account details will be available online for everyone.
Assistant PF Commissioner Kanchan Roy said  that  “You can see your PF account balance online from July 1,”during an interactive session at the Bengal National Chamber of Commerce and Industry.
Now  PF account number will gonna replace by Unique Identification Number (UID)  after inter-connecting all EPFO  offices by March, 2012.
This will be helpful for more than 5 crore  PF subscribers in India.
For more details , pls visit
http://www.epfindia.com



Wednesday, June 8, 2011

Nokia Windows Phone News, updates





June 1st ,the interview of  Nokia's CEO (Stephan Elop) with CNBC  , he was  asked what will be the Nokia's plan B if in a case Windows Phone7 does not work ?  Mr.Elop says that Plan B is to make sure  the Plan A is very successful. According to him consumers feedback is good & Windows phone operation system is very good better in satisfaction of needs than competing platforms. And Microsoft doesn't have partner for doing best for their windows phone that is what Nokia had commitment made through this process , by bringing together the Hardware & Software , off course there is need of third or balancing ecosystem in the environment .


Lets see following months will be crucial for both Windows Phone & Nokia lovers . Being a developer I hope something best from this deal.

For more details & video you can visit HERE .





Thursday, May 19, 2011

How to Play Audio, Video, Files transfer, Isolated Storage Explorer with Windows Phone 7 (WP7) Emulator


As a part of work I was gathering some information regarding playing media contents in Windows Phone 7 (WP7) emulator. I thought it is simple as similar with WM series devices. Though the code snippet for playing is not more than 5-7 lines but faced little problem while transferring media file from my hard drive to Emulator & playing the same.

In WM series devices we are transferring a file (manually) from desktop to Emulator either by using Active Sync or by using WMDC (Windows Mobile Device Center).
However in WP7 it is totally different. Here we need to install the WP7 Isolated Storage Explorer. It is local storage for WP7 applications & all I/O operations need to use it. You can download it from  HERE . Once you downloaded then follow the instructions .
Thanks to Microsoft Corporation for providing wonderful contents

Now its time for using MediaPlayerLauncher to play your media file.
Code snippet for playing media is as below :

 MediaPlayerLauncher objMPlayerLauncher = new MediaPlayerLauncher();
 objMPlayerLauncher.Media = new Uri("gags.wmv", UriKind.Relative); 
 //replace "gags" with your file path.
 objMPlayerLauncher.Location = MediaLocationType.Data;
 objMPlayerLauncher.Controls = MediaPlaybackControls.Pause| MediaPlaybackControls.Stop;
 objMPlayerLauncher.Show();

Please checkout this screen shot :


Hope this will helps.

Wednesday, May 18, 2011

Web Browser Control Windows Phone7 (WP7)


Recently I was just playing with the Web Browser in Windows Phone 7 (WP7) & got error as " You cannot call WebBrowser methods until it is in the visual tree " . 
So thought to share some basic ideas.


Once you drag and drop the WebBrowser control from tool box , you can see code below in .xaml file.
<phone:WebBrowser Name="WebBrowser1" Height="676" Width="450" />
Initially Screen looks like ( refer Screen1)


Now there are two ways to navigate to your web contents :
1. You need to update the Source property of the Web Browser control in  .xaml file:
 e.g. 
<phone:WebBrowser Source="http://www.mohzz.com" Name="WebBrowser1" Height="676" Width="450" />


If we update like above then your web contents will show default contents from specified source ( i.e. contents from "http://www.mohzz.com")
( refer Screen2)


2. Second way is ,
 No need to update the Source property of the Web Browser control in  .xaml file:
it will remains as it is 
<phone:WebBrowser Name="WebBrowser1" Height="227" Width="460" />


Now you need Set  URI location of the Web browser control your codebase accordingly.
You can set URI location by using either "WebBrowser1.Source" property or  by calling "WebBrowser1.Navigate('uri parameter') "


e.g. Written code on Click event of button "Click to visit Microsoft.com"  (from screen 2) 


WebBrowser1.Source = new Uri("http://www.microsoft.com");
Or
WebBrowser1.Navigate(new Uri("http://www.microsoft.com"));


Now you can see the contents of "http://www.microsoft.com" ( refer Screen3 )




Hope this information will helpful for someone


I found one more interesting article regarding with How to display content, embedded within the application assembly, using the WebBrowser , By Doug Holland.



Wednesday, May 11, 2011

Download MANGO SDK Windows Phone 7 (WP7) , release, news updates

Guys ,


After jail breaking the WP7 emulator we comes to know that the current version of WP7 is not supporting any access to the PIM items and developers can not access the camera, no more interaction with the calendar or contacts, also network  limiting to HTTP/HTTPS, and few more restrictions.

However these restrictions rolling out in next update for WP7, called "Mango"  in May2011. It seems to be most of these limits will disappear with Mango. Also came to know that Mango is going to expose around 1500 new APIs.

So Mango is the  MS's next big WP7 update. Hope Mango will rock in coming days.

Good news is that release date has been announced , Mango will gonna release on 24th May-2011. 
For more details visit link below:

Thursday, May 5, 2011

How to Unlock Windows Phone 7 (WP7) Emulator


Hello All,
Finally thought to write about subjected topic,

At the release of WP7 developer tool initially I faced problems for unlocking the WP7 emulator , however after surfing a lot and doing hell like Rn D got to overcome on the problem.
Below are some steps to unlock the WP7 Emulator :

1.I guess initially your emulator screen will looks like as below :
Initial screen

2. To unlock the screen I downloaded "wm70_copypaste" named file by referring
     http://windowsphonehacker.com/latest_windows_phone_7_emulator_unlocked-02-05-11.php 
   thanks for them


3. Once it got downloaded , I copied the file at path
    C:\Program Files\Microsoft SDKs\Windows Phone\v7.0\Emulation\Images



4. In the same path there is file names as "WM70C1.en-US" which is original emulator image file. For safety/backup purpose I renamed this file to "WM70C1.en-US-ORIGINAL".


5. Now its turn for  "wm70_copypaste" file to rename. Rename downloaded file to 
"WM70C1.en-US".


6. You are done here.


Now create/open any WP7 application from "Visual Studio 2010" you will observe the booting process of emulator as below :


(A) Complete OS boot
(B) Loading OS
(C) Home Screen
(D) Other options
Now you unlocked WP7 Emulator and now its ready for development
Hope this might be helpful for someone.

Monday, February 28, 2011

Celebration Of National Science Day (NSD)




On February 28 1928, Sir C.V. Raman announced the discovery of the Raman Effect. For this, he was awarded the Nobel Prize for Physics in 1930. The Raman Effect led to the growth of a new discipline, Raman Spectroscopy, which has now become a powerful tool for a wide range of scientific investigations and industrial applications.

Tuesday, January 25, 2011

How to write log files??





Why Log file needed ?

: Log files are needed for developer to understand flow of code/applications and most important to track/trace the errors in application. If we consider the case of execptions/errors in code sometimes we are unable to trace them at run time. So writing log file really help to overcome for tracking error locations.

Here is sample code written in Visual C-sharp  :


See the Class below:

public class YourLogger
    {
       public static void WriteLogToFile(string yourlogMsg)
        {
            public static string logFile = @"Path/LogFileName.txt";
            try
            {

                FileStream myFileStream = null;
                //creates file if not exist

                if (File.Exists(LogFileName) == false)
                {
                   FileStream fs = new FileStream(LogFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                    fs.Close();
                }
                else
                {
                    myFileStream = new FileStream(LogFileName, FileMode.Append, FileAccess.Write);
                }
                StreamWriter myStreamWriter = new StreamWriter(myFileStream);
                myStreamWriter.WriteLine(DateTime.Now.ToString() + "\t" + yourlogMsg);
                myStreamWriter.Flush();
                myStreamWriter.Close();
                myFileStream.Close();
            }
            catch
            {

                 //Do your exception related operations
            }
      
}
}


Now call  WriteLogToFile(string yourlogMsg) method your application specifically 

in  Catch block to logg the exception details .

Code to call :

YourLogger.WriteLogToFile(exceptionObject.Message);



Hope this might be helpful for new developer.



Thursday, January 20, 2011

How to Play Audio Files in Windows Mobile?

The intension behind this post is to share the code snippet for playing Audio files programatically for Windows Mobile devices.

What you need to is 
1. Create one class ( say class name as Sound ) file.
2. Copy and paste this code 
3. Need to create the object of Sound class & call  play() & StopPlay() accordingly  :
e.g . Sound objSound = new Sound(@"fileName");
      objSound.Play();


Code Snippet is as below :

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;

namespace YourNameSpace
{
    public class Sound
    {
        private byte[] m_soundBytes;
        private string m_fileName;

        public static bool isLooping = false;

        private enum Flags
        {
            SND_SYNC = 0x0000,  /* play synchronously (default) */
            SND_ASYNC = 0x0001,  /* play asynchronously */
            SND_NODEFAULT = 0x0002,  /* silence (!default) if sound not found */
            SND_MEMORY = 0x0004,  /* pszSound points to a memory file */
            SND_LOOP = 0x0008,  /* loop the sound until next sndPlaySound */
            SND_NOSTOP = 0x0010,  /* don't stop any currently playing sound */
            SND_NOWAIT = 0x00002000, /* don't wait if the driver is busy */
            SND_ALIAS = 0x00010000, /* name is a registry alias */
            SND_ALIAS_ID = 0x00110000, /* alias is a predefined ID */
            SND_FILENAME = 0x00020000, /* name is file name */
            SND_RESOURCE = 0x00040004 /* name is resource name or atom */
            // SND_HIGH = 0xFFFF
        }

        [DllImport("CoreDll.DLL", EntryPoint = "PlaySound", SetLastError = true)]
        private extern static int WCE_PlaySound(string szSound, IntPtr hMod, int flags);

        [DllImport("CoreDll.DLL", EntryPoint = "PlaySound", SetLastError = true)]
        private extern static int WCE_PlaySoundBytes(byte[] szSound, IntPtr hMod, int flags);

        public enum Volumes : int
        {
            OFF = 0,
            LOW = 858993459,
            NORMAL = 1717986918,
            MEDIUM = -1717986919,
            HIGH = -858993460,
            VERY_HIGH = -1
        }

        [DllImport("coredll.dll", SetLastError = true)]
        public static extern int waveOutSetVolume(IntPtr device, int volume);

        [DllImport("coredll.dll", SetLastError = true)]
        public static extern int waveOutGetVolume(IntPtr device, ref int volume);

        public static Volumes Volume
        {
            get
            {
                int v = (int)0;
                waveOutGetVolume(IntPtr.Zero, ref v);
                switch (v)
                {
                    case (int)Volumes.OFF: return Volumes.OFF;
                    case (int)Volumes.LOW: return Volumes.LOW;
                    case (int)Volumes.NORMAL: return Volumes.NORMAL;
                    case (int)Volumes.MEDIUM: return Volumes.MEDIUM;
                    case (int)Volumes.HIGH: return Volumes.HIGH;
                    case (int)Volumes.VERY_HIGH: return Volumes.VERY_HIGH;

                    default: return Volumes.OFF;
                }
            }
            set { waveOutSetVolume(IntPtr.Zero, (int)value); }
        }

        /// <summary>
        /// Construct the Sound object to play sound data from the specified file.
        /// </summary>
        public Sound(string fileName)
        {
            m_fileName = fileName;
        }

        /// <summary>
        /// Construct the Sound object to play sound data from the specified stream.
        /// </summary>
        public Sound(Stream stream)
        {
            // read the data from the stream
            m_soundBytes = new byte[stream.Length];
            stream.Read(m_soundBytes, 0, (int)stream.Length);
        }

        /// <summary>
        /// Play the sound
        /// </summary>
        public void Play(bool isLoop)
        {
            // if a file name has been registered, call WCE_PlaySound,
            //  otherwise call WCE_PlaySoundBytes
            try
            {
                //waveOutSetVolume(IntPtr.Zero, (int)Volumes.NORMAL);
                if (isLoop) isLooping = true;

                if (isLooping == false || isLoop == true)
                    if (m_fileName != null)
                     {
                                 if (isLoop)
                            WCE_PlaySound(m_fileName, IntPtr.Zero, (int)(Flags.SND_ASYNC |                                                  Flags.SND_LOOP | Flags.SND_FILENAME));
                                else
                            WCE_PlaySound(m_fileName, IntPtr.Zero, (int)(Flags.SND_ASYNC | Flags.SND_FILENAME));
                       }
                    else
                      {
              WCE_PlaySoundBytes(m_soundBytes, IntPtr.Zero, (int)(Flags.SND_ASYNC | Flags.SND_MEMORY));
                      }
            }
            catch
            {
                throw;
            }
        }

  public void StopPlay()
    {   // if a file name has been registered, call WCE_PlaySound,
        //  otherwise call WCE_PlaySoundBytes
         try
         {
            if (isLooping == false)
             {
               //waveOutSetVolume(IntPtr.Zero, (int)Volumes.OFF);
              if (m_fileName != null)
               WCE_PlaySound(m_fileName, IntPtr.Zero, (int)(Flags.SND_SYNC | Flags.SND_FILENAME));
             else
 WCE_PlaySoundBytes(m_soundBytes, IntPtr.Zero, (int)(Flags.SND_NODEFAULT | Flags.SND_MEMORY));
             }
         }
         catch
         {
                throw;
         }
        }
    }
}


Note : If you have any query please let me know.

Thanks

Wednesday, January 19, 2011

How to use TATA DOCOMO 3G 21 mbps for windows mobile?









Nowadays I am frequently watching advertisement from Tata Docomo  3G  21mbps. 
Anybody knows how to utilise the same for windows mobile or Windows Phone?
I mean to say , am looking for any ideas that can we implement using this, some samples or how to give exposure to 3G technology for windows based devices.


Ideas,help,suggestions will be appreciated.

Thursday, January 6, 2011

Brain Vs Face





I think everyone must experieced , When we meet to any new person our mind starts thinking about his/her personality by looking his face only. 
Mind starts to take different decisions like, he/she is Clever,Talented, Short tempered, Stupid, froudy, funny, naughty etc. etc.
Is anyone observed or thinked on this ? Why our mind play such game. Eventhough I also don't know , but really it is amazing.

I read some information about describing/identifying  a human personality by recongising face only, however facts is that those decision are taken up  depending on physical factors like Hair,Nose,Ear,Forehead etc. So I am wondering how does mind works ?
Any replies will be appriciated!!!