Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to call method in java from c# code?
    primarykey
    data
    text
    <p>I have written a method in android(java) i.e. is used to upload image to the server. I want this method to be called from c# code. How to go about i have no idea, the java code follows below?</p> <pre><code>protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button buttonUpload = (Button) findViewById(R.id.buttonUpload); buttonUpload.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); request.addProperty("imageName", imageName ); request.addProperty("base64String", compressedImageString); //request.addProperty("compressedImageBitmap", compressedImageBitmap); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.setOutputSoapObject(request); envelope.dotNet = true; try { HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); androidHttpTransport.call(SOAP_ACTION, envelope); SoapObject result = (SoapObject)envelope.bodyIn; if(result != null) { Toast.makeText(getApplicationContext(), result.getProperty(0).toString(), Toast.LENGTH_LONG).show(); } else { Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show(); } } catch (Exception e) { e.printStackTrace(); } } }); buttonBrowse = (Button) findViewById(R.id.buttonBrowse); buttonBrowse.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(position!= null){ showPopup(MainActivity.this, position); } } @SuppressWarnings("deprecation") private void showPopup(final Activity activity, Point position) { int popupWidth = 120; int popupHeight = 130; LinearLayout linearLayout = (LinearLayout) findViewById(R.id.popup); LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(LAYOUT_INFLATER_SERVICE); popupView = layoutInflater.inflate(R.layout.activity_popup, linearLayout); popupWindow = new PopupWindow(activity); popupWindow.setContentView(popupView); popupWindow.setWidth(popupWidth); popupWindow.setHeight(popupHeight); int offset_X = 85; int offset_Y = 5; popupWindow.setBackgroundDrawable(new BitmapDrawable()); popupWindow.showAtLocation(popupView, Gravity.NO_GRAVITY, position.x + offset_X, position.y + offset_Y); } }); } @Override public void onWindowFocusChanged(boolean hasFocus){ int[] location = new int[2]; buttonBrowse.getLocationOnScreen(location); position = new Point(); position.x = location[0]; position.y = location[1]; } public void buttonGallery_Click(View v){ Intent intent = new Intent( Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(intent, REQ_CODE_PICK_IMAGE); } public void buttonTakePhoto_Click(View v){ TakePhoto(); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent){ switch(requestCode) { case REQ_CODE_PICK_IMAGE: if(resultCode == RESULT_OK){ selectedImageUri = intent.getData(); selectedImageRealPath = getRealPathFromURI(selectedImageUri); String path = selectedImageRealPath; imageName = path.substring(path.lastIndexOf("/")+1, path.length()); imageSelected = BitmapFactory.decodeFile(selectedImageRealPath); final ImageView imageViewPhoto = (ImageView) findViewById(R.id.imageViewPhoto); imageViewPhoto.setImageBitmap(imageSelected); compressedImageString = imageCompression(selectedImageRealPath); } break; case CAMERA_REQUEST: try { if(resultCode == RESULT_OK){ selectedImageRealPath = getRealPathFromURI(selectedImageUri); imageSelected = BitmapFactory.decodeFile(selectedImageRealPath); final ImageView imageViewPhoto = (ImageView) findViewById(R.id.imageViewPhoto); imageViewPhoto.setImageBitmap(imageSelected); compressedImageString = imageCompression(selectedImageRealPath); } } catch(Exception e) { Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show(); } break; } popupWindow.dismiss(); } private void TakePhoto() { ContentValues values = new ContentValues(); imageName = String.valueOf(System.currentTimeMillis()); values.put(MediaStore.Images.Media.TITLE, imageName); selectedImageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, selectedImageUri); startActivityForResult(intent, CAMERA_REQUEST); } private String imageCompression(String filePath) { File imageFile = new File(filePath); FileInputStream fis = null; try { fis = new FileInputStream(imageFile); } catch(FileNotFoundException e) { e.printStackTrace(); } Bitmap bitmap = BitmapFactory.decodeStream(fis); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, 600, 300, false); scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 90, baos ); byte[] b = baos.toByteArray(); String imageString = Base64.encodeToString(b, Base64.DEFAULT); //byte[] imageByte = imageString.getBytes(); return imageString; </code></pre> <p>}</p> <pre><code>public String getRealPathFromURI(Uri contentUri) { try { String[] proj = {MediaStore.Images.Media.DATA}; @SuppressWarnings("deprecation") Cursor cursor = managedQuery(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } catch (Exception e) { return contentUri.getPath(); } } </code></pre> <p>}</p> <p>I want to call the method on buttonBrowse from c#</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload