Friday, April 27, 2012

Twitter login page content is not displayed properly.


Hi All
If the login page content is not displayed properly. In BlackBerry
Then plz follow this link.
Please, use BrowserFieldOAuthDialogWrapper in place of BrowserContentManagerOAuthDialogWrapper class. It works fine for me.
I got this success by the help of @ernandesmjr Ernandes Mourao Jr
If any find any issue. please let me know.
Thanks Ernandes

Friday, April 20, 2012

Delete file from SDCard in Android



String path="/mnt/sdcard/dhoom.mp3";
   File file = new File(path);
   boolean test1 = file.exists();
   String yes;
   if(test1==true)
   {
    boolean test = file.delete();
    System.out.println("done");
   }
   else
   {
    System.out.println("not exist file");
   }

Add this line in manifest also.

   

Download image from server in Android



public class DownloadImage {
 public static Bitmap downloadImg()
 {
  URL url = null;
  Bitmap _bitmap = null;
  try
  {
   url = new URL("https://www.google.co.in/ig/images/weather/cloudy.gif");
   _bitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream());
  }
  catch (MalformedURLException e)
  {
   e.printStackTrace();
  }
  catch (IOException e)
  {

   e.printStackTrace();
  }
  return _bitmap;
 }
}

Check the connection Availability in BlackBerry Device:



if(CoverageInfo.getCoverageStatus()==CoverageInfo.COVERAGE_NONE)
{
Dialog.alert("No Connection: ");
}
else
{
Dialog.alert("Connection: ");
}

Scale the image



public static Bitmap getScaledBitmapImage(String imagename,int wd,int ht)
{
EncodedImage image = EncodedImage.getEncodedImageResource(imagename);
if(image.getWidth()==wd && image.getHeight()==ht)
return image.getBitmap();
int currentWidthFixed32 = Fixed32.toFP(image.getWidth());
int currentHeightFixed32 = Fixed32.toFP(image.getHeight());
int width = wd;
if(width == -1)
width=image.getWidth();
int height = ht;
if(height == -1)
height=image.getHeight();
int requiredWidthFixed32 = Fixed32.toFP(width);
int requiredHeightFixed32 = Fixed32.toFP(height);
int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32);
int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32);
image = image.scaleImage32(scaleXFixed32, scaleYFixed32);
return image.getBitmap();
}

Return the Document object from by any XML file.





public static Document getDocument(String data)
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Document document = null;
try {
document = builder.parse(new ByteArrayInputStream(data.getBytes("UTF-8")));
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
document.getDocumentElement().normalize();

return document;
}

Get the Byte from by any file.



public static byte[] returnByte(String path)
{
FileConnection fconn;
int available = 0;
InputStream input = null;
byte[] data=null;
try
{
fconn = (FileConnection)Connector.open(path);
if(fconn.exists()==true)
{
input = fconn.openInputStream();
available = input.available();
int fSz = (int)fconn.fileSize();
data = new byte[fSz];
input.read(data, 0, fSz);
}
}
catch(Exception e)
{
Dialog.alert("Error");
}
return data;
}