Thursday, September 20, 2012

how to find file path extension and size not exceeded to 1 mb in android





String s="file path";
File file = new File(s);
   
long sizeInBytes = file.length();
sizeInBytes = sizeInBytes/1024;
Log.e("login bytes", ""+sizeInBytes);
     //transform in MB
     //double sizeInMb = sizeInBytes/(1024*1024);
               
     if(sizeInBytes<=2048)
   
        {
    Log.e("login", ""+sizeInBytes);
      int dot = c.lastIndexOf(".");
      String ff= c.substring(dot+1);
         
    //  tv1.setText(ff);
    if(ff=="pdf"||ff.compareTo("txt")==0||ff=="docx"||ff=="doc"||ff=="xls"||ff=="xlsx"||ff=="ppt"||ff=="pptx")
      {
    //Log.e("login if", ""+ff);
        exsistingFileName=c;
        Log.e("path file", ""+exsistingFileName);
    String searchFor = "bit.ly/yyyyyy";
    String s1=feed1.getText().toString();
        int len = searchFor.length();
        int result = 0;
        if (len > 0) {
        int start = s1.indexOf(searchFor);
        while (start != -1) {
        result++;
        start =s1.indexOf(searchFor, start+len);                
             
        }
        }        
       if(result==0)
    {
    feed1.append(" bit.ly/yyyyyy ");
    }
       else
       {
     
       }
     
      }
    else
    {
    showAlertDialog("file type only doc,txt,doc,docx,ppt,xls,xls");
    }

//Log.e("path", ""+exsistingFileName);
        }
    else
    {
    showAlertDialog("file size not exceed to 2mb");
    }

}

No comments:

Post a Comment