Current version number: v3.0.5
1. Download the SDK extract and import (Import Module,compile project (':P ushsdk ')), there is a demo, with the demo's package name to add an application to the official website, Then replace the demo in the manifest file inside the Appkey and Message_secret, you can run directly.
2. Initializing the SDK
- public class App extends application {
- Public pushagent mpushagent;
- @Override
- Public void onCreate() {
- super.oncreate ();
- Mpushagent = Pushagent.getinstance (this);
- //Register push service, callback this interface every time the register method is called
- Mpushagent.register (new Iumengregistercallback () {
- @Override
- Public void onsuccess(String devicetoken) {
- //Successful registration will return device token
- LOG.E ("Devicetoken-------", Devicetoken);
- }
- @Override
- Public void onfailure(string s, string s1) {
- }
- });
- Mpushagent.setpushintentserviceclass (Umengpushintentservice.class);
- }
- }
This is already ready for testing.
3. Open the specified page
Baunianga activity name, com.umeng.demo.SecondActivity
4. Custom Parameters
Customizing a service to inherit Umengmessageservice
public class UmengPushIntentService extends UmengMessageService {
- @Override
- Public void onMessage(context context, Intent Intent) {
- Intent data = new Intent (Intent);
- Data.setclass (context, testactivity.class);
- //need to add Flag:Intent.FLAG_ACTIVITY_NEW_TASK for Intent, otherwise the ACTIVITY cannot be started.
- Data.setflags (Intent.flag_activity_new_task);
- Context.startactivity (data);
- }
- }
In the jump activity to receive data and parse
- public class testactivity extends appcompatactivity {
- public static final String TAG = "testactivity";
- @Override
- protected void onCreate(Bundle savedinstancestate) {
- super.oncreate (savedinstancestate);
- Setcontentview (r.layout.activity_test);
- final String message = Getintent (). Getstringextra (message_body);
- if (textutils.isempty (message))
- return;
- final umessage msg;
- try {
- msg = New Umessage (new Jsonobject (message));
- Utrack.getinstance (this). Trackmsgclick (msg);
- map<string, string> extra = Msg.extra;
- LOG.D (TAG, "message=" + message); //message body
- LOG.D (TAG, "custom=" + msg.custom); //Customize the contents of the message
- LOG.D (TAG, "title=" + msg.title); //Notification title
- LOG.D (TAG, "text=" + msg.text); //notification content
- Alertdialog Dialog;
- if (null! = Extra && Extra.containskey ("Msgtype"))
- Dialog = New Alertdialog.builder (this)
- . Settitle ("if message hint")
- . Setmessage (msg.text+"11111")
- . setcancelable (false)
- . Setpositivebutton ("Confirm", new Dialoginterface.onclicklistener () {
- @Override
- Public void onClick(dialoginterface dialog, int which) {
- }
- })
- . Create ();
- Else
- Dialog = New Alertdialog.builder (this)
- . Settitle ("Else message hint")
- . Setmessage (Msg.text)
- . setcancelable (false)
- . Setpositivebutton ("confirm", null)
- . Create ();
- Dialog.setondismisslistener (new Dialoginterface.ondismisslistener () {
- @Override
- Public void ondismiss(Dialoginterface Dialog) {
- Onbackpressed ();
- }
- });
- Dialog.show ();
- } catch (Jsonexception e) {
- E.printstacktrace ();
- }
- }
- }
The custom service needs to be called in the application class
mPushAgent.setPushIntentServiceClass(UmengPushIntentService.class);
At the same time you need to register at manifest
- <service android:name=". Umengpushintentservice "
- android:process=":p ush"/>
Official Document: Http://dev.umeng.com/push/android/integration#4
Android Friend League push