无法在本地将我的安卓项目与解析仪表板连接

  • 本文关键字:项目 连接 仪表板 android
  • 更新时间 :
  • 英文 :


我试图将我的安卓程序连接到解析服务器仪表板。我已经成功创建了仪表板,我尝试到处搜索,但它就像在那里告诉我 d 我做过的同样的事情,这是我的代码谢谢。。`

****StarterApplication.java****
    package com.parse.starter;
    import android.app.Application;
    import android.util.Log;
    import com.parse.Parse;
    import com.parse.ParseACL;
    import com.parse.ParseException;
    import com.parse.ParseObject;
    import com.parse.ParseUser;
    import com.parse.SaveCallback;

    public class StarterApplication extends Application {
      @Override
      public void onCreate() {
        super.onCreate();
        // Enable Local Datastore.
        Parse.enableLocalDatastore(this);
        // Add your initialization code here
        Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
                .applicationId("instagram99n990nm900b")  //application id
                .clientKey("instagjusohjwjikkjjoeoeh")  //master key
                .server("https://instagram914.herokuapp.com/parse/")  //serverURl
        .build()
        );
          ParseObject gameScore = new ParseObject("GameScore");
          gameScore.put("score", 1337);
          gameScore.put("playerName", "Sean Plott");
          gameScore.put("cheatMode", false);
          gameScore.saveInBackground();
          gameScore.saveInBackground(new SaveCallback() {
              public void done(ParseException e) {
           if (e == null) {
                      Log.i("Parse", "Save Succeeded");
                  } else {
                      Log.i("Parse", "Save Failed");
                  }
              }
          });

          ParseUser.enableAutomaticUser();
        ParseACL defaultACL = new ParseACL();
        // Optionally enable public read access.
        // defaultACL.setPublicReadAccess(true);
        ParseACL.setDefaultACL(defaultACL, true);
      }
    }
    **MainActivity.java**
    import android.os.Bundle;
    import android.support.v7.app.ActionBarActivity;
    import android.view.Menu;
    import android.view.MenuItem;
    import com.parse.ParseAnalytics;

    public class MainActivity extends ActionBarActivity {
      @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);
      }
    }

将其添加到您的清单文件 -

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

您正在正确的步骤中,但在编写任何解析逻辑之前,您必须设置对解析的读写权限。好像在下面

1)//启用本地数据存储。

    Parse.enableLocalDatastore(this);

2)//在此处添加您的初始化代码

    Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
            .applicationId("instagram99n990nm900b")  //application id
            .clientKey("instagjusohjwjikkjjoeoeh")  // client key is optional.....                .server("https://instagram914.herokuapp.com/parse/")  //serverURl
            .build());

3)//将读写权限设置为 Parse

 ParseACL p_ACL = new ParseACL();
 p_ACL.setPublicReadAccess(true);         
 p_ACL.setPublicWriteAccess(true);
 ParseACL.setDefaultACL(p_ACL,true);

现在在 MainActivity.java 文件中应用您的解析逻辑

最新更新