使用parse-server-example和parse-dashboard连接新的Android项目(本地) [英] Connecting a new Android project with parse-server-example and parse-dashboard (local)

查看:60
本文介绍了使用parse-server-example和parse-dashboard连接新的Android项目(本地)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个新的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运行正常).

I am trying to connect a new android project with the parse-server-example (locally) and showing it with the parse-dashboard. I have successfully linked parse-server-example with parse-dashboard...(by changing appId and masterKey in parse-server-example/index.js and in parse-dashboard/parse-dashboard-config.json). I have installed mongodb and everything (mongodb,parse-server-example and parse-dashboard is working perfectly).

但是现在当我尝试在android项目中初始化解析服务器时,它不会在本地解析中创建任何内容(类).(在parse.com上运行良好).谢谢.我的密码

But now when i am trying to initialize parse server in android project, it does not create anything(class) in parse locally.(working fine with parse.com). Thanks. MY code

清单文件

<?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>

Build.gradle文件

Build.gradle file

...

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

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

StarterApplication.java

StarterApplication.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);
  }
}

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

I have also tried putting the creation of object in main activtiy

MainActivity.java

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

  }

推荐答案

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

Why do you have localhost in your code? Localhost means that the request is running on local device, you can use it inside server but not on a client device. Try to put there some IP address of the server/your computer

.server("http://localhost:1337/parse/")

这篇关于使用parse-server-example和parse-dashboard连接新的Android项目(本地)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