Answer the question
In order to leave comments, you need to log in
How to properly integrate AppMetrica into an Andorid application?
I have a simple webview application:MainActivity.java
package com.asd.asdf;
import android.annotation.TargetApi;
import android.app.Application;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.yandex.metrica.YandexMetrica;
import com.yandex.metrica.YandexMetricaConfig;
public class MainActivity extends AppCompatActivity {
private WebView mainWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mainWebView = findViewById(R.id.webView);
WebSettings webSettings = mainWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mainWebView.loadUrl("https://site.com");
mainWebView.setWebViewClient(new WebViewClient());
}
private class MyWebViewClient extends WebViewClient {
@TargetApi(Build.VERSION_CODES.N)
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(request.getUrl().toString());
return true;
}
}
@Override
public void onBackPressed() {
if (mainWebView.canGoBack()) {
mainWebView.goBack();
} else {
super.onBackPressed();
}
}
}
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
// Creating an extended library configuration.
YandexMetricaConfig config = YandexMetricaConfig.newConfigBuilder("API").build();
// Initializing the AppMetrica SDK.
YandexMetrica.activate(getApplicationContext(), config);
// Automatic tracking of user activity.
YandexMetrica.enableActivityAutoTracking(this);
}
}
package com.asdf.asdf;
import android.app.Application;
import com.yandex.metrica.YandexMetrica;
import com.yandex.metrica.YandexMetricaConfig;
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
// Creating an extended library configuration.
YandexMetricaConfig config = YandexMetricaConfig.newConfigBuilder("api").build();
// Initializing the AppMetrica SDK.
YandexMetrica.activate(getApplicationContext(), config);
// Automatic tracking of user activity.
YandexMetrica.enableActivityAutoTracking(this);
}
}
Class MyApp is never used
it is a warning. Answer the question
In order to leave comments, you need to log in
The problem is that you didn't understand what MyApp is.
You need to specify it in the manifest.
https://developer.android.com/guide/topics/manifes...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question