Aurora push jpush (easy to understand, teach you to do it in minutes)

Register an account first:

Then click on Developer Services: Click on the open link

Create an application:

Name whatever you want, but preferably the same as your app name

Then click Next to push the settings

Enter your project application name:

The application package name is the applicationId name [in the build.gradle] file

Click to download Demo after completion

After the demo is downloaded, unzip it, zip the package
, copy all the tool jar packages in the libs folder to your project, remember to compile

Import the jar package in the file into the libs folder in the project and refer to it, and 
copy the res folder directly to the main folder under the src folder in the project, 
it will directly fill in the missing parts in your project, so Don’t be afraid it will replace your original file

Developers using android studio, if you use the jniLibs folder to import the so file, you only need to copy all the cpu type folders in; if you add the so file to the libs folder of the module, pay attention to adding it in the gradle configuration of the module Let’s configure:

sourceSets {
    main {
        jniLibs.srcDirs = ['libs']
    }
}

Be careful, don’t forget the jniLibs empty folder

MyApp class (remember to add name in manifest file)

public  class  MyApp  extends  Application  {
     public  static String registrationId ; //Get the device unique ID RegistrationID pushed by Jiguang

    @Override
    public void onCreate() {
        super.onCreate();


        //Jiguang push 
        JPushInterface.setDebugMode( true );     // Set open log, please close the log when publishing 
        JPushInterface.init( this );   // Initialize JPush

        registrationId = JPushInterface.getRegistrationID( this ); //Get the device unique ID RegistrationID for Jiguang push 
        Log.e( "111111registrationId" , "run:--------->:" + registrationId );
    }
}

MyReceiver

TestActivity

Logger

MyReceiver
package com.sgy.sgy_jpush;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Iterator;
import cn.jpush.android.api.JPushInterface;

/**
 * custom receiver
 * 
 * If this Receiver is not defined, then:
 * 1) The default user will open the main interface
 * 2) Cannot receive custom message
 */
public class MyReceiver extends BroadcastReceiver {
    private static final String TAG = "JIGUANG-Example";

    @Override
    public void onReceive(Context context, Intent intent) {
        try {
            Bundle bundle = intent.getExtras();
            Logger.d(TAG, "[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle));

            if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
                String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
                //send the Registration Id to your server...

            } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
                Logger.d(TAG, "[MyReceiver] receives the push custom message: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));
 // processCustomMessage(context, bundle);

            } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
                Logger.d(TAG, "[MyReceiver] received a push notification" );
                 int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
                Logger.d(TAG, "[MyReceiver] ID of the push notification received: " + notifactionId);

            } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
                Logger.d(TAG, "[MyReceiver] user clicked to open the notification" );

                //Open custom Activity 
                Intent i = new Intent(context, TestActivity.class);
                i.putExtras(bundle);
                //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP );
                context.startActivity(i);

            } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {
                Logger.d(TAG, "[MyReceiver] The user receives RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA));
                 //Here, the code is processed according to the content of JPushInterface.EXTRA_EXTRA, such as opening a new Activity, opening a web page etc...

            } else if(JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
                boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
                Logger.w(TAG, "[MyReceiver]" + intent.getAction() +" connected state change to "+connected);
            } else {
                Logger.d(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction());
            }
        } catch (Exception e){

        }

    }

    // print all intent extra data 
    private  static String printBundle (Bundle bundle)  {
        StringBuilder sb = new StringBuilder();
        for (String key : bundle.keySet()) {
            if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {
                sb.append("\nkey:" + key + ", value:" + bundle.getInt(key));
            }else if(key.equals(JPushInterface.EXTRA_CONNECTION_CHANGE)){
                sb.append("\nkey:" + key + ", value:" + bundle.getBoolean(key));
            } else if (key.equals(JPushInterface.EXTRA_EXTRA)) {
                if (TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_EXTRA))) {
                    Logger.i(TAG, "This message has no Extra data");
                    continue;
                }

                try {
                    JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));
                    Iterator<String> it =  json.keys();

                    while (it.hasNext()) {
                        String myKey = it.next();
                        sb.append("\nkey:" + key + ", value: [" +
                                myKey + " - " +json.optString(myKey) + "]");
                    }
                } catch (JSONException e) {
                    Logger.e(TAG, "Get message extra JSON error!");
                }

            } else {
                sb.append("\nkey:" + key + ", value:" + bundle.get(key));
            }
        }
        return sb.toString();
    }

    //send msg to MainActivity
