通过本地解析服务器和解析仪表板推送通知

时间:2016-07-12 12:40:27

标签: android parse-server

您好我能够在我的本地系统中运行解析服务器和解析仪表板。我正在尝试将我的Android应用程序连接到也在同一系统中的解析服务器。我没有将解析服务器托管到Heroku或任何其他主机网站。我可以使用此命令从comandline获取/发送消息

curl -X POST \
  -H "X-Parse-Application-Id:<App_ID>" \
  -H "Content-Type: application/json" \
  -d '{"Name":"<Name>","Score":<Score>}' \
 http://localhost:1337/parse/classes/Player

但无法从我的Android应用程序连接解析服务器。

mongodb,parse-server-example和parse-dashboard正常工作。我的Android代码: 清单文件

  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="com.parse.pushnotification" >

            <uses-permission android:name="android.permission.INTERNET" />
            <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
         <uses-permission android:name="android.permission.GET_ACCOUNTS" />
            <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
        <permission
                android:name="<my_Package>.C2D_MESSAGE"
                android:protectionLevel="signature" />        
       <uses-permission android:name="<my_Package>.permission.C2D_MESSAGE" />       

            <application
                android:name=".PushParseServerTest"
                android:allowBackup="true"
                android:label="@string/app_name"
                android:theme="@style/AppTheme" >

                <activity
                    android:name=".MainActivity"
                    android:label="@string/app_name" >
                    <intent-filter>
                        <action android:name="android.intent.action.MAIN" />

                        <category android:name="android.intent.category.LAUNCHER" />
                    </intent-filter>
                </activity>

 <meta-data
            android:name="com.parse.push.gcm_sender_id"
            android:value="id:<gcm_project_id>" />

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

                <receiver
                    android:name="com.parse.GcmBroadcastReceiver"
                    android:permission="com.google.android.c2dm.permission.SEND" >
                    <intent-filter>
                        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />                 

                        <category android:name="<my_package_name>" />
                    </intent-filter>
                </receiver>
                <receiver
                    android:name="<my_package>.ParsePushnotificationReceiver"
                    android:exported="false" >
                    <intent-filter>
                        <action android:name="android.intent.action.BOOT_COMPLETED" />
                        <action android:name="android.intent.action.USER_PRESENT" />
                        <action android:name="com.parse.push.intent.RECEIVE" />
                        <action android:name="com.parse.push.intent.DELETE" />
                        <action android:name="com.parse.push.intent.OPEN" />

                        <category android:name="<my_package_name>" />
                    </intent-filter>
                </receiver>
            </application>    
        </manifest>

Build.gradle文件

{

    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.parse.bolts:bolts-tasks:1.3.0'
    compile 'com.parse:parse-android:1.13.0'
}

PushParseServerTest.java

public class StarterApplication extends Application {
  @Override
  public void onCreate() {
    super.onCreate();
    // Enable Local Datastore.
    Parse.enableLocalDatastore(this);

    // Add your initialization code here
   //Parse.initialize(this);

      Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
              .applicationId("@string/parse_app_id")
              .clientKey("@string/parse_client_key")
              .server("http://<my_system_ip>:1337/parse/")   // '/' important after 'parse'
              .build());    
  }
}

ParsePushnotificationReceiver.java

public class ParsePushnotificationReceiver extends BroadcastReceiver {
    private static final String TAG = "ParsePushnotificationReceiver";
   // public static final String intentAction = "com.parse.push.intent.RECEIVE";

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent == null) {
            Log.d(TAG, "Receiver intent null");
        } else {
            // Parse push message and handle accordingly
            Log.d(TAG, intent.getExtras().toString());
        }
    }
}

1 个答案:

答案 0 :(得分:0)

推送通知或将对象保存到解析服务器是一个问题吗?

您是否在解析服务器上正确配置推送通知并正确注册您的Android设备?