Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When disable notification it will direct call CrashReporterActivity #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public void onCreate() {
if (BuildConfig.DEBUG) {
//initialise reporter with external path
CrashReporter.initialize(this);

// test disable notification (call CrashReporterActivity)
CrashReporter.disableNotification();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,31 @@ public void onClick(View v) {


//Crashes and exceptions are also captured from other threads
new Thread(new Runnable() {
findViewById(R.id.catchException).setOnClickListener(new View.OnClickListener() {
@Override
public void run() {
public void onClick(View v) {
try {
context = null;
context.getResources();
} catch (Exception e) {
//log caught Exception
CrashReporter.logException(e);
}

}
}).start();
});
// new Thread(new Runnable() {
// @Override
// public void run() {
// try {
// context = null;
// context.getResources();
// } catch (Exception e) {
// //log caught Exception
// CrashReporter.logException(e);
// }
//
// }
// }).start();

mContext = this;
findViewById(R.id.crashLogActivity).setOnClickListener(new View.OnClickListener() {
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
android:textColor="@color/black"
android:textSize="14sp" />

<Button
android:id="@+id/catchException"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/catch_exception"
android:textColor="@color/black"
android:textSize="14sp" />

<Button
android:id="@+id/crashLogActivity"
android:layout_width="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<string name="index_out_of_bound_exception">IndexOutOfBound</string>
<string name="class_cast_exception">ClassCast Exeption</string>
<string name="array_store_exception">ArrayStoreException</string>
<string name="catch_exception">Exception</string>
<string name="add_your_crash">Add your own crash and check if it gets logged</string>
</resources>
7 changes: 6 additions & 1 deletion crashreporter/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
android:name=".CrashReporterInitProvider"
android:authorities="${applicationId}.CrashReporterInitProvider"
android:enabled="true"
android:exported="false" />
android:grantUriPermissions="true"
android:exported="false" >
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>

<activity
android:name=".ui.CrashReporterActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
import android.content.pm.ProviderInfo;
import android.database.Cursor;
import android.net.Uri;
import android.support.v4.content.FileProvider;

/**
* Created by amitshekhar on 16/11/16.
*/

public class CrashReporterInitProvider extends ContentProvider {
public class CrashReporterInitProvider extends FileProvider {


public CrashReporterInitProvider() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
Expand Down Expand Up @@ -75,10 +76,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

private void shareCrashReport(String filePath) {
Uri uri = FileProvider.getUriForFile(this, getPackageName() + ".CrashReporterInitProvider", new File(filePath));
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_TEXT, appInfo.getText().toString());
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filePath)));
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Share via"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@ private static void writeToFile(String crashReportPath, String filename, String
}

private static void showNotification(String localisedMsg, boolean isCrash) {
Context context = CrashReporter.getContext();

Intent intent = CrashReporter.getLaunchIntent();
intent.putExtra(Constants.LANDING, isCrash);
intent.setAction(Long.toString(System.currentTimeMillis()));

if (CrashReporter.isNotificationEnabled()) {
Context context = CrashReporter.getContext();
NotificationManager notificationManager = (NotificationManager) context.
getSystemService(NOTIFICATION_SERVICE);
createNotificationChannel(notificationManager, context);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_NOTIFICATION_ID);
builder.setSmallIcon(R.drawable.ic_warning_black_24dp);

Intent intent = CrashReporter.getLaunchIntent();
intent.putExtra(Constants.LANDING, isCrash);
intent.setAction(Long.toString(System.currentTimeMillis()));

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
builder.setContentIntent(pendingIntent);

Expand All @@ -119,6 +119,8 @@ private static void showNotification(String localisedMsg, boolean isCrash) {
builder.setColor(ContextCompat.getColor(context, R.color.colorAccent_CrashReporter));

notificationManager.notify(Constants.NOTIFICATION_ID, builder.build());
} else {
context.startActivity(intent);
}
}

Expand Down
4 changes: 4 additions & 0 deletions crashreporter/src/main/res/xml/provider_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>