Android Open Source - wifi-auto-forget Hockey Sender






From Project

Back to project page wifi-auto-forget.

License

The source code is released under:

GNU General Public License

If you think the Android project wifi-auto-forget listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package antoche;
// www . ja va2 s  . c  o  m
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
import org.acra.ACRA;
import org.acra.collector.CrashReportData;
import org.acra.ReportField;
import org.acra.sender.ReportSender;
import org.acra.sender.ReportSenderException;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;

/**
 * Pasted (and lightly adapted) from https://gist.github.com/antoche/5123357
 * @author Antoine Bouthors https://github.com/antoche
 */
public class HockeySender implements ReportSender {
  private static final String BASE_URL = "https://rink.hockeyapp.net/api/2/apps/";
  private static final String CRASHES_PATH = "/crashes";
 
  @Override
  public void send(CrashReportData report) throws ReportSenderException {
    String log = createCrashLog(report);
    String url = BASE_URL + ACRA.getConfig().formKey() + CRASHES_PATH;
 
    try {
      DefaultHttpClient httpClient = new DefaultHttpClient(); 
      HttpPost httpPost = new HttpPost(url);
 
      List<NameValuePair> parameters = new ArrayList<NameValuePair>(); 
      parameters.add(new BasicNameValuePair("raw", log));
      parameters.add(new BasicNameValuePair("userID", report.get(ReportField.INSTALLATION_ID)));
      parameters.add(new BasicNameValuePair("contact", report.get(ReportField.USER_EMAIL)));
      parameters.add(new BasicNameValuePair("description", report.get(ReportField.USER_COMMENT)));
      
      httpPost.setEntity(new UrlEncodedFormEntity(parameters, HTTP.UTF_8));
 
      httpClient.execute(httpPost);   
    }
    catch (Exception e) {
      e.printStackTrace();
    } 
  }
 
  private String createCrashLog(CrashReportData report) {
    Date now = new Date();
    StringBuilder log = new StringBuilder();
    
    log.append("Package: ").append(report.get(ReportField.PACKAGE_NAME)).append("\n");
    log.append("Version: ").append(report.get(ReportField.APP_VERSION_CODE)).append("\n");
    log.append("Android: ").append(report.get(ReportField.ANDROID_VERSION)).append("\n");
    log.append("Manufacturer: ").append(android.os.Build.MANUFACTURER).append("\n");
    log.append("Model: ").append(report.get(ReportField.PHONE_MODEL)).append("\n");
    log.append("Date: ").append(now).append("\n");
    log.append("\n");
    log.append(report.get(ReportField.STACK_TRACE));
    log.append("\n");
    
    // Print one-liners first
    for( Map.Entry<ReportField, String> reportField : report.entrySet() )
    {
      String value = reportField.getValue();
      if( !value.endsWith( "\n" ) )
      {
        log.append( reportField.getKey().name() + ": " + value + "\n" );
      }
    }
    
    // Then print big items
    for( Map.Entry<ReportField, String> reportField : report.entrySet() )
    {
      String value = reportField.getValue();
      if( value.endsWith( "\n" ) )
      {
        log.append( "-------------------------------------------------------------------------------------------\n" );
          log.append( reportField.getKey().name() + ":\n" );
        log.append( value );
      }
    } 
    return log.toString();
  }
}




Java Source Code List

antoche.HockeySender.java
com.cebesius.wifiautoforget.Secrets.java
com.cebesius.wifiautoforget.WifiAutoForgetApplication.java
com.cebesius.wifiautoforget.activity.AutoForgetWifisActivity.java
com.cebesius.wifiautoforget.adapter.AutoForgetWifisAdapter.java
com.cebesius.wifiautoforget.dialog.ChangeAutoForgetBehaviorDialog.java
com.cebesius.wifiautoforget.domain.AutoForgetWifi.java
com.cebesius.wifiautoforget.gateway.AddWifiNotificationUsageStorage.java
com.cebesius.wifiautoforget.gateway.AutoForgetWifiStorage.java
com.cebesius.wifiautoforget.gateway.NotificationIds.java
com.cebesius.wifiautoforget.gateway.SharedPreferenceKeys.java
com.cebesius.wifiautoforget.gateway.UserPreferenceStorage.java
com.cebesius.wifiautoforget.model.AutoForgetWifiModel.java
com.cebesius.wifiautoforget.mvp.ActivityView.java
com.cebesius.wifiautoforget.mvp.AddWifiModel.java
com.cebesius.wifiautoforget.mvp.AddWifiPresenter.java
com.cebesius.wifiautoforget.mvp.AddWifiView.java
com.cebesius.wifiautoforget.mvp.AppModel.java
com.cebesius.wifiautoforget.mvp.AppPresenter.java
com.cebesius.wifiautoforget.mvp.AppView.java
com.cebesius.wifiautoforget.mvp.AutoForgetWifisModel.java
com.cebesius.wifiautoforget.mvp.AutoForgetWifisPresenter.java
com.cebesius.wifiautoforget.mvp.AutoForgetWifisView.java
com.cebesius.wifiautoforget.mvp.ConnectivityChangeModel.java
com.cebesius.wifiautoforget.mvp.ConnectivityChangePresenter.java
com.cebesius.wifiautoforget.mvp.ConnectivityChangeView.java
com.cebesius.wifiautoforget.receiver.ConnectivityChangeReceiver.java
com.cebesius.wifiautoforget.service.AddWifiService.java
com.cebesius.wifiautoforget.service.ConnectivityChangeService.java
com.cebesius.wifiautoforget.util.AutoForgetDelegate.java
com.cebesius.wifiautoforget.util.BusPortal.java
com.cebesius.wifiautoforget.widget.AutoForgetWifiItem.java