Pages

April 16, 2014

Android Custom Crash Reporting Dialog & Reporting Data


MainApplication
package com.yourpkg;

import android.app.Application;
import android.content.Intent;
import android.util.Log;

public class MainApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        Thread.setDefaultUncaughtExceptionHandler(new TopExceptionHandler(this));
    }

    public class TopExceptionHandler implements Thread.UncaughtExceptionHandler {

        private Application app = null;
        
        public TopExceptionHandler(Application app) {
            Thread.setDefaultUncaughtExceptionHandler(this);
            this.app = app;
        }

        public void uncaughtException(Thread t, Throwable e) {
            
            Log.v("tagas","uncaught exception ");
            
            StackTraceElement[] arr = e.getStackTrace();
            String report = e.toString() + "\n\n";
            report += "--------- Stack trace ---------\n\n";
            for (int i = 0; i < arr.length; i++) {
                report += "    " + arr[i].toString() + "\n";
            }
            report += "-------------------------------\n\n";

            // If the exception was thrown in a background thread inside
            // AsyncTask, then the actual exception can be found with getCause
            report += "--------- Cause ---------\n\n";
            Throwable cause = e.getCause();
            if (cause != null) {
                report += cause.toString() + "\n\n";
                arr = cause.getStackTrace();
                for (int i = 0; i < arr.length; i++) {
                    report += "    " + arr[i].toString() + "\n";
                }
            }
            report += "-------------------------------\n\n";

            final String reportText=report;

            Log.d("atag","report["+report+"]");

            notifyDialog(reportText);
            android.os.Process.killProcess(android.os.Process.myPid());
            System.exit(1);
           
        }
        
        void notifyDialog(String reportText) {
            try {
                Log.d("atg", "Creating Dialog for " + reportText);
                Intent dialogIntent = new Intent(app.getApplicationContext(), CrashReportDialog.class);
                dialogIntent.putExtra("CRASH_LOG", reportText);
                dialogIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                app.getApplicationContext().startActivity(dialogIntent);
                
                
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

}


CrashReportDialog

package com.example.exceptionhandlr;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class CrashReportDialog extends Activity implements OnClickListener {

    String VersionName;
    String PackageName;
    String FilePath;
    String PhoneModel;
    String AndroidVersion;
    String Board;
    String Brand;
    String Device;
    String Display;
    String FingerPrint;
    String Host;
    String ID;
    String Manufacturer;
    String Model;
    String Product;
    String Tags;
    long Time;
    String Type;
    String User;
    
    Context mContext;
    String crashLog="TEXT";
    private Button buttonSubmitReport;
    private Button buttonSubmitCancle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.crashreport_activity);

        mContext = this;

        if (getIntent().getStringExtra("CRASH_LOG") != null) {
            crashLog = getIntent().getStringExtra("CRASH_LOG");
        }
        // showDialog(text);
        crashLog += CreateInformationString();

        ((TextView) findViewById(R.id.text1)).setText(crashLog);
        buttonSubmitReport = (Button) findViewById(R.id.buttonSumbmitReport);
        buttonSubmitCancle = (Button) findViewById(R.id.buttonCancleReport);
        buttonSubmitReport.setOnClickListener(this);
        buttonSubmitCancle.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.buttonSumbmitReport:
            sendEmailErrorReport(crashLog);
            break;

        case R.id.buttonCancleReport:
            restartApp();
            break;

        default:
            break;
        }
    }

    public void sendEmailErrorReport(String bodyContent) {

        final Intent emailIntent = new Intent(
                android.content.Intent.ACTION_SEND);

        // open with email supported apps
        emailIntent.setType("message/rfc822");

        // support mail from string.xml
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                new String[] { getString(R.string.support_email) });

        // AppName + Subject text from string.xml
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                getString(R.string.app_name)+getString(R.string.support_crash_subj));

        // Inital body text from string.xml + crash log 
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                getString(R.string.support_crash_body) + bodyContent);

        finish();
        
        startActivity(Intent.createChooser(emailIntent, "Send Report"));

        // restart app
        // restartApp();
        
    }

    public void restartApp() {
        Intent i = getBaseContext().getPackageManager()
                .getLaunchIntentForPackage(getBaseContext().getPackageName());
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        
        finish();
        startActivity(i);
    }
    

    void RecoltInformations(Context context) {
        try {
            PackageManager pm = context.getPackageManager();
            PackageInfo pi;
            // Version
            pi = pm.getPackageInfo(context.getPackageName(), 0);
            VersionName = pi.versionName;
            // Package name
            PackageName = pi.packageName;
            // Device model
            PhoneModel = android.os.Build.MODEL;
            // Android version
            AndroidVersion = android.os.Build.VERSION.RELEASE;

            Board = android.os.Build.BOARD;
            Brand = android.os.Build.BRAND;
            Device = android.os.Build.DEVICE;
            Display = android.os.Build.DISPLAY;
            FingerPrint = android.os.Build.FINGERPRINT;
            Host = android.os.Build.HOST;
            ID = android.os.Build.ID;
            Model = android.os.Build.MODEL;
            Product = android.os.Build.PRODUCT;
            Tags = android.os.Build.TAGS;
            Time = android.os.Build.TIME;
            Type = android.os.Build.TYPE;
            User = android.os.Build.USER;

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public String CreateInformationString() {
        RecoltInformations(mContext);

        String ReturnVal = "";
        ReturnVal += "Version : " + VersionName;
        ReturnVal += "\n";
        ReturnVal += "Package : " + PackageName;
        ReturnVal += "\n";
        ReturnVal += "FilePath : " + FilePath;
        ReturnVal += "\n";
        ReturnVal += "Phone Model" + PhoneModel;
        ReturnVal += "\n";
        ReturnVal += "Android Version : " + AndroidVersion;
        ReturnVal += "\n";
        ReturnVal += "Board : " + Board;
        ReturnVal += "\n";
        ReturnVal += "Brand : " + Brand;
        ReturnVal += "\n";
        ReturnVal += "Device : " + Device;
        ReturnVal += "\n";
        ReturnVal += "Display : " + Display;
        ReturnVal += "\n";
        ReturnVal += "Finger Print : " + FingerPrint;
        ReturnVal += "\n";
        ReturnVal += "Host : " + Host;
        ReturnVal += "\n";
        ReturnVal += "ID : " + ID;
        ReturnVal += "\n";
        ReturnVal += "Model : " + Model;
        ReturnVal += "\n";
        ReturnVal += "Product : " + Product;
        ReturnVal += "\n";
        ReturnVal += "Tags : " + Tags;
        ReturnVal += "\n";
        ReturnVal += "Time : " + Time;
        ReturnVal += "\n";
        ReturnVal += "Type : " + Type;
        ReturnVal += "\n";
        ReturnVal += "User : " + User;
        ReturnVal += "\n";
        // ReturnVal += "Total Internal memory : " +
        // getTotalInternalMemorySize();
        // ReturnVal += "\n";
        // ReturnVal += "Available Internal memory : "
        // + getAvailableInternalMemorySize();
        ReturnVal += "\n";

        return ReturnVal;
    }

}


MainActivity

package com.example.exceptionhandlr;

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);
        
        findViewById(R.id.buttonCreateCrash).setOnClickListener(new OnClickListener() {
            
            @Override
            public void onClick(View v) {

                // DIVIDE by ZERO Error
                // THIS LINE CAUSE EXCEPTION
                int i=55/0;
            }
        });
        
    }
}

