The data on server I want to retrieve, data in JSON format but problem is that I want to retrieve only data having specific CHEF_NAME from JSON array.I am using Android Studio.
JSON Array
[{"status":"Success","recpie":[{"id":"162","image":"1580130013.png","cat_id":"17","name":"Tikka Boti Mix Recipe","chef_name":"Mehran","link":"https:\/\/www.youtube.com\/watch?v=sbPNGHIOpQY","uvlink":"","like":"2","view":"227"},{"id":"168","image":"1580211123.png","cat_id":"17","name":"Seekh Kabab Paratha Roll Recipe","chef_name":"Mehran","link":"https:\/\/www.youtube.com\/watch?v=q36Syxhjg3o","uvlink":"","like":"19","view":"158"},{"id":"176","image":"recipe_1583154151.jpg","cat_id":"17","name":"Windows","chef_name":"Imran Ahmed","link":"","uvlink":"","like":"2","view":"119"},{"id":"190","image":"recipe_1584214019.jpg","cat_id":"17","name":"Chicken Broast","chef_name":"Imran Developer","link":"","uvlink":"http:\/\/billing.synctechsol.com\/video\/VID-20200112-WA0020.mp4","like":"3","view":"108"},{"id":"161","image":"1580309239.png","cat_id":"14","name":"Sindhi Biryani Mix Recipe","chef_name":"Mehran","link":"https:\/\/www.youtube.com\/watch?v=OUG7gYTrnEk","uvlink":"","like":"4","view":"104"},{"id":"182","image":"recipe_1584126527.jpeg","cat_id":"17","name":"Broast","chef_name":"Imran Developer","link":"","uvlink":"","like":"1","view":"64"},{"id":"198","image":"recipe_1584737360.jpeg","cat_id":"17","name":"Distribution Board","chef_name":"Imran Ahmed","link":"","uvlink":"http:\/\/billing.synctechsol.com\/video\/VID-20200219-WA0035.mp4","like":"7","view":"60"},{"id":"191","image":"recipe_1584260119.png","cat_id":"17","name":"ggbvn","chef_name":"Imran Developer","link":"","uvlink":"http:\/\/billing.synctechsol.com\/video\/VID-20200315-WA0001.mp4","like":"1","view":"58"},{"id":"163","image":"1580134470.png","cat_id":"15","name":"Achar Gosht Mix Recipe","chef_name":"Mehran","link":"https:\/\/www.youtube.com\/watch?v=5EQWOSRpzHg","uvlink":"","like":"8","view":"54"},{"id":"101","image":"1580210522.png","cat_id":"12","name":"Fish Fry Mix Recipe","chef_name":"Mehran","link":"https:\/\/www.youtube.com\/watch?v=GeSloGLoPMk","uvlink":"","like":"9","view":"50"},{"id":"178","image":"recipe_1583407824.jpg","cat_id":"17","name":"uhnbj","chef_name":"hi igh","link":"","uvlink":"","like":"0","view":"47"},{"id":"177","image":"recipe_1583234674.jpeg","cat_id":"17","name":"Kabuli Pulao","chef_name":"Imran Ahmed","link":"","uvlink":"","like":"0","view":"46"}]}]
Java Code
JSONArray jsonArray = new JSONArray(response);
JSONObject jsonObject = jsonArray.getJSONObject(0);
String status = jsonObject.getString("status");
if (status.equals("Success")) {
JSONArray recipe = jsonObject.getJSONArray("recpie");
Log.e("Lenght", String.valueOf(recipe.length()));
for (int i = 0; i < recipe.length(); i++) {
JSONObject jsonObject1 = recipe.getJSONObject(i);
SearchGetSet searchGetSet = new SearchGetSet();
String id = jsonObject1.getString("id");
String image = jsonObject1.getString("image");
String cat_id = jsonObject1.getString("cat_id");
String name = jsonObject1.getString("name");
String chef_name = jsonObject1.getString("chef_name");
String link = jsonObject1.getString("link");
String uvlink = jsonObject1.getString("uvlink");
String like = jsonObject1.getString("like");
String view = jsonObject1.getString("view");
searchGetSet.setId(id);
searchGetSet.setRec_name(name);
searchGetSet.setRec_image(image);
searchGetSet.setLikes(like);
searchGetSet.setCat_id(cat_id);
searchGetSet.setChef_name(chef_name);
searchGetSet.setLink(link);
searchGetSet.setUVlink(uvlink);
searchGetSet.setView(view);
searchList.add(searchGetSet);}}
Create and add your searchGetSet object only if the chef_name is matching the name you're searching.
My guess is (I don't know Java), you've to use a simple if-statement, while looping :
for (int i = 0; i < recipe.length(); i++) {
JSONObject jsonObject1 = recipe.getJSONObject(i);
SearchGetSet searchGetSet = null; // Do not create your searchGetSet() object yet.
String chef_name = jsonObject1.getString("chef_name");
// Check the chef's name is 'John'.
if (chef_name.equals('John')) {
String id = jsonObject1.getString("id");
String image = jsonObject1.getString("image");
String cat_id = jsonObject1.getString("cat_id");
String name = jsonObject1.getString("name");
// ...
searchGetSet = new SearchGetSet();
searchGetSet.setId(id);
searchGetSet.setRec_name(name);
searchGetSet.setRec_image(image);
// ...
// Let's add the result we have found.
searchList.add(searchGetSet);
}
}
I'm trying to add a href to Arraylist and this adds nicely to the Arraylist, but the link is broken. Everything after the question mark (?) in the URL is not included in the link.
Is there anything that I'm missing, code below:
private String processUpdate(Database dbCurrent) throws NotesException {
int intCountSuccessful = 0;
View vwLookup = dbCurrent.getView("DocsDistribution");
ArrayList<String> listArray = new ArrayList<String>();
Document doc = vwLookup.getFirstDocument();
while (doc != null) {
String paperDistro = doc.getItemValueString("DistroRecords");
if (paperDistro.equals("")) {
String ref = doc.getItemValueString("ref");
String unid = doc.getUniversalID();
// the link generated when adding to Arraylist is broken
listArray.add("" + ref + "");
}
Document tmppmDoc = vwLookup.getNextDocument(doc);
doc.recycle();
doc = tmppmDoc;
}
Collections.sort(listArray);
String listString = "";
for (String s : listArray) {
listString += s + ", \t";
}
return listString;
}
You have a problem with " escaping around unid value due to which you URL becomes gandhi.w3schools.com/testbox.nsf/distro.xsp?documentId="+ unid + "&action=openDocument.
It would be easier to read if you use String.format() and single quotes to generate the a tag:
listArray.add(String.format(
"<a href='gandhi.w3schools.com/testbox.nsf/distro.xsp?documentId=%s&action=openDocument'>%s</a>",
unid, ref));
I try to get the ID of email that I just send it through Java EWS API.
My goal is when I got that ID I would store it to Database.
This what I'm trying:
try {
String isiEmail = generateIsiEmail(nmBank, jenis, tglAw, tglAk, produk);
EmailMessage mail = new EmailMessage(service);
mail.setSubject(jdlEmail);
mail.setBody(new MessageBody(isiEmail));
//set to cc
mail.getToRecipients().add(new EmailAddress(from.replaceAll("\\s", "")));
String[] too = to.split("\\;");
for (int i = 0; i <too.length; i++) {
mail.getToRecipients().add(new EmailAddress(too[i].replaceAll("\\s", "")));
}
String[] ccc = cc.split("\\;");
for (int i = 0; i <ccc.length; i++) {
mail.getCcRecipients().add(new EmailAddress(ccc[i].replaceAll("\\s", "")));
}
mail.sendAndSaveCopy();
} catch (ServiceLocalException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
Thanks for help.
I solved by my self.
this step what I'm done with.
I use ExtendedPropertyDefinition refer from this tutorial https://learn.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2010/dd633654(v%3dexchg.80) , but I modified from C# into java programing language,
set ExtendedPropertyDefinition then save the uuidToStr to database
UUID uuid = UUID.randomUUID();
ExtendedPropertyDefinition epd = new ExtendedPropertyDefinition(uuid, "NamaId", MapiPropertyType.String);
String uuidToStr = uuid.toString();
String isiEmail = generateIsiEmail(nmBank, jenis, tglAw, tglAk, produk);
EmailMessage mail = new EmailMessage(service);
mail.setSubject(jdlEmail);
mail.setBody(new MessageBody(isiEmail));
//set to cc
mail.getToRecipients().add(new EmailAddress(from.replaceAll("\\s", "")));
String[] too = to.split("\\;");
for (int i = 0; i <too.length; i++){
mail.getToRecipients().add(new EmailAddress(too[i].replaceAll("\\s", "")));
}
String[] ccc = cc.split("\\;");
for (int i = 0; i <ccc.length; i++){
mail.getCcRecipients().add(new EmailAddress(ccc[i].replaceAll("\\s", "")));
}
mail.setExtendedProperty(epd, "isiId");
mail.sendAndSaveCopy();
get the email based on ExtendedPropertyDefinition uuidToStr from database
UUID uuid = UUID.fromString("cc59cdbf-aad4-4cd1-a4f0-e7819c56b884");
ExtendedPropertyDefinition epd = new ExtendedPropertyDefinition(uuid, "NamaId", MapiPropertyType.String);
ItemView view2 = new ItemView(3);
SearchFilter sf = new SearchFilter.IsEqualTo(epd,"isiId");
FindItemsResults<Item> fir = service.findItems(WellKnownFolderName.SentItems, sf, view2);
for (Item itm : fir.getItems()){
System.out.println(itm.getId());
System.out.println(itm.getSubject());
}
DONE;
You should make use of the InternetMessageId property.
Call the FindItems method to search for messages in the sent items folder. Then instantiate an EmailMessage object so you can access the InternetMessageId property:
ItemView view = new ItemView(100); // You can change this to your needs.
view.PropertySet = new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.InternetMessageId);
FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.SentItems, view);
foreach (Item item in results)
{
if (item is EmailMessage)
{
EmailMessage emailMsg = item as EmailMessage;
Console.WriteLine(emailMsg.InternetMessageId);
}
}
I am using C# EWS Api, But this logic will work for you.
First you have to Save the email in Draft and then after you can get Email id.
EmailMessage emailMessage = new EmailMessage(service);
emailMessage.From = email.From;
emailMessage.Subject = email.Subject;
emailMessage.Body = new MessageBody(BodyType.HTML, email.Body);
foreach (var toAddress in email.To)
{
emailMessage.ToRecipients.Add(toAddress);
}
// Send message and save copy by default to sentItems folder
emailMessage.Save();
emailMessage.Load();
// Get Email Conversation Id.
string ConversationId = emailMessage.ConversationId.UniqueId;
string EmailMessageId;
emailMessage.SendAndSaveCopy();
// Get Email Message Id by InternetMessageId.
List<SearchFilter> searchFilterCollection = new List<SearchFilter>();
searchFilterCollection.Add(new SearchFilter.ContainsSubstring(EmailMessageSchema.InternetMessageId, InternetMessageId));
// Create the search filter.
SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilterCollection.ToArray());
ItemView view = new ItemView(50);
view.PropertySet = new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.InternetMessageId);
FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.SentItems, searchFilter, view);
if (results.Items.Count > 0)
{
Item item = results.Items[0];
EmailMessage message = EmailMessage.Bind(service, item.Id);
EmailMessageId = message.Id.UniqueId;
}
I believe the solution is this:
EmailMessage em = EmailMessage.bind( service, item.getId(),
new PropertySet( EmailMessageSchema.InternetMessageId) );
Explanation :
We have to bind the item to an email message, but instead of grabbing all the info, we only ask for the ID and any additional properties we want through the PropertySet parameter.
found -> Exchange Web Services get Message Message-ID
i am aware that there is a lot of threads about this exception however, i would like people to view my code and assist me in where i am specifically going wrong.
Here is my code for trying to store my users input to an sqlite database and then transfer the code and display it in a new activity. Can anyone tell me where i am going wrong and why this error keeps occuring? (error in title)
Cursor res = myDb.getAllData();
StringBuffer buffer = new StringBuffer();
String getid = res.getString(0);
String getlt = res.getString(1);
String getpt = res.getString(2);
String getqty = res.getString(3);
String getdur = res.getString(4);
String getst = res.getString(5);
String getet = res.getString(6);
if ( res != null && res.moveToFirst()) {
do {
buffer.append(getid);
buffer.append(getlt);
buffer.append(getpt);
buffer.append(getqty);
buffer.append(getdur);
buffer.append(getst);
buffer.append(getet);
} while (res.moveToNext());
}
Intent TransferData = new Intent(getBaseContext(), screen4.class);
TransferData.putExtra("ID", getid);
TransferData.putExtra("LineType", getlt);
TransferData.putExtra("PackageType", getpt);
TransferData.putExtra("Quantity", getqty);
TransferData.putExtra("Duration", getdur);
TransferData.putExtra("Starttime",getst);
TransferData.putExtra("endtime", getet);
startActivity(TransferData);
}
});
}
}
ATTEMPT 2 INSIDE DO BLOCK :
Cursor res = myDb.getAllData();
StringBuffer buffer = new StringBuffer();
if ( res != null && res.moveToNext()) {
do {
String getid = res.getString(0);
String getlt = res.getString(1);
String getpt = res.getString(2);
String getqty = res.getString(3);
String getdur = res.getString(4);
String getst = res.getString(5);
String getet = res.getString(6);
buffer.append(getid);
buffer.append(getlt);
buffer.append(getpt);
buffer.append(getqty);
buffer.append(getdur);
buffer.append(getst);
buffer.append(getet);
Intent TransferData = new Intent(getBaseContext(), screen4.class);
TransferData.putExtra("ID", getid);
TransferData.putExtra("LineType", getlt);
TransferData.putExtra("PackageType", getpt);
TransferData.putExtra("Quantity", getqty);
TransferData.putExtra("Duration", getdur);
TransferData.putExtra("Starttime",getst);
TransferData.putExtra("endtime", getet);
startActivity(TransferData);
} while (res.moveToNext());
What you are trying to do is a unclear.
In your code there is:
String getid = res.getString(0);
String getlt = res.getString(1);
//bla bla bla
I believe they should be inside the do block.
You have tried to access the column data without moving the Cursor to first position.
You must call Cursor#moveToFirst(); before reading any value from the Cursor.
I am trying to post data in wordpress using this code but I am getting token null
In place of sXmlRpcURL I have used http://wordpress.com/ and http://sUsername.wordpress.com/ also but both the cases its generating token null.
String sXmlRpcURL= arg[0];
String sUsername = arg[1];
String sPassword = arg[2];
// Hard-coded blog_ID
int blog_ID = 1;
// XML-RPC method
String sXmlRpcMethod = "blogger.newPost";
// XML-RPC method ver 2
// sXmlRpcMethod = "metaWeblog.newPost"; // I have used this also
// We'll hard-code our blog content for now as well
String sTitle = "HI........";
String sContent = "Hello XML-RPC World!";
// Create our content struct
HashMap hmContent = new HashMap();
hmContent.put("title", sTitle);
hmContent.put("description", sContent);
// You can specify whether or not you want the blog published immediately
boolean bPublish = true;
// Try block
try {
// Create the XML-RPC client
XmlRpcClient client = new XmlRpcClient(sXmlRpcURL,true);
// Make our method call
Object token = client.invoke( sXmlRpcMethod, new Object[] { new Integer( blog_ID ), sUsername, sPassword, hmContent, new Boolean( bPublish ) } );
// The return is a String containing the postID
System.out.println("Posted : " + (String) token);
} // Catch exceptions
catch (Exception e) {
}
please help me.
I have got the solution you want to use -
http://sUsername.wordpress.com/xmlrpc.php?
for sXmlRpcURL.
Now it working well-