Search in sources :

Example 1 with SasquatchCrashesListener

use of com.microsoft.azure.mobile.sasquatch.utils.SasquatchCrashesListener in project mobile-center-sdk-android by Microsoft.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    sSharedPreferences = getSharedPreferences("Sasquatch", Context.MODE_PRIVATE);
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().build());
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().build());
    /* Set custom log URL if one was configured in settings. */
    String logUrl = sSharedPreferences.getString(LOG_URL_KEY, getString(R.string.log_url));
    if (!TextUtils.isEmpty(logUrl)) {
        MobileCenter.setLogUrl(logUrl);
    }
    /* Set listeners. */
    AnalyticsPrivateHelper.setListener(getAnalyticsListener());
    Crashes.setListener(new SasquatchCrashesListener(this));
    Distribute.setListener(new SasquatchDistributeListener());
    Push.setListener(getPushListener());
    /* Set distribute urls. */
    String installUrl = getString(R.string.install_url);
    if (!TextUtils.isEmpty(installUrl)) {
        Distribute.setInstallUrl(installUrl);
    }
    String apiUrl = getString(R.string.api_url);
    if (!TextUtils.isEmpty(apiUrl)) {
        Distribute.setApiUrl(apiUrl);
    }
    /* Enable Firebase analytics if we enabled the setting previously. */
    if (sSharedPreferences.getBoolean(FIREBASE_ENABLED_KEY, false)) {
        Push.enableFirebaseAnalytics(this);
    }
    /* Start Mobile center. */
    MobileCenter.start(getApplication(), sSharedPreferences.getString(APP_SECRET_KEY, getString(R.string.app_secret)), Analytics.class, Crashes.class, Distribute.class, Push.class);
    /* Print last crash. */
    Log.i(LOG_TAG, "Crashes.hasCrashedInLastSession=" + Crashes.hasCrashedInLastSession());
    Crashes.getLastSessionCrashReport(new ResultCallback<ErrorReport>() {

        @Override
        public void onResult(@Nullable ErrorReport data) {
            if (data != null) {
                Log.i(LOG_TAG, "Crashes.getLastSessionCrashReport().getThrowable()=", data.getThrowable());
            }
        }
    });
    /* Populate UI. */
    ((TextView) findViewById(R.id.package_name)).setText(String.format(getString(R.string.sdk_source_format), getPackageName().substring(getPackageName().lastIndexOf(".") + 1)));
    TestFeatures.initialize(this);
    ListView listView = (ListView) findViewById(R.id.list);
    listView.setAdapter(new TestFeaturesListAdapter(TestFeatures.getAvailableControls()));
    listView.setOnItemClickListener(TestFeatures.getOnItemClickListener());
}
Also used : SasquatchDistributeListener(com.microsoft.azure.mobile.sasquatch.SasquatchDistributeListener) TestFeaturesListAdapter(com.microsoft.azure.mobile.sasquatch.features.TestFeaturesListAdapter) ErrorReport(com.microsoft.azure.mobile.crashes.model.ErrorReport) StrictMode(android.os.StrictMode) ListView(android.widget.ListView) SasquatchCrashesListener(com.microsoft.azure.mobile.sasquatch.utils.SasquatchCrashesListener) TextView(android.widget.TextView)

Aggregations

StrictMode (android.os.StrictMode)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 ErrorReport (com.microsoft.azure.mobile.crashes.model.ErrorReport)1 SasquatchDistributeListener (com.microsoft.azure.mobile.sasquatch.SasquatchDistributeListener)1 TestFeaturesListAdapter (com.microsoft.azure.mobile.sasquatch.features.TestFeaturesListAdapter)1 SasquatchCrashesListener (com.microsoft.azure.mobile.sasquatch.utils.SasquatchCrashesListener)1