//  private void processCustomMessage(Context context, Bundle bundle) {
//      if (MainActivity.isForeground) {
//          String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
//          String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
//          Intent msgIntent = new Intent(MainActivity.MESSAGE_RECEIVED_ACTION);
//          msgIntent.putExtra(MainActivity.KEY_MESSAGE, message);
//          if (!ExampleUtil.isEmpty(extras)) {
//              try {
//                  JSONObject extraJson = new JSONObject(extras);
//                  if (extraJson.length() > 0) {
//                      msgIntent.putExtra(MainActivity.KEY_EXTRAS, extras);
//                  }
//              } catch (JSONException e) {
//
//              }
//
//          }
//          LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent);
//      }
//  }
}
TestActivity
package com.sgy.sgy_jpush;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;
import cn.jpush.android.api.JPushInterface;

public class TestActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TextView tv = new TextView(this);
        tv.setText( "User-defined open Activity" );
        Intent intent = getIntent();
        if (null != intent) {
            Bundle bundle = getIntent().getExtras();
            String title = null;
            String content = null;
            if(bundle!=null){
                title = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);
                content = bundle.getString(JPushInterface.EXTRA_ALERT);
            }
            tv.setText("Title : " + title + "  " + "Content : " + content);
        }
        addContentView(tv, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    }

}
Logger 
package com.sgy.sgy_jpush;

import android.util.Log;

/**
 * Created by efan on 2017/4/13.
 */

public class Logger {

    //Set to false to close the log 
    private  static  final  boolean LOG_ENABLE = true ;

    public static void i(String tag, String msg){
        if (LOG_ENABLE){
            Log.i(tag, msg);
        }
    }
    public static void v(String tag, String msg){
        if (LOG_ENABLE){
            Log.v(tag, msg);
        }
    }
    public static void d(String tag, String msg){
        if (LOG_ENABLE){
            Log.d(tag, msg);
        }
    }
    public static void w(String tag, String msg){
        if (LOG_ENABLE){
            Log.w(tag, msg);
        }
    }
    public static void e(String tag, String msg){
        if (LOG_ENABLE){
            Log.e(tag, msg);
        }
    }
}

Manifest file: add permissions:

<!-- Required -->
    <permission
        android:
        android:protectionLevel="signature" />

    <!-- Required some permissions required by the system, such as access to the network, etc.--> 
    < uses-permission  android:name = "com.sgy.sgy_jpush.permission.JPUSH_MESSAGE" /> 
    < uses-permission  android:name = "android. permission.RECEIVE_USER_PRESENT" /> 
    < uses-permission  android:name = "android.permission.INTERNET" /> 
    < uses-permission  android:name = "android.permission.READ_PHONE_STATE" /> 
    < uses-permission  android:name = "android .permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android: />
    <uses-permission android: />
    <uses-permission android: />
    <uses-permission android: />
    <uses-permission android: />

    <!-- Optional for location --> 
    < uses-permission  android:name = "android.permission.VIBRATE" /> 
    < uses-permission  android:name = "android.permission.SYSTEM_ALERT_WINDOW" />  <!-- for Open the debug version of the application to cascade the window permissions on the 6.0 system --> 
    < uses-permission  android:name = "android.permission.ACCESS_COARSE_LOCATION" /> 
    < uses-permission  android:name = "android.permission.CHANGE_WIFI_STATE" /> 
    < uses-permission  android:name = "android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android: />
    <uses-permission android: />
    <uses-permission android: />

