0
我試圖做一個程序,將GCM註冊ID發送學生註冊數據服務器。當我嘗試註冊用戶的父親名字和母親名字沒有姓氏 例子: 阿賈伊Android的Web服務無法正常工作
和實施例
阿賈伊[空白]索德
在第一實施例中的名稱工作正常無需空白和姓..但第二示例名稱以空格一點兒也不作品..
即使我在名字和姓氏之間使用Underscore _,它也可以很好地工作。 我不知道怎麼回事錯
RegistrationApp.java
名字和喜歡_姓姓氏之間,package com.example.akshay.parentapp;
/**
* Created by Akshay on 8/19/2015.
*/
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
public class RegisterApp extends AsyncTask<Void, Void, String> {
private static final String TAG = "GCMRelated";
Context ctx;
GoogleCloudMessaging gcm;
String SENDER_ID = "237184799993";
String regid = null;
private int appVersion;
String SNAME , CLASS , FNAME , MNAME , TIMINGS ;
int ROLLNO , ROUTE;
Long MNO , FNO;
Double LAT , LONG;
public RegisterApp(Context ctx, int rollno , String sname, GoogleCloudMessaging gcm, String classs , String fname,Long fno, String mname,Long mno,int route, String timings,Double lat , Double longg, int appVersion) {
this.ctx = ctx;
this.ROLLNO = rollno;
this.SNAME = sname;
this.CLASS = classs;
this.FNAME = fname;
this.FNO = fno;
this.MNAME = mname;
this.MNO = mno;
this.ROUTE = route;
this.TIMINGS = timings;
this.LAT = lat;
this.LONG = longg;
this.gcm = gcm;
this.appVersion = appVersion;
Log.e("In Constructor", "-======================");
}
@Override
protected void onPreExecute() {
super.onPreExecute();
Log.e("In PreExecute", "-======================");
}
@Override
protected String doInBackground(Void... arg0) {
String msg = "";
try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(ctx);
}
regid = gcm.register(SENDER_ID);
msg = "Device registered, registration ID=" + regid;
// You should send the registration ID to your server over HTTP,
// so it can use GCM/HTTP or CCS to send messages to your app.
// The request to your server should be authenticated if your app
// is using accounts.
try {
sendRegistrationIdToBackend();
} catch (URISyntaxException e) {
e.printStackTrace();
}
// For this demo: we don't need to send it because the device
// will send upstream messages to a server that echo back the
// message using the 'from' address in the message.
// Persist the regID - no need to register again.
storeRegistrationId(ctx, regid);
} catch (IOException ex) {
msg = "Error :" + ex.getMessage();
// If there is an error, don't just keep trying to register.
// Require the user to click a button again, or perform
// exponential back-off.
}
Log.e("MESSAGE " , msg);
Log.e("ROLLNO", String.valueOf(ROLLNO));
return msg;
}
private void storeRegistrationId(Context ctx, String regid) {
final SharedPreferences prefs = ctx.getSharedPreferences(MainActivity.class.getSimpleName(),
Context.MODE_PRIVATE);
Log.i(TAG, "Saving regId on app version " + appVersion);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("registration_id", regid);
editor.putInt("appVersion", appVersion);
editor.commit();
Log.e("In Shared Prefs" , "-======================");
}
private void sendRegistrationIdToBackend() throws URISyntaxException {
Log.e("INSEND REG TO BACK" , "HEY");
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI("http://akshay.site90.net/register.php?rollno="+ROLLNO+"&sname="+SNAME+"®id="+regid+"&class="+CLASS+"&fname="+FNAME+"&fno="+FNO+"&mname="+MNAME+"&mno="+MNO+"&route="+ROUTE+"&timings="+TIMINGS +"&latitude="+LAT+"&longitude="+LONG));
Log.e("RESULT", "http://akshay.site90.net/register.php?rollno=" + ROLLNO + "&sname=" + SNAME + "®id=" + regid + "&class=" + CLASS + "&fname=" + FNAME + "&fno=" + FNO + "&mname=" + MNAME + "&mno=" + MNO + "&route=" + ROUTE + "&timings=" + TIMINGS + "&latitude=" + LAT + "&longitude=" + LONG);
try {
httpclient.execute(request);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("Something Went Wrong " , "ClientPro");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("Something Went Wrong ", "IOEX");
}
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
Toast.makeText(ctx, "Registration Completed. Now you can see the notifications", Toast.LENGTH_SHORT).show();
Log.v(TAG, result);
Toast.makeText(ctx , "In PostEx" , Toast.LENGTH_SHORT).show();
}
}
logcat的文件_行之有效:
18:31:51.632 29049-29049/? E/Zygote﹕ MountEmulatedStorage()
09-04 18:31:51.632 29049-29049/? E/Zygote﹕ v2
09-04 18:31:51.642 29049-29049/? E/SELinux﹕ [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
09-04 18:31:52.422 29049-29049/com.example.akshay.parentapp E/=====ROUTE====﹕ 401
09-04 18:32:35.082 29049-29049/com.example.akshay.parentapp E/ROLLNO==========﹕ 1
09-04 18:32:35.092 29049-29049/com.example.akshay.parentapp E/SNAME==========﹕ Akshay
09-04 18:32:35.092 29049-29049/com.example.akshay.parentapp E/REGID==========﹕ [ 09-04 18:32:35.092 29049:29049 E/CLASS========== ]
Mca
09-04 18:32:35.092 29049-29049/com.example.akshay.parentapp E/FATHERNAME==========﹕ Ajay_Sood
09-04 18:32:35.092 29049-29049/com.example.akshay.parentapp E/FATHERNO==========﹕
09-04 18:32:35.092 29049-29049/com.example.akshay.parentapp E/MOTHERNAME==========﹕ Manju_Sood
09-04 18:32:35.092 29049-29049/com.example.akshay.parentapp E/MOTHERNO==========﹕
09-04 18:32:35.092 29049-29049/com.example.akshay.parentapp E/ROUTE==========﹕ 401
09-04 18:32:35.092 29049-29049/com.example.akshay.parentapp E/Timings==========﹕ 568
09-04 18:32:35.092 29049-29049/com.example.akshay.parentapp E/LAT==========﹕ 78.555454
09-04 18:32:35.092 29049-29049/com.example.akshay.parentapp E/LONG==========﹕ 78.545545
09-04 18:32:35.092 29049-29049/com.example.akshay.parentapp E/In Constructor﹕ -======================
09-04 18:32:35.092 29049-29049/com.example.akshay.parentapp E/In PreExecute﹕ -======================
09-04 18:32:35.332 29049-29128/com.example.akshay.parentapp E/INSEND REG TO BACK﹕ HEY
09-04 18:32:35.332 29049-29128/com.example.akshay.parentapp E/RESULT﹕ http://akshay.site90.net/register.php?rollno=1&sname=Akshay®id=APA91bHeO4ugp3ENRU-XJb65Xjk99gB6s7r-7IF8680hgrn5RJugtG2xU5_IgSvk64wjYPvpczKIqeXlyrry7y2xT8Kj8CGF5kQnZ-68YeR4WGGEhc6d-dAZ6jsRUaCZ1G3_JMYfIMYJ&class=Mca&fname=Ajay_Sood&fno=&mname=Manju_Sood&mno=&route=401&timings=568&latitude=78.555454&longitude=78.545545
09-04 18:32:36.422 29049-29128/com.example.akshay.parentapp E/In Shared Prefs﹕ -======================
09-04 18:32:36.422 29049-29128/com.example.akshay.parentapp E/MESSAGE﹕ Device registered, registration ID=APA91bHeO4ugp3ENRU-XJb65Xjk99gB6s7r-7IF8680hgrn5RJugtG2xU5_IgSvk64wjYPvpczKIqeXlyrry7y2xT8Kj8CGF5kQnZ-68YeR4WGGEhc6d-dAZ6jsRUaCZ1G3_JMYfIMYJ
09-04 18:32:36.432 29049-29128/com.example.akshay.parentapp E/ROLLNO﹕ 1
的HttpClient現在已經過時,請對你的jar文件 –
我知道一起來看看它的棄用。如果你知道答案,那麼請告訴我...它沒有空格做工精細 –
你可以爲用戶編碼技術您的網址在發送之前 –