You are on page 1of 3

package com.example.saurav.

calculator;
import
import
import
import
import
import
import
import
import
import
import

android.content.Intent;
android.graphics.Bitmap;
android.graphics.BitmapFactory;
android.net.Uri;
android.provider.MediaStore;
android.support.v7.app.AppCompatActivity;
android.os.Bundle;
android.util.Base64;
android.view.View;
android.widget.Button;
android.widget.Toast;

import
import
import
import
import
import
import
import
import
import

com.android.volley.AuthFailureError;
com.android.volley.Request;
com.android.volley.RequestQueue;
com.android.volley.Response;
com.android.volley.VolleyError;
com.android.volley.toolbox.StringRequest;
com.android.volley.toolbox.Volley;
com.google.android.gms.appindexing.Action;
com.google.android.gms.appindexing.AppIndex;
com.google.android.gms.common.api.GoogleApiClient;

import
import
import
import

java.io.ByteArrayOutputStream;
java.net.URL;
java.util.HashMap;
java.util.Map;

public class MainActivity extends AppCompatActivity {


Button btn1, btn2;
String imageInStringFormat = " ";
String url="http://www.programvara.in/keshav/poll_booth/upload.php";
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1 = (Button) findViewById(R.id.button);
btn2 = (Button) findViewById(R.id.button2);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent pclick = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(pclick, 100);
}
});
btn2.setOnClickListener(new View.OnClickListener() {
@Override

public void onClick(View v) {


RequestQueue rq= Volley.newRequestQueue(MainActivity.this);
StringRequest stringRequest=new StringRequest(Request.Method.POS
T,url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(MainActivity.this, response, Toast.LENGTH
_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
})
{
@Override
protected Map<String,String> getParams()throws AuthFailureEr
ror{
Map<String,String>params=new HashMap<String, String>();
params.put("uname","uname");
params.put("email","uemail");
params.put("upass","upass");
params.put("unumber","unumber");
params.put("udepart","udepart");
params.put("uyear","uyear");
params.put("upic",imageInStringFormat);
params.put("fname","fname");
params.put("simno","simno");
return params;
}
};
rq.add(stringRequest);

}
});
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data
) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100 && resultCode == RESULT_OK) {
Bitmap bm = data.getParcelableExtra("data");
}
}
public String getStringImage(Bitmap bmp) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG,50,baos);
byte[] imageBytes=baos.toByteArray();

String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);


return encodedImage;
}
@Override
public void onStart() {
super.onStart();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"Main Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app acti
vity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app URL is correct.
Uri.parse("android-app://com.example.saurav.calculator/http/host
/path")
);
AppIndex.AppIndexApi.start(client, viewAction);
}
@Override
public void onStop() {
super.onStop();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"Main Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app acti
vity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app URL is correct.
Uri.parse("android-app://com.example.saurav.calculator/http/host
/path")
);
AppIndex.AppIndexApi.end(client, viewAction);
client.disconnect();
}
}

You might also like