<!-- For test only test status notification bar, need to open Activity --> 
        < activity  android:name = "com.sgy.sgy_jpush.TestActivity"  android:exported = "false" > 
            < intent-filter > 
                < action  android :name = "jpush.testAction" /> 
                < category  android:name = "jpush.testCategory" /> 
            </ intent-filter > 
        </ activity >

        <activity
            android:
            android:theme="@style/MyDialogStyle"
            android:exported="false">
        </activity>

        <activity
            android:
            android:configChanges="orientation|keyboardHidden"
            android:theme="@android:style/Theme.NoTitleBar"
            android:exported="false">
            <intent-filter>
                <action android: />
                <category android: />
                <category android: />
            </intent-filter>
        </activity>

        <!-- Required SDK core functions--> 
        <!-- Configurable android:process parameter to put PushService in other processes--> 
        < service 
            android:name = "cn.jpush.android.service.PushService" 
            android: process = ":pushcore" 
            android:exported = "false" > 
            < intent-filter > 
                < action  android:name = "cn.jpush.android.intent.REGISTER" /> 
                < action  android:name = "cn.jpush.android .intent.REPORT" /> 
                < action  android:name = "cn.jpush.android.intent.PushService" />
                <action android: />
            </intent-filter>
        </service>
        <provider
            android:authorities="com.sgy.sgy_jpush.DataProvider"
            android:
            android:process=":pushcore"
            android:exported="false"
            />

        <!-- since 1.8.0 option optional. The function that JPush services used for different applications in the same device pull up each other. --> 
        <!-- If you do not enable this function, you can delete this component, and it will not be able to pull up other applications or be pulled up by other applications--> 
        < service 
            android:name = "cn.jpush.android.service.DaemonService" 
            android:enabled = "true" 
            android:exported = "true" > 
            < intent-filter > 
                < action  android:name = "cn.jpush.android.intent.DaemonService" /> 
                < category  android:name = "com.sgy. sgy_jpush" /> 
            </ intent-filter >

        </service>
        <provider
            android:authorities="com.sgy.sgy_jpush.DownloadProvider"
            android:
            android:exported="true"
            />
        <receiver
            android:
            android:enabled="true"
            android:exported="false">
            <intent-filter android:priority="1000">
                <category android: />
            </intent-filter>
            <intent-filter>
                <action android: />
                <action android: />
            </intent-filter>
            <!-- Optional -->
            <intent-filter>
                <action android: />
                <action android: />

                <data android:scheme="package" />
            </intent-filter>
        </receiver>

        <receiver android:/>

        <!-- User defined. For test only User-defined broadcast receiver --> 
        < receiver 
            android:name = "com.sgy.sgy_jpush.MyReceiver" 
            android:exported = "false" 
            android:enabled = "true" > 
            < intent-filter > 
                < action  android:name = "cn.jpush.android.intent.REGISTRATION" />  <!--Required user registration SDK intent--> 
                < action  android:name = "cn.jpush.android. intent.MESSAGE_RECEIVED" />  <!--Required intent--> 
                < action  android: />  <!--Required Intent--> for users to receive SDK notification bar information 
                < action  android:name = "cn.jpush.android.intent.NOTIFICATION_OPENED" />  <! --Required user to open the intent of the custom notification bar--> 
                < action  android:name = "cn.jpush.android.intent.CONNECTION" /> <!-- Receive network changes connect/disconnect since 1.6.3 -- > 
                < category  android:name = "com.sgy.sgy_jpush" /> 
            </ intent-filter > 
        </ receiver >

        <!-- Required . Enable it you can get statistics data with channel --> 
        < meta-data  android:name = "JPUSH_CHANNEL"  android:value = "developer-default" /> 
        < meta-data  android:name = "JPUSH_APPKEY "  android:value = "da075747e2a374d552993f2a" />  <!-- </>The value comes from the AppKey obtained from the developer platform-->

Then run the project:

On Back to Aurora Platform: Click to open the link

Hahaha, then you can receive push messages, isn’t it easy! ! !

Finally, attach the complete AndroidManifest.xml manifest file:

    package=”com.sgy.sgy_jpush”>


            android:
        android:protectionLevel=”signature” />


   
   
   
   
   
   
   
   
   


   
   
   
   
   
   
   

        android:
        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/AppTheme”>
       
           
               


           
       


       
           
               
               
           

       

            android:
            android:theme=”@style/MyDialogStyle”
            android:exported=”false”>
       

            android:
            android:configChanges=”orientation|keyboardHidden”
            android:theme=”@android:style/Theme.NoTitleBar”
            android:exported=”false”>
           
               
               
               
           

       


       
                    android:
            android: process=”:pushcore”
            android:exported=”false”>
           
               
               
               
               
           

       
                    android:authorities=”com.sgy.sgy_jpush.DataProvider”
            android:
            android:process=”:pushcore”
            android:exported=”false”
            />


       
                    android:
            android:enabled=”true”
            android:exported=”true”>
           
               
               
           


                    android:authorities=”com.sgy.sgy_jpush.DownloadProvider”
            android:
            android:exported=”true”
            />
                    android:
            android:enabled=”true”
            android:exported=”false”>
           
               
               
           

           
               
               
           

           
           
               
               


           
       


                    android:
            android:exported=”false”
            android:enabled=”true”>
           
               
               
               
               
               
               
           

       


       
       

Leave a Comment

Your email address will not be published. Required fields are marked *