1

我一直在尝试在 android 中接收推送通知并且遇到了一些问题。你可以帮帮我吗?

1) 基本实现在 Android 4.0+ 中运行良好,但在 Android 2.3 中不行,为什么?

2)我已经按照教程解释实现了自定义接收器,还按照教程所示插入了行AndroidManifest(维护<service android:name="com.parse.PushService" />),并且我删除了定义 的行DefaultPushCallback,对吗?当我从仪表板发送推送时,应用程序会收到它并仅显示默认消息,而不是传入自定义接收器,以解析我发送的额外信息。

4

1 回答 1

0
use the given Manifest 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="your package name"
    android:versionCode="3"
    android:versionName="1.1" >

    <uses-sdk
        android:minSdkVersion="4"
        android:targetSdkVersion="13" />

    <uses-permission android:name="android.permission.INTERNET" />
    <!-- GCM requires a Google account. -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <!-- Keeps the processor from sleeping when a message is received. -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.QUICKBOOT_POWERON" />
    <uses-permission android:name="android.permission.VIBRATE" />

    <application
        android:name="com.test.param.mainActivity"
        android:allowBackup="true"
        android:icon="@drawable/menu"
        android:label="@string/app_name" 
          android:theme="@style/AppTheme"
        >
        <activity
            android:name="Splash"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.test.param..Profile"
            android:screenOrientation="portrait" 
              android:windowSoftInputMode="adjustPan" 

            >
        </activity>
        <activity
            android:name="com.test.param.AnnounceActivity"
            android:screenOrientation="portrait" 
             android:label="@string/app_name"


            >
        </activity>
        <activity
            android:name="com.test.param.MenuActivity"
            android:screenOrientation="portrait" >
        </activity>




             >
        </activity>
        <activity
            android:name="com.test.param.ShowPopUp"
            android:screenOrientation="portrait" 
             android:label="@string/app_name"
            android:theme="@android:style/Theme.Holo.Light.Dialog"

            >
        </activity>

        <service android:name="com.parse.PushService" />

        <receiver android:name="com.parse.ParseBroadcastReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.RECEIVE_BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
                <action android:name="android.intent.action.USER_PRESENT" />
                 <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>
        <receiver android:name="com.test.param.MyCustomReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.USER_PRESENT" />
               <action android:name="android.intent.action.RECEIVE_BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
                <action android:name="com.test.param.UPDATE_STATUS" />
                 <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>
    </application>

</manifest>


----------
use this to send the push notification



 JSONObject obj;
             try {

             obj = new JSONObject();
             obj.put("alert", "hello");
             obj.put("action", "*Your main package name*.UPDATE_STATUS");

             obj.put("title", "param");
             obj.put("msg", "Today meeting is at 9 AM ");
             obj.put("time", CurrentDate.getCurrentDate());

             ParsePush push = new ParsePush();
             @SuppressWarnings("rawtypes")
             ParseQuery query = ParseInstallation.getQuery();

             // Notification for Android users

             query.whereEqualTo("deviceType", "android");

             push.setQuery(query);
             push.setData(obj);
             push.sendInBackground();
             } catch (JSONException e) {

             e.printStackTrace();
             }


use it as a Custom receiver class.....

public class MyCustomReceiver extends BroadcastReceiver {
    String title, time,msg;

    @Override
    public void onReceive(Context context, Intent intent) {

        Bundle extras = intent.getExtras();

        String message = extras != null ? extras.getString("com.parse.Data")
                : "";

        Log.e("message ", " " + message);




         JSONObject jObject;
            try {
                if (message != null && !message.equals("")) {
                  jObject = new JSONObject(message); 

                  time = jObject.getString("time");
                  msg = jObject.getString("title");
                  title = jObject.getString("msg");





                }

              }         


        catch (JSONException e) {
            e.printStackTrace();
        }







    }


}


----------
and dont remove the DefaultPushCallback
i have successfully implemented and it's working very fine
于 2014-05-05T05:58:50.113 回答