1, go to Jpush website to register an account, create your app, and get your app's Appkey
2, download the corresponding SDK on Jpush website, unzip it, copy all the files under the Libs file to the Libs file of your project.
3, add the corresponding permissions and activity in the manifest file (change the corresponding package name and the corresponding Appkey)
Androidmanifest.xml Permissions configuration: <?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "/http Schemas.android.com/apk/res/android "package=" the package name you applied "android:versioncode=" Android:versionname= "1.0.0" &G T <USES-SDK android:minsdkversion= "one" android:targetsdkversion= "/> <!--Required--<permission A Ndroid:name= "The package name you applied. Permission.jpush_message" android:protectionlevel= "signature"/> <!--Required-< Uses-permission android:name= "You Package.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.WAKE_LOCK"/> <uses-permission android:name= "Androi D.permission.read_phone_state "/> <uses-permission android:name=" Android.permission.WRITE_EXTERNAL_STORAGE " /> <uses-permission android:name= "android.permission.Read_external_storage "/> <uses-permission android:name=" Android.permission.VIBRATE "/> <uses-permissio n android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> <uses-permission android:name= " Android.permission.ACCESS_NETWORK_STATE "/> <uses-permission android:name=" android.permission.WRITE_ SETTINGS "/> <!--Optional. Required for location feature-<uses-permission android:name= "Android.permission.ACCESS_COARSE_LOCATION"/& Gt <uses-permission android:name= "Android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name= " Android.permission.CHANGE_WIFI_STATE "/> <uses-permission android:name=" android.permission.ACCESS_FINE_ Location "/> <uses-permission android:name=" Android.permission.ACCESS_LOCATION_EXTRA_COMMANDS "/> <uses -permission android:name= "Android.permission.CHANGE_NETWORK_STATE"/> App package name and Appkey replacement: <application Andro id:icon= "@drawable/ic_launcher" Android:label= "@string/app_name" android:name= "Your Application" > <!--Required SDK core functions-- <!--option since 2.0.5 configurable pushservice,daemonservice,pushreceiver,alarmreceiver android:process parameters to set Jpush related components to One independent process-<!--such as: android:process= ": Remote"--<service android:name= "Cn.jpush.andro Id.service.PushService "android:enabled=" true "android:exported=" false "> <intent-f ilter> <action android:name= "Cn.jpush.android.intent.REGISTER"/> <action androi D:name= "Cn.jpush.android.intent.REPORT"/> <action android:name= "Cn.jpush.android.intent.PushService" /> <action android:name= "Cn.jpush.android.intent.PUSH_TIME"/> </intent-filter> </service> <!--since 1.8.0 option available. The ability to pull together Jpush services for different applications in the same device. -<!--If you do not enable this feature to remove the component, it will not pull up other apps or be pulled from other apps--<service android:name= "Cn.jpush.android.service.DaemonService" android:enabled= "t Rue "android:exported=" true "> <intent-filter > <action android:name=" c N.jpush.android.intent.daemonservice "/> <category android:name=" The package name you applied "/> </inten T-filter> </service> <!--Required--<receiver android:name= "Cn.jpush . Android.service.PushReceiver "android:enabled=" true "> <intent-filter android:priority=" &G " T <action android:name= "Cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY"/> <category android:n Ame= "The package name you applied"/> </intent-filter> <intent-filter> <action Android:na Me= "Android.intent.action.USER_PRESENT"/> <action android:name= "Android.net.conn.CONNECTIVITY_CHANGE "/> </intent-filter> <!--Optional--<intent-filter> <action Andro Id:name= "Android.intent.action.PACKAGE_ADDED"/> <action android:name= "android.intent.action.PACKAGE_ Removed "/> <data android:scheme=" package "/> </intent-filter> </receiv Er> <!--Required SDK Core Features--<activity android:name= "Cn.jpush.android.ui.PushActivity" Android:configchanges= "Orientation|keyboardhidden" android:exported= "false" > <inten t-filter> <action android:name= "cn.jpush.android.ui.PushActivity"/> <category A Ndroid:name= "Android.intent.category.DEFAULT"/> <category android:name= "The package name you applied"/> < ;/intent-filter> </activity> <!--Required SDK Core Features--<service android:n Ame= "cn.jpUsh.android.service.DownloadService "android:enabled=" true "android:exported=" false "> < ;/service> <!--Required SDK Core Features--<receiver android:name= "Cn.jpush.android.service.AlarmReceiv Er "/> <!--User defined. User-defined broadcast receivers--<receiver android:name= "your own defined receiver" android:enabled= "true" > <intent-filter> <!--Required User Registration SDK intent--> <action Android:na Me= "Cn.jpush.android.intent.REGISTRATION"/> <action android:name= "Cn.jpush.android.intent.UNREGIST Ration "/> <!--Required user receives intent--> <action android:name= for SDK messages" cn.jpush.an Droid.intent.MESSAGE_RECEIVED "/> <!--Required user receives intent--> of SDK notification bar information <action Android:name= "Cn.jpush.android.intent.NOTIFICATION_RECEIVED"/> <!--Required User open Customintent--> <action android:name= "Cn.jpush.android.intent.NOTIFICATION_OPENED"/> in the notification bar <!--Optional User accepts the intent--> <action android:name= "cn.jpush.android of the rich Push Javascript callback function. Intent. Action_richpush_callback "/> <!--receive network changes connect/disconnect since 1.6.3--<action Androi D:name= "Cn.jpush.android.intent.CONNECTION"/> <category android:name= "The package name you applied"/> < ;/intent-filter> </receiver> <!--Required. For publish channel feature-<!--Jpush_channel is a handy way for developers to count APK distribution channels. -<!--For example:-<!--to Google Play apk can be set to Google-play; -<!--to other markets APK can be set to Xxx-market. -<!--The current report on this channel stats feature is not yet open. --<meta-data android:name= "Jpush_channel" android:value= "Developer-default"/> <!--Required. AppKey copied from Portal--<meta-data Android:name= "Jpush_appkey" android:value= "Your APPKEY"/> </application></manifest>
4, initialize the Jpush in the custom application
public class Exampleapplication extends application {@Override public void OnCreate () { super.oncreate (); Jpushinterface.setdebugmode (true); Jpushinterface.init (this);} }
This is basically OK, but to accept the custom message you need to write a broadcast recipient, and register it OK
Custom Broadcastreceiver Myjpushbroadcastreceiver.java
Package Com.example.jpush;import Android.content.broadcastreceiver;import Android.content.context;import Android.content.intent;import Android.os.bundle;import Android.util.log;import Cn.jpush.android.api.jpushinterface;public class Myjpushbroadcastreceiver extends Broadcastreceiver {@ overridepublic void OnReceive (context context, Intent Intent) {Bundle bundle = Intent.getextras (); if (JPushInterface.ACTION_REGISTRATION_ID.equals (Intent.getaction ())) {}else if (jpushinterface.action_message_rec Eived.equals (Intent.getaction ())) {System.out.println ("The custom message was received. Message content is: "+ bundle.getstring (jpushinterface.extra_message)); The custom message will not be displayed in the notification bar, the developer must write code to process} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals (Intent.getaction ())) { SYSTEM.OUT.PRINTLN ("Notification received"); Here you can do some statistics, or do some other work} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals (Intent.getaction ())) { System.out.println ("User clicked to open the notification");Here you can write your own code to define the behavior of the user after click Intent i = new Intent (context, mainactivity.class); Custom Open Interface I.setflags (intent.flag_activity_new_task); Context.startactivity (i); } else {}}}
This will allow us to push our own app's messages and notifications.
Implement message push (Jpush) in Android