Всем доброго дня, с Android разработкой только знакомлюсь, прошу не кидать камни. Решил в свое приложение интегрировать AppsFlyer SDK для дальнейшего отслеживания трафика, делал все по инструкции, но при попытке компилирования приложение запускается, но сразу же вылетает. Не подскажите куда смотреть, чтобы исправить данную проблему. Заранее спасибо.
Документация по SDK
Мой код:
build.gradle
repositories {
maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.9'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
repositories {
maven { url 'https://maven.google.com' }
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
manifestPlaceholders = [
onesignal_app_id: 'ad7d98b3-c263-4065-a891-bd884fb6753a',
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: 'REMOTE'
]
applicationId "com.example.quizshow"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.onesignal:OneSignal:3.15.4'
implementation 'com.appsflyer:af-android-sdk:5.4.5'
implementation 'com.appsflyer:af-android-sdk:5.4.5'
implementation 'com.android.installreferrer:installreferrer:2.1'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
MainActivity
public class MainActivity extends AppCompatActivity {
private static String AF_DEV_KEY = "xULabDxxCwdQhvLXMM3DZF";
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AppsFlyerConversionListener conversionListener = new AppsFlyerConversionListener() {
@Override
public void onConversionDataSuccess(Map<String, Object> conversionData) {
for (String attrName : conversionData.keySet()) {
Log.d("LOG_TAG", "attribute: " + attrName + " = " + conversionData.get(attrName));
}
}
@Override
public void onConversionDataFail(String errorMessage) {
Log.d("LOG_TAG", "error getting conversion data: " + errorMessage);
}
@Override
public void onAppOpenAttribution(Map<String, String> attributionData) {
for (String attrName : attributionData.keySet()) {
Log.d("LOG_TAG", "attribute: " + attrName + " = " + attributionData.get(attrName));
}
}
@Override
public void onAttributionFailure(String errorMessage) {
Log.d("LOG_TAG", "error onAttributionFailure : " + errorMessage);
}
};
AppsFlyerLib.getInstance().init(AF_DEV_KEY, conversionListener, this);
// Logging set to help debug issues, remove before releasing your app.
OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE);
// OneSignal Initialization
OneSignal.startInit(this)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.unsubscribeWhenNotificationsAreDisabled(true)
.init();
setContentView(R.layout.activity_main);
WebView webView = findViewById(R.id.webView);
WebSettings settings = webView.getSettings();
webView.loadUrl("https://www.youtube.com/");
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSaveFormData(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setSupportMultipleWindows(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setCacheMode(2);
webView.getSettings().setLoadWithOverviewMode(true);
webView.setWebContentsDebuggingEnabled(true);
webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; Android 7.1; Mi A1 Build/N2G47H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.83 Mobile Safari/537.36");
this.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
WebViewClient webViewClient = new WebViewClient() {
@SuppressWarnings("deprecation")
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@TargetApi(Build.VERSION_CODES.N)
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(request.getUrl().toString());
return true;
}
};
webView.setWebViewClient(webViewClient);
AppsFlyerLib.getInstance().startTracking(this);
}
}
AndroidManifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.quizshow">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- Optional : -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:name="com.example.quizshow.MainActivity"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.QuizShow">
<activity android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.appsflyer.SingleInstallBroadcastReceiver" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
</application>
</manifest>
В манифесте с <application до все подсвечивается желтым.
лог ошибок
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.quizshow, PID: 6170
java.lang.RuntimeException: Unable to instantiate application com.example.quizshow.MainActivity: java.lang.ClassCastException: com.example.quizshow.MainActivity cannot be cast to android.app.Application
at android.app.LoadedApk.makeApplication(LoadedApk.java:1244)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6683)
at android.app.ActivityThread.access$1300(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.ClassCastException: com.example.quizshow.MainActivity cannot be cast to android.app.Application
at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
at androidx.core.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:52)
at android.app.Instrumentation.newApplication(Instrumentation.java:1158)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1236)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6683)
at android.app.ActivityThread.access$1300(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Насколько я понял, в объекте a будут доступны только те переменные и методы, которые есть в классе A, но запускаться они будут из класса BНо вот...
Мне нужно программно получить полный номер фискального регистратора(ФР), я использую метод getPhysicalDeviceName:
Необходимо сделать, чтобы при нажатии кнопки Back на телефоне приложение не закрывалосьНашел код на форуме, вроде бы расставил все куда нужно,...