小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

android – ACRA 4.9.0:如何將ACRA報(bào)告寫入文件(在應(yīng)用程序數(shù)據(jù)文件夾中)

 印度阿三17 2019-07-06

我想使用最新的Acra 4.9.0在文本文件中編寫崩潰報(bào)告.
我可以舉例說明這個(gè)最新版本.
我嘗試使用可用的文檔.

Acra已啟用
但它,不是寫在文件中.

myApp

 package com.myApp;

import org.acra.ACRA;

import android.app.AlertDialog;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.KeyEvent;
import android.view.View;

import com.myApp.Application.AppLauncher;
import com.myApp.interfaces.AppEvents;
import com.myApp.R;
import com.utils.Config;
import com.utils.Constants;
import com.utils.DeviceValidator;

public class myApp extends FragmentActivity
{
    private AppLauncher appLauncher = null;


    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

        if(!ACRA.isACRASenderServiceProcess())
        {
            setContentView(R.layout.activity_myApp);

            appLauncher = new AppLauncher();

            appLauncher.registerEventListener(appEventsListener);

            appLauncher.initApp(this);

        }
    }

    @Override
    public void onPause() {
        super.onPause();

        if(!DeviceValidator.isDeviceValid())
        {
            return;
        }

        appLauncher.activityOnPause();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
    }

    @Override
    protected void onStart() 
    {
        super.onStart();
    }

    @Override
    public void onResume()
    {
        super.onResume();

        appLauncher.activityOnResume();
    }
}

AcraApplication

    package com.myAPP;

    import org.acra.ACRA;
    import org.acra.ReportField;
    import org.acra.ReportingInteractionMode;
    import org.acra.annotation.ReportsCrashes;
    import org.acra.sender.HttpSender.Method;

    import android.app.Application;

    @ReportsCrashes(
            formUri = "http://staging./variable_dump/index.php",
            customReportContent = { ReportField.REPORT_ID, ReportField.DEVICE_ID, ReportField.APP_VERSION_NAME, ReportField.ANDROID_VERSION, ReportField.STACK_TRACE, ReportField.CUSTOM_DATA, ReportField.LOGCAT },
            httpMethod = Method.POST,
            reportSenderFactoryClasses = org.acra.util.MyOwnSenderFactory.class,
            mode = ReportingInteractionMode.SILENT
    )

    public class AcraApplication extends Application
    {
        public AcraApplication() 
        {
            super();
        }

        @Override
        public void onCreate() {
            super.onCreate();
            ACRA.init(this);
        }

    }

MyOwnSender

package org.acra.util;

import java.io.File;
import java.io.FileOutputStream;

import org.acra.ReportField;
import org.acra.collector.CrashReportData;
import org.acra.config.ACRAConfiguration;
import org.acra.sender.ReportSender;
import org.acra.sender.ReportSenderException;

import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;

public class MyOwnSender implements ReportSender  {
    private static final String FILE_NAME = "AcraReport.txt";
    //private final Map<ReportField, String> mMapping = new HashMap<ReportField, String>();
    //private FileWriter crashReport = null;

    MyOwnSender(Context context,  @NonNull ACRAConfiguration config)
    {
        Log.d("testAcra", "MyOwnSender created");
       /* File logFile = new File(context.getFilesDir().getPath()   "/"   FILE_NAME, FILE_NAME);

        try {
            crashReport = new FileWriter(logFile, true);
        } catch (IOException e) {
            e.printStackTrace();
        }*/
    }

    @Override
    public void send(Context context, CrashReportData report) throws ReportSenderException
    {
            // Iterate over the CrashReportData instance and do whatever
            // you need with each pair of ReportField key / String value

         String finalReport = createCrashReport(report);
         String tempFile = context.getFilesDir().getPath()   "/"   FILE_NAME;

        try
        {            
            File detailedFile = new File(tempFile); 

            if(!detailedFile.exists())
                detailedFile.createNewFile();

            FileOutputStream stream = new FileOutputStream(detailedFile, true);

            stream.write(finalReport.getBytes());
            Log.d("testAcra","adding to file: " stream);
            stream.close();

           }
       catch (Exception e)
       { 

        e.printStackTrace(); 
       }
     /*final Map<String, String> finalReport = remap(report);

         try {
             BufferedWriter buf = new BufferedWriter(crashReport);

             Set<Entry<String, String>> set = reportBody.entrySet();
             Iterator<Entry<String, String>> i = set.iterator();

             while (i.hasNext()) {
                 Map.Entry<String, String> me = (Entry<String, String>) i.next();
                 buf.append("["   me.getKey()   "]="   me.getValue());
             }

             buf.flush();
             buf.close();
         } catch (IOException e) {
             Log.e("TAG", "IO ERROR", e);
         }*/
    }

    private String createCrashReport(CrashReportData crashReportData){
        StringBuilder body = new StringBuilder();

        body.append("ReportID : "   crashReportData.getProperty(ReportField.REPORT_ID))
                .append("\n")
                .append("DeviceID : "   crashReportData.getProperty(ReportField.DEVICE_ID))
                .append("\n")
                .append("AppVersionName : "   crashReportData.getProperty(ReportField.APP_VERSION_NAME))
                .append("\n")
                .append("Android Version : "   crashReportData.getProperty(ReportField.ANDROID_VERSION))
                .append("\n")
                .append("CustomData : "   crashReportData.getProperty(ReportField.CUSTOM_DATA))
                .append("\n")
                .append("STACK TRACE : \n"   crashReportData.getProperty(ReportField.STACK_TRACE))
                .append("\n")
                .append("LogCAT : \n"   crashReportData.getProperty(ReportField.LOGCAT));

        return body.toString();
    }

 /*   private Map<String, String> remap(Map<ReportField, String> report) {

       Set<ReportField>fields = ACRA.getConfig().getReportFields();


        final Map<String, String> finalReport = new HashMap<String, String>(report.size());
        for (ReportField field : fields)
        {
            if (mMapping == null || mMapping.get(field) == null) 
                finalReport.put(field.toString(), report.get(field));
             else 
                finalReport.put(mMapping.get(field), report.get(field));
        }
        return finalReport;
    }*/
}

MyOwnSenderFactory

package org.acra.util;

import org.acra.config.ACRAConfiguration;
import org.acra.sender.ReportSender;
import org.acra.sender.ReportSenderFactory;

import android.content.Context;
import android.support.annotation.NonNull;

public class MyOwnSenderFactory implements ReportSenderFactory {

     // NB requires a no arg constructor.
    /*MyOwnSenderFactory()
    {
         Log.e("testAcra", "MyOwnSenderFactory created");
    }*/

    @Override
    @NonNull
    public ReportSender create(@NonNull Context context, @NonNull ACRAConfiguration config) {
        // TODO Auto-generated method stub
        return new MyOwnSender(context, config);
    }
}

解決方法:

因?yàn)槲沂褂玫氖莏ar文件而不是aar
在我的清單中我失蹤了

 <service
            android:name="org.acra.sender.SenderService"
            android:exported="false"
            android:process=":acra" />
enter code here

那就是為什么SendeService在Acra中使用的原因并沒有開始.

來源:https://www./content-1-303501.html

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多