Category Archives: android-activity

HTTP Post Request giving NULL in Android

I am trying to send some data on an API. However my APP isn't giving any response. Neither giving any error nor getting stopped. Its like nothing just happened. I am bit new to android so kindly guide. Besides I know HTTPClient and other imports have become deprecated.

public void makePostRequest()
{
    class makePostRequestAsyncTask extends AsyncTask<Void, Void, String> {


        @Override
        protected String doInBackground(Void... params) {

            HttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost("http://103.226.216.209/finger_varification/api/finger_verification");
            List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(7);
            nameValuePair.add(new BasicNameValuePair("sec_key", "2af8b9d956c39d2d52c46c2a02a978d1"));
            nameValuePair.add(new BasicNameValuePair("cnic", "3520214037921"));
            nameValuePair.add(new BasicNameValuePair("imei_no", "864121017028886"));
            nameValuePair.add(new BasicNameValuePair("device_name", "FingerMap5"));
            nameValuePair.add(new BasicNameValuePair("finger_index",index ));
            nameValuePair.add(new BasicNameValuePair("finger_template", "sdsd"));//model1.toString()));
            nameValuePair.add(new BasicNameValuePair("template_type", "RAW_IMAGE"));

            try {
                httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
            } catch (UnsupportedEncodingException e) {
                // log exception
                e.printStackTrace();
            }


            //making POST request.
            try {
                HttpResponse response = httpClient.execute(httpPost);
                // write response to log

                Log.d("Http Post Response:", response.toString());
            } catch (ClientProtocolException e) {
                // Log exception
                e.printStackTrace();
            } catch (IOException e) {
                // Log exception
                e.printStackTrace();
            }

            return null;
        }
        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);

            if(result.equals("working")){
                Toast.makeText(getApplicationContext(), "HTTP POST is working...", Toast.LENGTH_LONG).show();
            }else{
                Toast.makeText(getApplicationContext(), "Invalid POST req...", Toast.LENGTH_LONG).show();
            }
        }


    }

}

Trying to send HTTP Client image and string to API – compile error = multipartentitybuilder() is not public cannot be accessed from outside package

Since the code below has deprecated classes I've tried all day to find .jars to import that have Apache HttpClient MultipartEntityBuilder class that will import and compile. Below is the old code given to me by the API developer, but it has deprecated classes.

// Image + Multipart
    File image = new File(imageFilename);
    ContentBody body =
            new FileBody(image, "image/jpeg", "image_file", null);
    MultipartEntity multipartContent = new MultipartEntity();
    multipartContent.addPart("image_file", body);

Here is what I've been trying:

        // Image + Multipart
    File image = new File(imageFilename);
    ContentBody body =
            new FileBody(image, "image/jpeg", "image_file", null);
    MultipartEntityBuilder multipartContent = new MultipartEntityBuilder();
    multipartContent.addPart("image_file", body);

build.gradle looks like this:

dependencies {
compile files('libs/moodstocks.jar')
compile files('org.apache.commons.httpclient.jar')
compile files('libs/httpcore-4.0.1.jar')
compile files('libs/httpcore-4.0.1-sources.jar')
compile files('libs/httpclient-4.0.1-sources.jar')
compile files('libs/httpclient-4.3.5.jar')
compile files('libs/httpmime-4.3.6.jar')
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5'
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'

}

You can see that I've put a lot of .jars in my libs folder trying to find something that would play nice. I'm essentially just trying to send an image file with a string to an API using Digest Authentication.

I've struggled with this at various times for quite awhile and now that I have most other pieces working I need to figure this communication out.

Apache ODE Invoke activity name is empty

I have a question about Apache ODE. After i run a bpel process, using ode instance management api i manage to take Scope with Activities. I want to know which activities the process run thru. I am able to get that. But getActivities there are no invoke activities in the list. There are some activities that are with empty name (like ""). I think these activities are invoke activities, but i was unable to understand why their names are empty. So this is my question. Does someone knows are these activities with empty names Invoke Activities and why their names are empty.

Thanks!

Read excel content and display it in table format in android application

I am trying to read the excel content and display it in the form of table in android application.I tried all the possible ways which I got from google but none of them did work for me. I tried using apache poi as well as jxl but both did not work. 

It would be great help for me if you can suggest me the code or steps.

For the below code I got /C:\Users\\Admin\Pictures\Book1.xls file not found error . / trailing slash added before the path.

                    Vector cellVectorHolder = new Vector();
            FileInputStream myInput = new 
                FileInputStream("C:\\Users\\Admin\\Pictures\\Book1.xls");
                    POIFSFileSystem myFileSystem = new
                POIFSFileSystem(myInput);   
            HSSFWorkbook myWorkBook = new
                HSSFWorkbook(myFileSystem);                 
            HSSFSheet mySheet = myWorkBook.getSheetAt(0);
                        Iterator rowIter = mySheet.rowIterator();
            while(rowIter.hasNext())
            {
                HSSFRow myRow = (HSSFRow) rowIter.next();
                Iterator cellIter = myRow.cellIterator();
                Vector cellStoreVector=new Vector();
                while(cellIter.hasNext()){
                HSSFCell myCell = (HSSFCell) cellIter.next();
                cellStoreVector.addElement(myCell);
            }
            cellVectorHolder.addElement(cellStoreVector);
        }
                        for(int i=0;i<cellVectorHolder.size();i++)
            {   String data=(String) cellVectorHolder.get(i);   }}}
