如何从Android向Onesignal发送消息?

时间:2019-04-28 15:21:10

标签: java android firebase onesignal

如何从Android发送消息到 Onesignal,我已经审查了Onesignal网站上的一系列步骤 一切都很好,我做了电子邮件,一切都很好,但是我想发送问候消息

// -Main class 
public class MainActivity extends AppCompatActivity {

    private Button btn;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn = (Button) findViewById(R.id.btn1);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sendAmessage("domin@gmail.com");
                //   sendNotification(true);
            }
        });
        // End-----
    }

    private void sendAmessage(String email) {
        String emailAuthHash = "mail@gmail.com";
        Toast.makeText(MainActivity.this, "Don", Toast.LENGTH_LONG).show();
        //OneSignal.setEmail("aideveloper0@gmail.com");
        // Email auth hash generated from your server ..................
        OneSignal.setEmail(email, emailAuthHash, new OneSignal.EmailUpdateHandler() {
            @Override
            public void onSuccess() {
                // Email successfully synced with OneSignal
                Log.i("onSuccess", "it's well");
                //Toast.makeText(MainActivity.this, "Email successfully", Toast.LENGTH_LONG).show();
            }

            @Override
            public void onFailure(OneSignal.EmailUpdateError error) {
                Log.i("Field ", "it's bad :" + error.toString());
                // Error syncing email, check error.getType() and error.getMessage() for details
                //Toast.makeText(MainActivity.this, "Email Error" +error.toString(), Toast.LENGTH_LONG).show();
            }
        });
    }

}

等级:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
        maven { url 'https://plugins.gradle.org/m2/'}
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.11.0, 0.99.99]'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}



allprojects {
    repositories {
        google()
        jcenter()
        maven{url 'https://maven.google.com'}

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}


/// --------
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.onesignal"
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    android {
        defaultConfig {
            manifestPlaceholders = [
                    //
                    onesignal_app_id: 'e4c4c8bb-495b-4b53-94f7-b32eb5b991d6',
                    //PUT YOUR ONESIGNAL APP ID HERE
                    // Project number pulled from dashboard, local value is ignored.
                    onesignal_google_project_number: 'REMOTE'
            ]
        }
    }



    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}


dependencies {

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'

    testImplementation 'junit:junit:4.12'

    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'


    implementation 'com.onesignal:OneSignal:[3.9.1, 3.99.99]'

}
public class MyAppClass extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

          // OneSignal Initialization ..............
          OneSignal.startInit(this)
          .inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
          .unsubscribeWhenNotificationsAreDisabled(true)
          .init();

    }
}

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ahmed.onesignal" >
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:name=".MyAppClass"
        android:theme="@style/AppTheme" >
        <activity android:name="com.ahmed.onesignal.MainActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

0 个答案:

没有答案