我正在尝试从解析用户类中获取电子邮件地址, 在这里,我正在尝试让其他用户在登录时收到电子邮件ID 用户,登录用户的电子邮件ID正在显示,但其他用户的电子邮件ID 没有显示始终为空
我也尝试使用主密钥,仍然无效,
下面是我的java代码。
String objectId;
protected TextView txtv;
protected TextView txtv1;
protected ImageView txtv2;
protected ImageView txtv3;
protected TextView individualOrganization;
Button emailPerson;
Button callPerson;
Button callPersonTelephone;
ParseObject personObject;
String personEmail;
String personNumber;
String personNumberTelephone;
ParseQuery query;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_individual);
txtv =(TextView)findViewById(R.id.txt123);
txtv1 =(TextView)findViewById(R.id.coporateSector);
txtv2 =(ImageView)findViewById(R.id.txt12345);
txtv3 =(ImageView)findViewById(R.id.txt123456);
individualOrganization =(TextView) findViewById(R.id.individualOrganization);
Intent i =getIntent();
objectId = i.getStringExtra("objectId");
ParseQuery<ParseUser> query = ParseUser.getQuery();
//query.put("useMasterKey", true);
query.setLimit(2000);
query.include("email");
query.getInBackground(objectId, new GetCallback<ParseUser>() {
@Override
public void done(final ParseUser object, com.parse.ParseException e) {
if (e == null) {
personObject = object;
String username = object.getString("firstname");
txtv.setText(username + " " + object.getString("lastname"));
String position = object.getString("position");
txtv1.setText(position);
String organizationName = object.getString("organizationName");
individualOrganization.setText(organizationName);
URL url = null;
try {
url = new URL("" + object.getString("image"));
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
Glide.with(getApplicationContext())
.load(String.valueOf(url))
.into(txtv2);
try {
url = new URL("" + object.getString("image"));
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
Glide.with(getApplicationContext())
.load(String.valueOf(url))
.into(txtv3);
// try{
// JSONObject jsonObject = parseObjectToJson(object);
// Log.d("Object", jsonObject.toString());
// Log.d("Email", "+" + object.get("email"));
// personNumber = jsonObject.getString("telephone");
// //personEmail = jsonObject.getString("email");
// personEmail= object.getEmail();
//
// }catch (JSONException je){
// }catch (ParseException pe){
// } catch (com.parse.ParseException e1) {
// e1.printStackTrace();
// }
} else {
}
callPerson = (Button) findViewById(R.id.individualMobile) ;
personNumber = object.getString("mobile");
callPerson.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"+personNumber));
startActivity(i);
}
});
if(personNumber==null || personNumber.equals("") || personNumber.equals(" ")){
callPerson.setClickable(false);
callPerson.setEnabled(false);
callPerson.setVisibility(View.GONE);
}
else{
callPerson.setEnabled(true);
callPerson.setClickable(true);
callPerson.setVisibility(View.VISIBLE);
}
callPersonTelephone = (Button) findViewById(R.id.individualTelephone);
personNumberTelephone = object.getString("telephone");
callPersonTelephone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+personNumberTelephone));
startActivity(i);
}
});
if(personNumberTelephone==null || personNumberTelephone.equals("") || personNumberTelephone.equals(" ") || personNumberTelephone.equals("6855")){
callPersonTelephone.setClickable(false);
callPersonTelephone.setEnabled(false);
callPersonTelephone.setVisibility(View.GONE);
}
else{
callPersonTelephone.setEnabled(true);
callPersonTelephone.setClickable(true);
callPersonTelephone.setVisibility(View.VISIBLE);
}
emailPerson = (Button)findViewById(R.id.individualEmail);
object.put("useMasterKey", true);
personEmail= object.getString("email");
emailPerson.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setData(Uri.parse("mailto:"));
i.setType("plain/text");
i.putExtra(Intent.EXTRA_EMAIL, new String[] {personEmail});
startActivity(i);
}
});
if(personEmail==null || personEmail.equals("") || personEmail.equals(" ")){
emailPerson.setClickable(false);
emailPerson.setEnabled(false);
emailPerson.setVisibility(View.GONE);
}
else{
emailPerson.setEnabled(true);
emailPerson.setClickable(true);
emailPerson.setVisibility(View.VISIBLE);
}
individualOrganization.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String organizationID = personObject.getString("organizationID");
if(organizationID == null || organizationID.equals("")){
Toast.makeText(SingleIndividual.this, "Sorry No Organization Available!", Toast.LENGTH_SHORT).show();
}else{
Intent i = new Intent(getApplicationContext(), SingleCorporate.class);
i.putExtra("objectId", organizationID);
i.putExtra("image", organizationID);
startActivity(i);
}
}
});
}
});
}
private JSONObject parseObjectToJson(ParseObject parseObject) throws ParseException, JSONException, com.parse.ParseException {
JSONObject jsonObject = new JSONObject();
parseObject.fetchIfNeeded();
Set<String> keys = parseObject.keySet();
for (String key : keys) {
Object objectValue = parseObject.get(key);
if (objectValue instanceof ParseObject) {
jsonObject.put(key, parseObjectToJson(parseObject.getParseObject(key)));
} else if (objectValue instanceof ParseRelation) {
} else {
jsonObject.put(key, objectValue.toString());
}
}
return jsonObject;
}
}
答案 0 :(得分:1)
Master Key只能用于您的服务器代码,而不能用于客户端代码。让您的用户公开阅读是一种选择,尽管是非常糟糕的。最好有一个云代码功能,您可以使用主密钥验证用户会话,确保他们能够访问此信息并从那里进行查询。