All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.eg.agent.android.crash.crashReport Maven / Gradle / Ivy

There is a newer version: 2.1.3
Show newest version
package com.eg.agent.android.crash;


import android.util.Log;

import com.eg.agent.android.AgentConfiguration;
import com.eg.agent.android.AndroidAgentImpl;
import com.eg.agent.android.ApplicationInformation;
import com.eg.agent.android.trace.Trace;
import com.eg.agent.android.util.Util;
import com.eg.google.gson.Gson;

import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.net.URL;

public class crashReport  {
    private static String useSsl = AgentConfiguration.useSsl ? "https://" : "http://";
    static String apiType="ApiType";
    static String activityName="ActivityName";
    static Gson gson = new Gson();
    private static AndroidAgentImpl androidAgentimpl = new AndroidAgentImpl();
    private static final AgentConfiguration agentConfiguration = new AgentConfiguration();

    static String dev_info = gson.toJson(androidAgentimpl.getDeviceInformation());

    public crashReport() {
        Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread thread, Throwable e) {
            	Log.e("eGwefwerfwerew Agent$$$$$$$$$$$$$", e.getLocalizedMessage());
                handleUncaughtException(thread, e);
                System.exit(0);
            }
        });
    }
    public class UncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {

        @Override
        public void uncaughtException(Thread thread, Throwable ex) {

        }
        public UncaughtExceptionHandler() {}
    }
    private void handleUncaughtException(Thread thread, Throwable e) {
        final StringWriter sw = new StringWriter();
        final PrintWriter pw = new PrintWriter(sw, true);
        e.printStackTrace(pw);
        String crashMessage = sw.getBuffer().toString();
        Log.e("eG Agent$$$$$$$$$$$$$", crashMessage);
        Util.addStrictMode();
        String url = "" + useSsl + "" + AgentConfiguration.AndroidAppCommonDetails;
        try{
            URL obj = new URL(url);
            HttpURLConnection con = (HttpURLConnection) obj.openConnection();
            con.setRequestMethod("POST");

            JSONObject reqJsonObject=new JSONObject();
            AndroidAgentImpl androidAgentimpl = new AndroidAgentImpl();

            ApplicationInformation applicationInformation=new ApplicationInformation();
            reqJsonObject.put("app_name",androidAgentimpl.getApplicationInformation().getAppName() );
            reqJsonObject.put("crashdetails",crashMessage+"");
            reqJsonObject.put("InstrumentationType","Crash");
            reqJsonObject.put(activityName, Trace.getActiviteClassName());
            reqJsonObject.put("DeviceInformation", dev_info);
            reqJsonObject.put("applicationToken",agentConfiguration.getApplicationToken());

            // reqJsonObject.put(apiType, "crash");
            JSONObject mainjson=new JSONObject();
            mainjson.put("reqJson",reqJsonObject);
            String urlParameters = "app_name=" + AgentConfiguration.applicationName + "&crashdetails=" + crashMessage + "";
            // Send post request
           // Log.e("urlParameters", urlParameters);
            Log.e("Request Json Params \n", mainjson.toString());

            con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
            con.setDoOutput(true);
            DataOutputStream wr = new DataOutputStream(con.getOutputStream());
            wr.write(mainjson.toString().getBytes("UTF-8"));
            wr.flush();
            wr.close();
            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String inputLine;
            StringBuffer response = new StringBuffer();

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();
        }
        catch (Exception exception)
        {
            e.printStackTrace();
            Log.e("eG","Data send to eG Rum"+exception.getMessage());
        }
    }
}






© 2015 - 2024 Weber Informatics LLC | Privacy Policy