1. Create a new project
----- Obtain the API key and secret key
2. Push settings
3. Create an android project and set the application package name to the same as the package name set in the push.
4. Download the Baidu cloud client SDK
5. Unzip and add the libs folder file to the corresponding path, and add the pushservice-4.2.0.63.jar to the build path
6. Add utils. Java in the demo \ SRC \ com \ Baidu \ push \ example path to the package.
7. Create the mypushmessagereceiver class and inherit the frontiapushmessagereceiver class.
8. Initialize all methods as prompted and rewrite the onicationicationclicked method.
/*** Function used to receive click notifications. Note: Before a push notification is clicked by a user, the application cannot obtain the notification content through the interface. ** @ Param context * @ Param title * the title of the push notification * @ Param Description * the description of the push notification * @ Param customcontentstring * Custom content, is an empty or JSON string */@ override public void onnotificationclicked (context, String title, string description, string customcontentstring) {string policystring = "Notification click Title = \" "+ title +" \ "Description = \" "+ description +" \ "customcontent =" + customcontentstring; log. D (TAG, no Tifystring); // custom Content acquisition method. mykey and myvalue correspond to the key and value set in the Custom content during notification push if (! Textutils. isempty (customcontentstring) {jsonobject customjson = NULL; try {customjson = new jsonobject (customcontentstring); string myvalue = NULL; If (customjson. isnull ("mykey") {myvalue = customjson. getstring ("mykey") ;}} catch (jsonexception e) {// todo auto-generated Catch Block E. printstacktrace () ;}}// demo display code. add your own processing logic updatecontent (context, policystring) Here.} private void updatecontent (context, string content) {mainactivity. url = "http://www.sina.com"; mainactivity. num = 1; intent = new intent (); intent. setclass (context. getapplicationcontext (), mainactivity. class); intent. addflags (intent. flag_activity_new_task); context. getapplicationcontext (). startactivity (intent );}
View code
9 modify the androidmanifest. xml file
---------------------- Modify the application node Android: Name = "com. Baidu. frontia. frontiaapplication"
---------------------- Register the mypushmessagereceiver class
The XML file is as follows:
<Application Android: hardwareaccelerated = "true" Android: icon = "@ drawable/icon" Android: Label = "Xiao Yang" Android: Name = "com. baidu. frontia. frontiaapplication "> <activity Android: configchanges =" orientation | keyboardhidden | keyboard | screensize | locale "Android: Label =" @ string/app_name "Android: launchmode =" singletop "Android: name = ". splashactivity "Android: screenorientation =" portrait "Android: theme =" @ Android: style/theme. black. notitlebar "Android: windowsoftinputmode =" adjustresize "> <intent-filter Android: Label =" @ string/launcher_name "> <action Android: Name =" android. intent. action. main "/> <category Android: Name =" android. intent. category. launcher "/> </intent-filter> </activity> <activity Android: configchanges =" keyboardhidden "Android: Name = ". guideactivity "Android: screenorientation =" portrait "Android: theme =" @ Android: style/theme. notitlebar. fullscreen "/> <activity Android: Name = ". mainactivity "/> <activity Android: configchanges =" orientation | keyboardhidden "Android: Label =" mediaviewactivity "Android: Name =" com. baidu. android. pushservice. richmedia. mediaviewactivity "/> <activity Android: configchanges =" orientation | keyboardhidden "Android: Label =" medialistactivity "Android: launchmode =" singletask "Android: Name =" com. baidu. android. pushservice. richmedia. medialistactivity "/> <er Android: Name =" com. hn. esgj. mypushmessagereceiver ">-<intent-filter>-<action Android: Name =" com. baidu. android. pushservice. action. message "/> <action Android: Name =" com. baidu. android. pushservice. action. receive "/> <action Android: Name =" com. baidu. android. pushservice. action. notification. click "/> </intent-filter> </Cycler> <Cycler Android: Name =" com. baidu. android. pushservice. pushservicereceiver "Android: Process =": bdservice_v1 ">-<intent-filter> <action Android: Name =" android. intent. action. boot_completed "/> <action Android: Name =" android.net. conn. connectivity_change "/> <action Android: Name =" com. baidu. android. pushservice. action. notification. show "/> <action Android: Name =" com. baidu. android. pushservice. action. media. click "/> </intent-filter> </Cycler> <Cycler Android: Name =" com. baidu. android. pushservice. registrationconfigurer "Android: Process =": bdservice_v1 ">-<intent-filter> <action Android: Name =" com. baidu. android. pushservice. action. method "/> <action Android: Name =" com. baidu. android. pushservice. action. bind_sync "/> </intent-filter> <action Android: Name =" android. intent. action. package_removed "/> <data Android: Scheme =" package "/> </intent-filter> </Cycler> <service android: exported =" true "Android: name = "com. baidu. android. pushservice. pushservice "Android: Process =": bdservice_v1 ">-<intent-filter> <action Android: Name =" com. baidu. android. pushservice. action. push_service "/> </intent-filter> </service> </Application>
View code
10. Enable this function in the oncreate method of the active node.
public void onCreate(Bundle savedInstanceState) { try{ PushManager.startWork(getApplicationContext(), PushConstants.LOGIN_TYPE_API_KEY, "KH2j92etnCvrO0WyDLUQob4z") ; }catch (Exception e){ } super.onCreate(savedInstanceState); //setContentView(R.layout.activity_main); Toast.makeText(getApplicationContext(), url, Toast.LENGTH_SHORT).show(); super.setBooleanProperty("loadInWebView", true); super.loadUrl(url); this.num=0; this.url="file:///android_asset/www/index.html"; }
View code
11. Go to the Baidu console to push notifications for testing
Theoretically successful, please download the corresponding SDK on the server side
Phonegap Baidu cloud push