2

我正在尝试将一个新的 android 项目与 parse-server-example (本地)连接并使用 parse-dashboard 显示它。我已经成功地将 parse-server-example 与 parse-dashboard 链接...(通过更改 parse-server-example/index.js 和 parse-dashboard/parse-dashboard-config.json 中的 appId 和 masterKey)。我已经安装了 mongodb 和所有东西(mongodb、parse-server-example 和 parse-dashboard 运行良好)。

但是现在当我尝试在 android 项目中初始化解析服务器时,它不会在本地解析中创建任何东西(类)。(与 parse.com 一起工作)。谢谢。我的代码

清单文件

<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (c) 2015-present, Parse, LLC.
  ~ All rights reserved.
  ~
  ~ This source code is licensed under the BSD-style license found in the
  ~ LICENSE file in the root directory of this source tree. An additional grant
  ~ of patent rights can be found in the PATENTS file in the same directory.
  -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.parse.starter" >

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

    <application
        android:name=".StarterApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.parse.APPLICATION_ID"
            android:value="@string/parse_app_id" />
        <meta-data
            android:name="com.parse.CLIENT_KEY"
            android:value="@string/parse_client_key" />

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

</manifest>

构建.gradle 文件

...

dependencies {

    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'
}

MainActivity.java

package com.parse.starter;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;

import com.parse.Parse;
import com.parse.ParseAnalytics;
import com.parse.ParseObject;


public class MainActivity extends AppCompatActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ParseAnalytics.trackAppOpenedInBackground(getIntent());


  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
      return true;
    }

    return super.onOptionsItemSelected(item);
  }
}

启动应用程序.java

package com.parse.starter;

import android.app.Application;

import com.parse.Parse;
import com.parse.ParseACL;
import com.parse.ParseObject;
import com.parse.ParseUser;


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://localhost:1337/parse/")   // '/' important after 'parse'
              .build());

      ParseObject testObject = new ParseObject("TestObject");
      testObject.put("foo", "bar");
      testObject.saveInBackground();


      ParseUser.enableAutomaticUser();
    ParseACL defaultACL = new ParseACL();
    // Optionally enable public read access.
    // defaultACL.setPublicReadAccess(true);
    ParseACL.setDefaultACL(defaultACL, true);
  }
}

我也尝试过将对象的创建放在主要活动中

MainActivity.java

public class MainActivity extends AppCompatActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ParseAnalytics.trackAppOpenedInBackground(getIntent());

    ParseObject testObject = new ParseObject("TestObject");
    testObject.put("foo", "bar");
    testObject.saveInBackground();

  }
4

2 回答 2

1

为什么你的代码中有 localhost?本地主机表示请求在本地设备上运行,您可以在服务器内部使用它,但不能在客户端设备上使用。尝试放一些服务器/您的计算机的IP地址

.server("http://localhost:1337/parse/")
于 2016-03-14T10:10:05.100 回答
0

在您的初始化方法中,使用 .server(API_ADDRESS) ,api 地址由解析服务提供者提供。例如 back4app 称之为 API 地址

于 2017-08-22T20:06:39.217 回答