Android Friend League push

Source: Internet
Author: User

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

  1. public class App extends application {
  2. Public pushagent mpushagent;
  3. @Override
  4. Public void onCreate() {
  5. super.oncreate ();
  6. Mpushagent = Pushagent.getinstance (this);
  7. //Register push service, callback this interface every time the register method is called
  8. Mpushagent.register (new Iumengregistercallback () {
  9. @Override
  10. Public void onsuccess(String devicetoken) {
  11. //Successful registration will return device token
  12. LOG.E ("Devicetoken-------", Devicetoken);
  13. }
  14. @Override
  15. Public void onfailure(string s, string s1) {
  16. }
  17. });
  18. Mpushagent.setpushintentserviceclass (Umengpushintentservice.class);
  19. }
  20. }

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 {
    1. @Override
    2. Public void onMessage(context context, Intent Intent) {
    3. Intent data = new Intent (Intent);
    4. Data.setclass (context, testactivity.class);
    5. //need to add Flag:Intent.FLAG_ACTIVITY_NEW_TASK for Intent, otherwise the ACTIVITY cannot be started.
    6. Data.setflags (Intent.flag_activity_new_task);
    7. Context.startactivity (data);
    8. }
    9. }

In the jump activity to receive data and parse

  1. public class testactivity extends appcompatactivity {
  2. public static final String TAG = "testactivity";
  3. @Override
  4. protected void onCreate(Bundle savedinstancestate) {
  5. super.oncreate (savedinstancestate);
  6. Setcontentview (r.layout.activity_test);
  7. final String message = Getintent (). Getstringextra (message_body);
  8. if (textutils.isempty (message))
  9. return;
  10. final umessage msg;
  11. try {
  12. msg = New Umessage (new Jsonobject (message));
  13. Utrack.getinstance (this). Trackmsgclick (msg);
  14. map<string, string> extra = Msg.extra;
  15. LOG.D (TAG, "message=" + message); //message body
  16. LOG.D (TAG, "custom=" + msg.custom); //Customize the contents of the message
  17. LOG.D (TAG, "title=" + msg.title); //Notification title
  18. LOG.D (TAG, "text=" + msg.text); //notification content
  19. Alertdialog Dialog;
  20. if (null! = Extra && Extra.containskey ("Msgtype"))
  21. Dialog = New Alertdialog.builder (this)
  22. . Settitle ("if message hint")
  23. . Setmessage (msg.text+"11111")
  24. . setcancelable (false)
  25. . Setpositivebutton ("Confirm", new Dialoginterface.onclicklistener () {
  26. @Override
  27. Public void onClick(dialoginterface dialog, int which) {
  28. }
  29. })
  30. . Create ();
  31. Else
  32. Dialog = New Alertdialog.builder (this)
  33. . Settitle ("Else message hint")
  34. . Setmessage (Msg.text)
  35. . setcancelable (false)
  36. . Setpositivebutton ("confirm", null)
  37. . Create ();
  38. Dialog.setondismisslistener (new Dialoginterface.ondismisslistener () {
  39. @Override
  40. Public void ondismiss(Dialoginterface Dialog) {
  41. Onbackpressed ();
  42. }
  43. });
  44. Dialog.show ();
  45. } catch (Jsonexception e) {
  46. E.printstacktrace ();
  47. }
  48. }
  49. }

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

    1. <service android:name=". Umengpushintentservice "
    2. android:process=":p ush"/>

Official Document: Http://dev.umeng.com/push/android/integration#4

Android Friend League push

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.