April 11, 2014

Why Web Based Software As A Service is Getting Popularity These Days?

Software As A Service (SAAS ) is now-a-days becoming too much viral in the software industry as it is very convenient to vendors as well as users. Many of us is not knowing what is software as a service, How it works and How it can benefit us in our work ? At SoftwareSuggest, we often get these questions from our users.

Software as a service is nothing but the software delivery method which provides access to the software and all its functionalities from anywhere and on any device remotely. Software as a Service allows organizations to access and manage their data at low costs than buying a licensed software as SAAS is mostly based on a monthly subscriptions. As software is hosted remotely, organizations don't have any additional expenses on hardware like servers. Software as a service makes organizations free from setting up and installation of software, backing up data and maintenance costs and problems of hardware.

In Software as a service, software and its associated data is hosted on the cloud than it is accessed by users using thin client via web browser on any device. Below are common reasons why web based software as a service is getting popular these days and why organizations should switch to SAAS -

  • Fast setup and installation
  • Non-Technical Configuration
  • Little IT involvement.
  • Integrated MDM Support
  • Upgrades included.
  • Frequent New Features.
  • No Hardware Costs.
  • Subscription Billing.

March 20, 2014

SoftwareSuggest.com‏ - Find Best Software For Business in India, Made In India Softwares

What is Software Suggest?

Software Suggest is a free service that helps Indian business, companies, organization, professionals and individuals find the best software solution for their business.

What can Software Suggest do for me?

In its Browse Software segment, Software Suggest provides a wide list of option for various business function like Accounting, Human Resource Management etc, and for various industry starting from Agriculture to Pharmaceuticals, so Indian business owner can select the best software fit for their business.
You can start browsing the available software options by clicking here.

However, if the user is still not sure as to which software shall be fitting his requirement best, he/she can contact our software expert who will help him/her come down to 1-3 best matches. To connect to our expert click here.

Everyday hundreds of Business uses SoftwareSuggest to find right Accounting Software, HR Software, Payroll Software, CRM Software, Helpdesk Software, Pharmaceutical Software, Email Marketing Software in India. Primarily Software Suggest Lists Made In India Software Product.