I am sagar, i am trying to implement the Parse Push-Notification in android using REST API (Service), and i am almost got success in implement the Push-Notification in Xamarin-Android using REST API. But i got stuck with one part in sending the Data into REST service. I trying to pass the ParseObject in service, but the in parse table there is a need of Object,(). I have tried to pass the ParseObject as below:
JsonConvert.SerializeObject(ParseUser.CurrentUser)
It convert ParseObject into array and array is not accepted in table and ,i got failed to save it in table. because there i a need of object.
I need solution or suggestion from developer guys. Yours help will be appreciated. I am trying the below code to achieve the result.
public static void RegisterPush(string regristrationId)
{
if (regristrationId != null) {
string appID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
string restID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
string masterID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
try {
var client = new RestClient ("https://api.parse.com");
var request = new RestRequest ("1/installations", RestSharp.Method.POST);
request.AddHeader ("Accept", "application/json");
request.AddHeader ("X-Parse-Application-Id", appID);
request.AddHeader ("X-Parse-REST-API-Key", restID);
request.Credentials = new NetworkCredential (appID, masterID);
request.Parameters.Clear ();
Console.Error.WriteLine ("ParseUser.CurrentUser-->"+ (ParseObject) ParseUser.CurrentUser);
//JsonConvert.SerializeObject(ParseUser.CurrentUser)
string strJSONContent = "{\"user\" :"+ JsonConvert.SerializeObject(ParseUser.CurrentUser)+",\"owner\":\"" + ParseUser.CurrentUser.ObjectId + "\",\"deviceType\":\"android\",\"GCMSenderId\":\"1234567890\",\"appName\":\"abcdefgh\",\"pushType\":\"gcm\",\"deviceToken\":\"" + regristrationId + "\"}";
Console.Error.WriteLine("json string-->"+ strJSONContent);
request.AddParameter ("application/json", strJSONContent, ParameterType.RequestBody);
client.ExecuteAsync (request, response => {
Console.Error.WriteLine ("response for android parse installation-->" + response.Content);
});
} catch (Exception ex) {
Console.WriteLine (ex.Message);
}
}
}`
Output:{"user" :[{"Key":"dealOffered","Value":4},{"Key":"dealRequested","Value":5},{"Key":"displayName","Value":"Cook"},{"Key":"email","Value":"lorenzo#gmail.com"},{"Key":"firstName","Value":"Lorenzo"},{"Key":"lastName","Value":"Cook"},{"Key":"mobileNumber","Value":9999999999.0},{"Key":"picture","Value":{"IsDirty":false,"Name":"tfss-afd25c29-6679-4843-842c-fe01f7fcf976-profile.jpg","MimeType":"image/jpeg","Url":"http://files.parsetfss.com/profile.jpg"}},{"Key":"provider","Value":"password"},{"Key":"userType","Value":"Merchant"},{"Key":"username","Value":"merchant#sailfish.com"},{"Key":"zipCode","Value":2342343}],"owner":"3cF1vHUXkW","deviceType":"android","GCMSenderId":"1234567890123","appName":"Sailfish","pushType":"gcm","deviceToken":"APA91bE3bsTIInQcoloOBE4kdLVVHVTRVtNyA1A788hYSC15wAVu8mUg-lwk7ZPk370rngrK7J6OoLmiM9HRr1CGPaBo6LCNrSUL7erBku4vepaFFkQzgqS6BcAemp"}
Error:{"code":111,"error":"invalid type for key user, expected *_User, but got array"}
maven
I found the solution in , parse xamarin docs, in one query , the way is simple, but i little bit hard to found out.
The issue is with the data passing in json format in REST, to pass any pointer using REST API, use as below.
The solution is as below:
`{
"user":{
"__type":"Pointer",
"className":"_User",
"objectId":"qYvzFzGAzc"
},
"owner":"qYvzFzGAzc",
"deviceType":"android",
"GCMSenderId":"123456789",
"appName":"NiceApp",
"pushType":"gcm",
"deviceToken":"APA91bFeM10jdrCS6fHqGGSkON17UjEJEfvJEmGpRM-d6hq3hQgDxKHbyrqAIxMnEGgbLEZf0E9AllHxiQQQCdEFiNMF1_A8q0n9tGpBE5NKhvS2ZGJ9PZ7585puWqz_1Z1EjSjOvgZ1LQo708DeL2KzA7EFJmdPAA"
}`
It looks like your column user is set up wrong. It should show as a Pointer<_User> not Pointer
If you load this class in your Data Browser, is the "user" key defined as a string, or a Pointer <_User>
This error seems to indicate that this is a string column, which is why the Parse.User object is not being accepted as a valid value. You might have tried setting a string on this key before, which in turn type-locked the "user" key as a string column.
Found it on the examples given on this page - https://www.parse.com/docs/rest
Have you check your REST API connection while passing ParseObject?
Because your error says:
Error:{"code":111,"error":"invalid type for key user, expected *_User, but got array"}
Here "code":111This error code comes when server refuse for connection
why if i run this source , error FAILED EXCEPTION Asynctask #2 Illegal character in url
this is source
Intent in = getIntent();
get_nama = in.getStringExtra(tag_nama);
get_subkategoris = in.getStringExtra(tag_subkategoris);
"http://tribinacita.esy.es/tribinacita/index.php/sikomando/tampil_lokasi/?";
url += "nama_lok="+get_nama+"&subkategoris="+get_subkategoris+"&is_android=1";
"http://tribinacita.esy.es/tribinacita/index.php/sikomando/tampil_lokasi/?";
This line of code is just a string literal that isn't assigned to a variable. If this is identical to the code you are actually running, then you need to add an assignment:
url = "http://tribinacita.esy.es/tribinacita/index.php/sikomando/tampil_lokasi/?";
<media:group>
<media:content type="video/mp4"
url="http://cdn2.junctiontv.net/dmv/roku/ChiroDiniTumiJeAmar2997fps800kbpsForIPTV.mp4"
bitrate="800"
duration="8100"/>
</media:group>
<media:thumbnail
url="http://cdn2.junctiontv.net/dmv/images/ChiroDiniTumiJeAmar158x204.png"/>
I am trying to parse this xml using SAX Parser. But am getting error due to : in the tags. However if I replace remove : ie, change to its working fine. But problem is ,if I do this, am getting error in url as : is removed after http.
any solution?????????
Instead of using SAXparder, use
android.util.Xml.parse(InputStream,Xml.Encoding.ISO_8859_1, DefaultHandler);
to solve this problem...
This is an appropriate code. Adding this code to any SAX Parser code, xml containing http:// and https:// both can be parsed .
String text10=text9.replaceAll(":", ""); //text9 is any valid url with http:// or https:// or both
String text11="",text12="",text13="",text14="";
if(text10.contains("http//"))
{
text14=text10.replaceAll("http//", "http://");
}
if(text10.contains("https//"))
{
text14=text10.replaceAll("https//", "https://");
}
if(text10.contains("https//") && (text10.contains("http//")))
{
if(text10.contains("http//"))
{
text13=text10.replaceAll("http//", "http://");
}
if(text13.contains("https//"))
{
text14=text13.replaceAll("https//", "https://");
}
}
System.out.println("This is demo text " + text14);
Finally managed to do it.....in a round away process. It works fine if code contains only http://
String text2=text1.replaceAll(":", "");
String text3=text2.replaceAll("http", "http:");
Adding these two lines to my code,makes everything go fine.
When logging my Tags always look like this:
com.myapp.SomeActivity
For each log statement I prepend the first part "com.myapp." to the Tag of the class which is making the log call. For instance:
MyActivity extends Activity{
private static final String TAG = "MyActivity";
public void someMethod(){
LogWrapper.e(TAG, "Something is wrong here.");
}
}
My class LogWrapper basically does the following
public class LogWrapper {
private static final String applicationTAG = "com.myapp.";
public static void e(String classTag, String message){
Log.e(applicationTAG + classTag, message);
}
}
So all I do is prepend a static Tag to the class's tag. The reason is, that I want to filter the logcat output by the Log statements my application writes and to avoid cluttering my logfile with logs from the system or other applications.
Hence I came up with obtaining the Logs like this:
String command = "logcat -d -v time com.myapp.*:I *:S"
Process process = Runtime.getRuntime().exec(command);
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
StringBuilder log = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
log.append(line);
log.append(StringUtils.NEW_LINE);
}
However, I end up with an empty logfile. Which makes me thing the regex expression "com.myapp.:I" does not work. I also tried omitting the asterix () but that works neither. However if I use "*:I" that works.
Which makes me wonder, whether it is only possible to filter by a complete tag name? Is there a way I can get hold of a log that's filtered by "com.myapp." ?
I guess plan B would be that in the while loop I could check if the line contains my tag and append it only if that's the case, but I'd really like to avoid that...
Ok to solve the issue I gave up the more elegant (and still unknown) solution for the Plan B I hinted at in my first post. I use the following regex to filter each line of the logfile that I obtained using the command logcat -d -v time *:I (executed using Runtime.getRuntime().exec(command)):
.*([DIWE]{1}/com.myapp.).*
The above regex matches log statements like this:
I/com.myapp.MyClass Crashed and did not recover - too bad.
The [DEWI] means that, the log level must be either D(ebug), E(rror), W(arning) or I(nfo) in order for the regex to match. If you want to extract V(erbose) logging as well, just add a "V" .
There are some pdf files in my d drive.In my android application I have to return the list of files from a servlet to my activity class,but through my codes it is returning the name of all files as a string.But i need each name separetly.How to do that,
You a using HTTP to pass data from your servlet to your Android application. HTTP doesn't care about the content of the response, so there is no standard way of defining the structure of the data you are passing. You are pretty much free to do as you please.
One option therefore would be to put your filenames into a comma-separated list in the servlet. In your Android application you chop the String apart into an array of Strings each representing one file name:
String[] filenames;
filenames = responseString.split(",");
That's the easy way. You could also create XML from your filenames in your servlet, and parse the XML in your Android application. That would look nicer, but it is more work.
Use JSONObject
JSONObject jsEmployeeObj = new JSONObject();
JSONArray empArray = new JSONArray();
while (condition) {
JSONObject jsObject = new JSONObject();
jsObject.accumulate("name", res.getString("name"));
empArray.add(jsObject);
}
if ((empArray != null) && (empArray.size() > 0)) {
jsEmployeeObj.accumulate("employeeList", empArray);
} else {
jsEmployeeObj.accumulate("employeeList", "empty");
}
String output = jsEmployeeObj.toString();
return the string ... u can parse JSON in android