2017-07-26 55 views
0

我在使用ACRA Android上我的應用程序Android Studio和我相當確信一切都正確設置:ACRA不工作,但我正確設置它

package prospect.firmname.net.prospect; 
import android.app.Application; 
import android.content.Context; 

import org.acra.*; 
import org.acra.annotation.*; 
import org.acra.sender.HttpSender; 

import static org.acra.ACRA.log; 

@ReportsCrashes(
    formUri = "http://prospect.firmname.net/report.php", 
    reportType = HttpSender.Type.JSON, 
    httpMethod = HttpSender.Method.POST, 
    customReportContent = { 
      ReportField.APP_VERSION_CODE, 
      ReportField.APP_VERSION_NAME, 
      ReportField.ANDROID_VERSION, 
      ReportField.PACKAGE_NAME, 
      ReportField.REPORT_ID, 
      ReportField.BUILD, 
      ReportField.STACK_TRACE 
    }, 
    mode = ReportingInteractionMode.TOAST 
) 
public class ProspectApplication extends Application { 
    @Override 
    public void onCreate() { 
     super.onCreate(); 
     log.e("ACRA BOOTING","OK"); 
     ACRA.init(this); 
    } 
    @Override 
    protected void attachBaseContext(Context base) { 
     super.attachBaseContext(base); 
     ACRA.init(this); 
    } 
    } 

我增加了log.e("ACRA BOOTING","OK");和它出現在調試,我把@overrides出於絕望,其實本來是作爲this page here

的mainfest看起來像這樣

<application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:name="ProspectApplication" 
     android:theme="@style/AppTheme">    
      ~~~~ 
    </application> 

的gradle這個文件看起來像這樣

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 24 
    buildToolsVersion "25.0.0" 
    defaultConfig { 
     applicationId "prospect.firmname.net.prospect" 
     minSdkVersion 14 
     targetSdkVersion 19 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    compile 'com.android.support:appcompat-v7:24.2.1' 
    compile 'com.googlecode.json-simple:json-simple:1.1' 
    compile 'ch.acra:acra:4.9.2' 
    testCompile 'junit:junit:4.12' 
} 

android { 
    useLibrary 'org.apache.http.legacy' 
} 

當我訪問的URL http://prospect.firmname.net/report.php手動(觸摸網站)它記錄的訪問,完全是因爲我使用此代碼(我添加了一個error_log中以100%的把握它的工作原理),它會記錄訪問的時候我做手工它從來沒有記錄,如果該應用程序崩潰訪問:

report.php 
<?php 
    // Outputs all POST parameters to a text file. The file name is the date_time of the report reception 
    error_log("_REQUEST called " . print_r($_REQUEST,true),0); 
    $fileName = 'acra/'.date('Y-m-d_H-i-s').'.txt'; 
    $file = fopen($fileName,'w') or die('Could not create report file: ' . $fileName); 
    foreach($_POST as $key => $value) { 
    $reportLine = $key." = ".$value."\n"; 
     fwrite($file, $reportLine) or die ('Could not write to report file ' . $reportLine); 
    } 
    fclose($file); 
?> 

誰能explin爲什麼沒有反應?

+0

在AndroidManifest.xml中,自定義應用程序類的名字,你應該在類名前加上一個點這樣的'機器人:name =「。ProspectApplication」',我相信你添加了互聯網權限 – MatPag

+0

謝謝:我把它改成'.',它沒有幫助,(這就是爲什麼'log.e'在那裏,跑了整個時間),是的,我有'<使用權限android:name =「android.permission.INTERNET」/> ' –

+0

但你打電話'log.e(「ACRA引導」,「確定」); 'ACRA.init(this)'行之前?在初始化庫之前不能發送錯誤... – MatPag

回答

0

首先,名稱前需要一個.android:name=".ProspectApplication"

其次,你有這樣一行:

mode = ReportingInteractionMode.TOAST 

但是你有沒有內容敬酒以示。您需要添加resToastId:

resToastText=R.string.errorMessage 

或沒有顯示在吐司

+0

謝謝,但我已經評論過「。」 TOAST(或沒有)與這些有什麼關係?如果你喜歡,請忽略該行。它不會使它工作 –

+0

吐司是我在他的代碼中看到的一個錯誤,他顯示了沒有內容的吐司。 – Zoe

相關問題