溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

給自己的項(xiàng)目做極光推送的步驟

發(fā)布時(shí)間:2020-06-14 23:12:19 來源:網(wǎng)絡(luò) 閱讀:4670 作者:buildzhang 欄目:移動(dòng)開發(fā)

極光推送(對(duì)客戶端的app如天貓進(jìn)行消息推送)

第一種:利用網(wǎng)頁進(jìn)行推送(下面按這種來介紹)

第二種:利用javase代碼進(jìn)行消息推送

使用步驟

1\登陸極光網(wǎng)址

2\注冊后并登陸

3、點(diǎn)擊用戶名下的控制臺(tái)

給自己的項(xiàng)目做極光推送的步驟

4、創(chuàng)建應(yīng)用進(jìn)入以下界面(只要填寫應(yīng)用名稱,應(yīng)用圖標(biāo),應(yīng)用包名即可,再點(diǎn)擊下載最下方的創(chuàng)建我的應(yīng)用即消息推送的sdkDemos可以進(jìn)行消息推送的例子)

給自己的項(xiàng)目做極光推送的步驟

 

5、將下載下來的消息推送的sdkDemos導(dǎo)到excipse

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

給自己的項(xiàng)目做極光推送的步驟

 

第二個(gè)參數(shù)是手機(jī)的設(shè)備別名(在放手機(jī)電池的槽里可以看到IMEI的號(hào)就是)

7、在官方模擬器下運(yùn)行Demos,在日志上有日志

 

如果成功運(yùn)行了Demos后,在極光自己的賬號(hào)登陸后創(chuàng)建的應(yīng)用里,點(diǎn)擊發(fā)送消息進(jìn)入下面的界面:將手機(jī)的設(shè)備別名寫的框里和寫下發(fā)送的信息后,點(diǎn)擊立即發(fā)送消息即可在自己的手機(jī)里看到推送的消息

給自己的項(xiàng)目做極光推送的步驟

 

 

 

怎么在自己的項(xiàng)目里做消息推送:

1、 將之前下載下來的消息推送Demos中的MyReicever.java,ExampleUtilTestActivity三個(gè)文件copy到自己的項(xiàng)目里

2、 在自己項(xiàng)目中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  一些系統(tǒng)要求的權(quán)限,如訪問網(wǎng)絡(luò)等-->

    <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 測試狀態(tài)通知欄,需要打開的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 回調(diào)函數(shù)的intent-->

                <action android:name="cn.jpush.android.intent.CONNECTION"/><!-- 接收網(wǎng)絡(luò)變化連接/斷開 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" /><!--  </>值來自開發(fā)者平臺(tái)取得的AppKey-->

 

4、完成了以上3步驟就可以在自己的項(xiàng)目中推送消息了

       

       

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI