簡體   English   中英

如何使用parse.com發送和檢索數據

[英]How can I send and retrieve data with parse.com

我編寫了該代碼以將數據發送到parse.com,然后也接收它,但是直到現在我都無法發送它,為什么?! 我不知道主要原因,我將Internet和網絡權限放在AndroidManifest.xml中,將解析類也放在了AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mkadaimtwo"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="21" />

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

<application
    android:name="com.example.mkadaimtwo.ParseCode"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <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>

並將parse類也放入AndroidManifest.xml中的應用程序中,該類的兩個代碼和main Activity

ParseCode類的活動:

package com.example.mkadaimtwo;

import com.parse.Parse;

import android.app.Application;

public class ParseCode extends Application {
public void onCreate() {
      Parse.initialize(this, "GIuhlGILKRd8itvCF79femTyReHM6XjVkrfLKm3X",   "Fjg4tBrMgl0mY47K4kCL7hVmXhu8FmkE2on9PlXK");
    }
  }

MainActivity代碼:

package com.example.mkadaimtwo;

   import android.app.AlertDialog;
   import android.app.ProgressDialog;
   import android.net.ParseException;
   import android.os.Bundle;
   import android.support.v7.app.ActionBarActivity;
   import android.view.View;
    import android.widget.EditText;

   import com.parse.GetCallback;
   import com.parse.ParseObject;
   import com.parse.ParseQuery;

   public class MainActivity extends ActionBarActivity {

EditText etCompanyName,etAddress,etNumberOfEmployees,etContactNumber;
ProgressDialog pd,pd2;

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

    etCompanyName = (EditText) findViewById(R.id.etCompanyName);
    etAddress = (EditText) findViewById(R.id.etAddress);
    etNumberOfEmployees = (EditText) findViewById(R.id.etNumberOfEmployees);
    etContactNumber = (EditText) findViewById(R.id.etContactNumber);

    pd = new ProgressDialog(this);
    pd.setTitle("wait");
    pd.setMessage("by7aml elmafrod");
    pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    pd.setCancelable(true);


    pd2 = new ProgressDialog(this);
    pd2.setTitle("wait");
    pd2.setMessage("by7aml elmafrod");
    pd2.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    pd2.setCancelable(true);

    //here we will Load the old company data from Parse.com

    ParseQuery<ParseObject> query = ParseQuery.getQuery("TestBosyApp");
    query.getInBackground("ijy1qi78g8", new GetCallback<ParseObject>() {
        public void done(ParseObject testBosyApp, ParseException e) {
            if (e == null) {

                String companyName = testBosyApp.getString("company_name");
                String address = testBosyApp.getString("address");
                String numberOfEmployees = testBosyApp.getString("number_of_employees");
                String contactNumber = testBosyApp.getString("contact_number");

                etCompanyName.setText(companyName);
                etAddress.setText(address);
                etNumberOfEmployees.setText(numberOfEmployees);
                etContactNumber.setText(contactNumber);

                pd.dismiss();


            } else {
                AlertDialog.Builder mDialoge = new AlertDialog.Builder(MainActivity.this); 
                mDialoge.setTitle("Erorr");
                mDialoge.setMessage("Check el net plz :)");
                mDialoge.setPositiveButton("ok", null);
                mDialoge.show();
            }
        }

        @Override
        public void done(ParseObject arg0, com.parse.ParseException arg1) {
            // TODO Auto-generated method stub

        }

    });

}

  public void update (View V){
    pd2.show();
    //update data in Parse

    ParseQuery<ParseObject> myQuery = ParseQuery.getQuery("TestBosyApp");

    // Retrieve the object by id
    myQuery.getInBackground("U6Gwn2tiD8", new GetCallback<ParseObject>() {
        public void done(ParseObject testBosyApp, ParseException e) {
            if (e == null) {
                //Initials our variables
                String companyName = etCompanyName.getText().toString().trim();
                String address = etAddress.getText().toString().trim();
                String numberOfEmployees = etNumberOfEmployees.getText().toString().trim();
                String contactNumber = etContactNumber.getText().toString().trim();

                //update it with new data

                testBosyApp.put("company_name", companyName);
                testBosyApp.put("address", address);
                testBosyApp.put("number_of_employees", numberOfEmployees);
                testBosyApp.put("contact_number", contactNumber);
                testBosyApp.saveInBackground();

                pd2.dismiss();

                AlertDialog.Builder mDialoge = new AlertDialog.Builder(MainActivity.this); 
                mDialoge.setTitle("2shta");
                mDialoge.setMessage("Keda eldata ra7t t2riban");
                mDialoge.setPositiveButton("cool", null);
                mDialoge.show();
            }else{
                pd2.dismiss();
                AlertDialog.Builder mDialoge = new   AlertDialog.Builder(MainActivity.this); 
                mDialoge.setTitle("Erorr");
                mDialoge.setMessage("Check el net plz :)");
                mDialoge.setPositiveButton("ok", null);
                mDialoge.show();
            }
        }

        @Override
        public void done(ParseObject arg0, com.parse.ParseException arg1) {
            // TODO Auto-generated method stub

            }
    });

}

 }

所以問題是,進度條正在無休止地加載,如果我提供進度條取消功能,然后將數據放入字段中,則不會發生任何事情。 另外,如果有人有與parse.com一起使用android的教程,請向我提供。

杜德..先生? goto parse.com,有一些教程..您需要啟用一些 我不記得的功能: 轉到設置->應用程序權限->允許創建客戶端類。 將其設置為ON>之前,您可以從設備發送推送並接收它。.據我所知,您的清單不完整。

<application
android:name="com.example.mkadaimtwo.ParseCode"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<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>

//edit started here
<service android:name="com.parse.PushService" />

    <receiver android:name="com.parse.ParseBroadcastReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
        </intent-filter>
    </receiver>
</application>

因此復制並粘貼此清單

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM