Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sunpengfei
committed
Nov 30, 2018
1 parent
78c73f1
commit 5601e60
Showing
4 changed files
with
72 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 72 additions & 20 deletions
92
sample/src/main/java/com/dodola/breakpad/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,80 @@ | ||
package com.dodola.breakpad; | ||
|
||
import android.Manifest; | ||
import android.app.Activity; | ||
import android.content.pm.PackageManager; | ||
import android.os.Bundle; | ||
import android.os.Environment; | ||
import android.view.View; | ||
|
||
import com.sample.breakpad.BreakpadInit; | ||
|
||
import java.io.File; | ||
|
||
import androidx.core.app.ActivityCompat; | ||
import androidx.core.content.ContextCompat; | ||
|
||
|
||
public class MainActivity extends Activity { | ||
static { | ||
System.loadLibrary("crash-lib"); | ||
} | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
findViewById(R.id.crash_btn) | ||
.setOnClickListener( | ||
new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
crash(); | ||
} | ||
}); | ||
} | ||
|
||
public native void crash(); | ||
private static final int WRITE_EXTERNAL_STORAGE_REQUEST_CODE = 100; | ||
|
||
static { | ||
System.loadLibrary("crash-lib"); | ||
} | ||
|
||
private File externalReportPath; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
|
||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) | ||
!= PackageManager.PERMISSION_GRANTED) { | ||
ActivityCompat.requestPermissions( | ||
this, | ||
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, | ||
WRITE_EXTERNAL_STORAGE_REQUEST_CODE); | ||
} else { | ||
initExternalReportPath(); | ||
} | ||
|
||
findViewById(R.id.crash_btn) | ||
.setOnClickListener( | ||
new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
initBreakPad(); | ||
crash(); | ||
// copy core dump to sdcard | ||
} | ||
}); | ||
} | ||
|
||
private void initBreakPad() { | ||
if (externalReportPath == null) { | ||
externalReportPath = new File(getFilesDir(), "crashDump"); | ||
if (!externalReportPath.exists()) { | ||
externalReportPath.mkdirs(); | ||
} | ||
} | ||
BreakpadInit.initBreakpad(externalReportPath.getAbsolutePath()); | ||
} | ||
|
||
@Override | ||
public void onRequestPermissionsResult( | ||
int requestCode, String[] permissions, int[] grantResults) { | ||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
initExternalReportPath(); | ||
} | ||
|
||
private void initExternalReportPath() { | ||
externalReportPath = new File(Environment.getExternalStorageDirectory(), "crashDump"); | ||
if (!externalReportPath.exists()) { | ||
externalReportPath.mkdirs(); | ||
} | ||
} | ||
|
||
public native void crash(); | ||
} |
22 changes: 0 additions & 22 deletions
22
sample/src/main/java/com/dodola/breakpad/SampleApplication.java
This file was deleted.
Oops, something went wrong.
Binary file not shown.