Я работаю над проектом, в котором используются службы уведомлений OneSignal Pu sh, я следовал документации https://documentation.onesignal.com/docs/android-sdk-setup и настраивал все, но при запуске приложения я получаю вышеуказанную ошибку , Я следовал за несколькими ответами, но все они не смогли мне помочь, как лучше всего решить эту ошибку.
Вот мой AndroidManifest. xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zara.cash">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<application
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/AppThemeNO"
android:usesCleartextTraffic="true"
android:screenOrientation="portrait">
<activity android:name=".VerifyOTPActivity" android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"></activity>
<activity android:name=".SendOTPActivity" android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden" />
<activity android:name=".ForgotPinActivity" android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden" />
<activity android:name=".LoanIneligibleActivity" android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden" />
<activity
android:name=".loans.LoanTransactionsActivity"
android:label="Loan Transactions"
android:theme="@style/AppTheme" android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden" />
<activity
android:name=".loans.LoanHistoryActivity"
android:label="Loan Statement"
android:theme="@style/AppTheme" android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden" />
<activity
android:name=".loans.PayLoanActivity"
android:label="Pay loan"
android:theme="@style/AppTheme" android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden" />
<activity
android:name=".loans.WithdrawActivity"
android:label="Withdraw"
android:theme="@style/AppTheme" android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden" />
<activity
android:name=".loans.ApplyLoanActivity"
android:label="New loan"
android:theme="@style/AppTheme" android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden" />
<activity
android:name=".PermissionsActivity"
android:label="Permissions"
android:theme="@style/AppTheme" android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden" />
<activity
android:name=".RegistrationActivity"
android:theme="@style/AppTheme" android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden" />
<activity
android:name=".HomeActivity"
android:label=""
android:icon="@drawable/icon_launcher"
android:theme="@style/AppTheme.NoActionBar" android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden" />
<activity
android:name=".Slider.MainSliderActivity"
android:label="@string/title_activity_home"
android:theme="@style/AppTheme.NoActionBar" android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyBozgdcoXc0xTs3jcqUvx4oJIh2af1tjuY" />
<activity android:name=".LoginActivity" android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden" />
<activity android:name=".LandingActivity" android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden" />
<activity android:name=".MainActivity" android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".SmsBroadcastReceiver">
<intent-filter android:priority="100">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
</manifest>
Вот мой build.gradle
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.4, 0.99.99]'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
repositories {
maven { url 'https://maven.google.com' }
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.zara.cash"
manifestPlaceholders = [
onesignal_app_id: '*************************************',
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: 'REMOTE'
]
minSdkVersion 16
targetSdkVersion 29
versionCode 14
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.navigation:navigation-fragment:2.0.0'
implementation 'androidx.navigation:navigation-ui:2.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.android.material:material:1.0.0'
//Verification code editText
implementation 'com.justkiddingbaby:vercodeedittext:1.1.0'
//map
implementation 'com.google.android.gms:play-services-maps:16.1.0'
implementation 'com.google.android.libraries.places:places:1.1.0'
//Directions
implementation 'com.google.maps:google-maps-services:0.10.1'
//dialog for location permission
implementation 'com.karumi:dexter:5.0.0'
//Volley library
implementation 'com.android.volley:volley:1.1.0'
//circular progression bar
implementation 'com.mikhaellopez:circularprogressbar:3.0.3'
//Lottie Library
implementation "com.airbnb.android:lottie:3.4.0"
implementation 'com.google.android.gms:play-services-maps:16.1.0'
//Material Design
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.google.android.material:material:1.2.0-alpha03'
implementation 'com.google.android.gms:play-services-auth-api-phone:17.0.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
//one signal
implementation 'com.onesignal:OneSignal:[3.13.0, 3.99.99]'
}
А это мой Класс PushNotification
package com.zara.cash.notifications;
import android.app.Application;
import com.onesignal.OneSignal;
public class PushNotification extends Application {
@Override
public void onCreate() {
super.onCreate();
OneSignal.setLogLevel(OneSignal.LOG_LEVEL.DEBUG, OneSignal.LOG_LEVEL.DEBUG);
// OneSignal Initialization
OneSignal.startInit(this)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.unsubscribeWhenNotificationsAreDisabled(true)
.init();
}
}
Вот мои разрешения Активность
package com.zara.cash;
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.zara.cash.Slider.MainSliderActivity;
import java.util.ArrayList;
import java.util.List;
import static androidx.constraintlayout.widget.Constraints.TAG;
public class PermissionsActivity extends AppCompatActivity {
private static final int PERMISSION_REQUESTS = 1;
private Button grantBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_permissions);
if (allPermissionsGranted()){
startActivity(new Intent(PermissionsActivity.this, MainSliderActivity.class));
finish();
return;
}else {
getRuntimePermissions();
}
//init
grantBtn = findViewById(R.id.grantBtn);
grantBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getRuntimePermissions();
}
});
}
private String[] getRequiredPermissions() {
try {
PackageInfo info =
this.getPackageManager()
.getPackageInfo(this.getPackageName(), PackageManager.GET_PERMISSIONS);
String[] ps = info.requestedPermissions;
if (ps != null && ps.length > 0) {
return ps;
} else {
return new String[0];
}
} catch (Exception e) {
return new String[0];
}
}
private boolean allPermissionsGranted() {
for (String permission : getRequiredPermissions()) {
if (!isPermissionGranted(PermissionsActivity.this, permission)) {
return false;
}
}
return true;
}
private void getRuntimePermissions() {
List<String> allNeededPermissions = new ArrayList<>();
for (String permission : getRequiredPermissions()) {
if (!isPermissionGranted(PermissionsActivity.this, permission)) {
allNeededPermissions.add(permission);
}
}
if (!allNeededPermissions.isEmpty()) {
ActivityCompat.requestPermissions(PermissionsActivity.this, allNeededPermissions.toArray(new String[0]), PERMISSION_REQUESTS);
}
}
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onRequestPermissionsResult(
int requestCode, String[] permissions, int[] grantResults) {
Log.i(TAG, "Permission granted!");
if (allPermissionsGranted()) {
startActivity(new Intent(PermissionsActivity.this, MainSliderActivity.class));
finish();
return;
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
private static boolean isPermissionGranted(Context context, String permission) {
if (ContextCompat.checkSelfPermission(context, permission)
== PackageManager.PERMISSION_GRANTED) {
Log.i(TAG, "Permission granted: " + permission);
return true;
}
Log.i(TAG, "Permission NOT granted: " + permission);
return false;
}
}