极光推送(对客户端的app如天猫进行消息推送)

第一种:利用网页进行推送(下面按这种来介绍)

第二种:利用javase代码进行消息推送

使用步骤

1\登陆极光网址

2\注册后并登陆

3、点击用户名下的控制台

4、创建应用进入以下界面(只要填写应用名称,应用图标,应用包名即可,再点击下载最下方的创建我的应用即消息推送的sdkDemos可以进行消息推送的例子)

 

5、将下载下来的消息推送的sdkDemos导到excipse

6、在Demos中的ExampleApplication.java添加代码

 

第二个参数是手机的设备别名(在放手机电池的槽里可以看到IMEI的号就是)

7、在官方模拟器下运行Demos,在日志上有日志

 

如果成功运行了Demos后,在极光自己的账号登陆后创建的应用里,点击发送消息进入下面的界面:将手机的设备别名写的框里和写下发送的信息后,点击立即发送消息即可在自己的手机里看到推送的消息

 

 

 

怎么在自己的项目里做消息推送:

1、 将之前下载下来的消息推送Demos中的MyReicever.javaExampleUtilTestActivity三个文件copy到自己的项目里

2、 在自己项目中MainActivityoncreate里写registerMessageReceiver();并在MainActivity下添加以下代码

privateMessageReceiver mMessageReceiver;

        publicstaticfinal String MESSAGE_RECEIVED_ACTION = "com.example.jpushdemo.MESSAGE_RECEIVED_ACTION";

        publicstaticfinal String KEY_TITLE = "title";

        publicstaticfinal String KEY_MESSAGE = "message";

        publicstaticfinal String KEY_EXTRAS = "extras";

       

        publicvoid registerMessageReceiver() {

            mMessageReceiver = new MessageReceiver();

            IntentFilter filter = new IntentFilter();

            filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);

            filter.addAction(MESSAGE_RECEIVED_ACTION);

            registerReceiver(mMessageReceiver, filter);

        }

 

        publicclass MessageReceiver extendsBroadcastReceiver {

 

            @Override

            publicvoid onReceive(Context context, Intent intent) {

                if (MESSAGE_RECEIVED_ACTION.equals(intent.getAction())) {

                 String messge = intent.getStringExtra(KEY_MESSAGE);

                 String extras = intent.getStringExtra(KEY_EXTRAS);

                 StringBuilder showMsg = new StringBuilder();

                 showMsg.append(KEY_MESSAGE + " : " + messge + "\n");

                 if (!ExampleUtil.isEmpty(extras)){

                   showMsg.append(KEY_EXTRAS + " : " + extras + "\n");

                 }

//               setCostomMsg(showMsg.toString());

                }

            }

        }

3、 在清单中将

  <permission

        android:name="com.example.ex_example.permission.JPUSH_MESSAGE"

        android:protectionLevel="signature"/>

 

    <!-- Required  一些系统要求的权限,如访问网络等-->

    <uses-permission android:name="com.example.ex_example.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="android.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.WRITE_SETTINGS"/>

    <uses-permission android:name="android.permission.VIBRATE" />

    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> 

    <!-- Optional for location -->

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

    <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"/>

   

   

   

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>

    <uses-permission android:name="android.permission.VIBRATE" />

    <uses-permission android:name="android.permission.CAMERA" />

 

    <uses-feature android:name="android.hardware.camera" />

    <uses-feature android:name="android.hardware.camera.autofocus" />

<uses-permission android:name="android.permission.INTERNET"/>

 

<!--Required SDK核心功能-->

        <activity

            android:name="cn.jpush.android.ui.PushActivity"

            android:theme="@android:style/Theme.Translucent.NoTitleBar"

            android:configChanges="orientation|keyboardHidden">

            <intent-filter>

                <action android:name="cn.jpush.android.ui.PushActivity" />

                <category android:name="android.intent.category.DEFAULT" />

                <category android:name="com.example.ex_example" />

            </intent-filter>

        </activity>

       

       

         <!-- For test only 测试状态通知栏,需要打开的Activity -->

        <activity android:name="com.example.jpushdemo.TestActivity">

            <intent-filter>

                <action android:name="jpush.testAction" />

                <category android:name="jpush.testCategory" />

            </intent-filter>

        </activity>

        <!-- Required  SDK核心功能-->

        <service

            android:name="cn.jpush.android.service.DownloadService"

            android:enabled="true"

            android:exported="false">

        </service>

   

       

        <!-- Required SDK 核心功能-->

        <service

            android:name="cn.jpush.android.service.PushService"

            android:enabled="true"

            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:name="cn.jpush.android.intent.PUSH_TIME" />

               

            </intent-filter>

        </service>

       

        <!-- Required SDK核心功能-->

        <receiver

            android:name="cn.jpush.android.service.PushReceiver"

            android:enabled="true">

             <intent-filter android:priority="1000">

                <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY"/>   <!--Required  显示通知栏 -->

                <category android:name="com.example.ex_example" />

            </intent-filter>

            <intent-filter>

                <action android:name="android.intent.action.USER_PRESENT"/>

                <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>

            </intent-filter>

             <!-- Optional -->

            <intent-filter>

                <action android:name="android.intent.action.PACKAGE_ADDED"/>

                <action android:name="android.intent.action.PACKAGE_REMOVED"/>

                <data android:scheme="package" />

            </intent-filter>

  

        </receiver>

       

        <!-- Required SDK核心功能-->

        <receiver android:name="cn.jpush.android.service.AlarmReceiver"/>

       

        <!-- User defined.  For test only 用户自定义的广播接收器-->

        <receiver

            android:name="com.example.jpushdemo.MyReceiver"

            android:enabled="true">

            <intent-filter>

                <action android:name="cn.jpush.android.intent.REGISTRATION"/><!--Required  用户注册SDKintent-->

                <action android:name="cn.jpush.android.intent.UNREGISTRATION"/> 

                <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED"/><!--Required  用户接收SDK消息的intent-->

                <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED"/><!--Required  用户接收SDK通知栏信息的intent-->

                <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED"/><!--Required  用户打开自定义通知栏的intent-->

                <action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK"/><!--Optional 用户接受Rich Push Javascript 回调函数的intent-->

                <action android:name="cn.jpush.android.intent.CONNECTION"/><!-- 接收网络变化连接/断开 since 1.6.3 -->

                <category android:name="com.example.ex_example" />

            </intent-filter>

        </receiver>

 

       

        <!-- Required  . Enable it you can get statistics data withchannel -->

        <meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>

        <meta-data android:name="JPUSH_APPKEY" android:value="4825c98077eb95d8b2397a3c" /><!--  </>值来自开发者平台取得的AppKey-->

 

4、完成了以上3步骤就可以在自己的项目中推送消息了