我试图将我的Android程序连接到解析服务器仪表板。 我已经创建了仪表板成功,我已经尝试过到处搜索,但它就像那里告诉我我做过的一样, 这是我的代码 谢谢你......。
****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);
}
}
答案 0 :(得分:0)
将此添加到您的清单文件 -
<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 :(得分:0)
您处于正确的步骤但是必须在写入任何解析逻辑之前设置对Parse的读写权限。它似乎如下
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文件中应用您的Parse逻辑