second way
    public class ExcelActivity extends Activity {

 private String LOG_TAG = "ReadExcelFromUrl";
 ArrayList<ShoppingCart> shoppingCartList;    

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_comparison);

            // Hashmap for ListView

        // Loading Albums JSON in Background Thread
        new ExcelURL().execute();

        // get listview
        //ListView lv = getListView();

 }


private void displayCart() {

  //Array list of countries
  List<String> myList = new ArrayList<String>();
  for(int i = 0, l = shoppingCartList.size(); i < l; i++){
   ShoppingCart shoppingCart = shoppingCartList.get(i);
   String myData = shoppingCart.getItemNumber() + ": " +
       shoppingCart.getDescription() + "\nPrice: $" +
       shoppingCart.getPrice() + "\nQuantity: " +
       shoppingCart.getQuantity();
   myList.add(myData);
  }



 }


 private class ExcelURL extends AsyncTask<String, Void, String> {
  private static final int REGISTRATION_TIMEOUT = 3 * 1000;
  private static final int WAIT_TIMEOUT = 30 * 1000;
  private final HttpClient httpclient = new DefaultHttpClient();
  final HttpParams params = httpclient.getParams();
  HttpResponse response;
  private String content =  null;
  private ProgressDialog dialog = new ProgressDialog(ExcelActivity.this);

  protected void onPreExecute() {
   dialog.setMessage("Getting your data... Please wait...");
   dialog.show();
  }

  protected String doInBackground(String... urls) {

   String URL = null;

   BufferedReader br=null;
 StringBuffer sb=new StringBuffer();
       try {
        parseExcel( getAssets().open(
                        "book1.xls"));

        } catch (ClientProtocolException e) {
            Log.w("HTTP2:",e );
            content = e.getMessage();
            cancel(true);
           } catch (IOException e) {
            Log.w("HTTP3:",e );
            content = e.getMessage();
            cancel(true);
           }catch (Exception e) {
            Log.w("HTTP4:",e );
            content = e.getMessage();
            cancel(true);
           }

           return content;


  }

  protected void onCancelled() {
   dialog.dismiss();
   Toast toast = Toast.makeText(ExcelActivity.this, 
     "Error connecting to Server", Toast.LENGTH_LONG);
   toast.setGravity(Gravity.TOP, 25, 400);
   toast.show();

  }

  protected void onPostExecute(String content) {
   dialog.dismiss();
   displayCart();
   //Display the Excel data in a ListView
    // updating UI from Background Thread
    runOnUiThread(new Runnable() {
        public void run() {
            /**
             * Updating parsed JSON data into ListView
             * */
    /*      ListAdapter adapter = new SimpleAdapter(
                    ExcelActivity.this, shoppingCartList,
                    R.layout.list_item_comparision, new String[] { TAG_ID,
                            TAG_NAME,COMPLETE_NAME}, new int[] {
                            R.id.album_id, R.id.album_name,R.id.album_cname });

            // updating listview
            setListAdapter(adapter);*/
        }
    });
  }



  private void parseExcel(InputStream fis){

   shoppingCartList = new ArrayList<ShoppingCart>();    

   try{

    // Create a workbook using the Input Stream 
    HSSFWorkbook myWorkBook = new HSSFWorkbook(fis);

    // Get the first sheet from workbook 
    HSSFSheet mySheet = myWorkBook.getSheetAt(0);

    // We now need something to iterate through the cells
    Iterator<Row> rowIter = mySheet.rowIterator();
    while(rowIter.hasNext()){

     HSSFRow myRow = (HSSFRow) rowIter.next();
     // Skip the first 2 rows
     if(myRow.getRowNum() < 2) {
      continue;
     }

     ShoppingCart shoppingCart = new ShoppingCart();

     Iterator<Cell> cellIter = myRow.cellIterator();
     while(cellIter.hasNext()){

      HSSFCell myCell = (HSSFCell) cellIter.next();
      String cellValue = "";

      // Check for cell Type
      if(myCell.getCellType() == HSSFCell.CELL_TYPE_STRING){
       cellValue = myCell.getStringCellValue();
      }
      else {
       cellValue = String.valueOf(myCell.getNumericCellValue());
      }

      // Just some log information
      Log.v(LOG_TAG, cellValue);

      // Push the parsed data in the Java Object
      // Check for cell index
      switch (myCell.getColumnIndex()) {
      case 0: 
       shoppingCart.setItemNumber(cellValue);
       break;
      case 1: 
       shoppingCart.setDescription(cellValue);
       break;
      case 2: 
       shoppingCart.setPrice(Double.valueOf(cellValue));
       break;
      case 3: 
       shoppingCart.setQuantity(Double.valueOf(cellValue));
       break;
      default: 
       break;
      }

     }

     // Add object to list
     shoppingCartList.add(shoppingCart);
    }
   }
   catch (Exception e){
    e.printStackTrace(); 
   }

  }

 }
}

Could not find class 'java.awt.font.FontRenderContext', referenced from method org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn

Could not find class 'java.awt.font.FontRenderContext', referenced from method org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn Could not find class 'java.awt.font.FontRenderContext', referenced from method org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn

please suggest the issues