【问题标题】:Push Notification through local parse-server and parse dash board通过本地解析服务器和解析仪表板推送通知
【发布时间】:2016-07-12 12:40:26
【问题描述】:

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

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());
        }
    }
}

【问题讨论】:

    标签: android parse-server


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您分享您的答案。是的,我确实正确配置了解析服务器。正如我所提到的,我可以使用上述命令从命令行获取/发送消息。但我认为 android 设备的注册没有发生使用这个 api Parse.initialize()。请告诉我如何查看安卓应用的流量。
    • 我根本不是 Android 专家,我可能不是最适合在这里为您提供帮助的人。据我所见,许多人设法让它发挥作用。我建议浏览github.com/ParsePlatform/parse-server/issues 上的问题,可能会有修复提示;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多