activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="OneSignal Notification"
android:textSize="40sp"
android:textStyle="bold"
android:gravity="center"
android:layout_margin="16dp"/>
</RelativeLayout>
MainActivity.java
package trusof.com.onesignaldemo;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.onesignal.OneSignal;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Onesignal initialization
OneSignal.startInit(this)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.unsubscribeWhenNotificationsAreDisabled(true)
.init();
}
}
google-services.json
{
"project_info": {
"project_number": "859844779565",
"project_id": "onesignal-42b00",
"storage_bucket": "onesignal-42b00.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:859844779565:android:1add1f48153bcb6a0be2a4",
"android_client_info": {
"package_name": "trusof.com.onesignaldemo"
}
},
"oauth_client": [
{
"client_id": "859844779565-8lbpj7671t4ap14i6ildjq2dhph2t5do.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyDufwJEfLJEk5Yg5o5eU7lQDd4u2RgW81E"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "859844779565-8lbpj7671t4ap14i6ildjq2dhph2t5do.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
build.gradle (OneSignalDemo)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.3"
classpath 'com.google.gms:google-services:4.3.10'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (:app)
buildscript {
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 31
defaultConfig {
applicationId "trusof.com.onesignaldemo"
minSdkVersion 16
targetSdkVersion 31
versionCode 3
versionName "3.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
}
android {
defaultConfig {
manifestPlaceholders = [
onesignal_app_id: '7c2eef73-7293-4b19-9cd0-dc6eaa734139',
onesignal_google_project_number: 'REMOTE'
]
}
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'com.onesignal:OneSignal:3.15.3'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
apply plugin: 'com.google.gms.google-services'
Comments
Post a Comment