I have a recyclerview data is set from server i want to save the data to pdf file
how can i achieve please help
JSONArray jsonArray = jobj.getJSONArray("Complaint Details");
rcview.setBackgroundResource(R.drawable.bbg1);
for (int i = 0; i < jsonArray.length(); i++) {
jobj = jsonArray.getJSONObject(i);
viewcmplist item = new viewcmplist(
jobj.getString("subject"),
jobj.getString("mark"),
jobj.getString("ce"),
jobj.getString("te"),
jobj.getString("grade")
);
listitems1.add(item);
}
cmpadapter = new CmpviewAdapter(listitems1, getApplicationContext());
rcview.setAdapter(cmpadapter);
You can use a custom library such as https://github.com/HendrixString/Android-PdfMyXml. I prefer this library than any other method. Just Go through these.
but there is another way -
How to convert Android View to PDF - that generate a pdf that contains bitmap of your layout
Related
I am using gson 2.2.4.
The code in question:
int[] byte_message = new int[message.getBytes("UTF8").length];
for (int i = 0; i < message.getBytes("UTF8").length; i++) {
byte_message[i] = message.getBytes("UTF8")[i] & 0xff;
}
result.put("message", byte_message);
JSONObject json_obj = new JSONObject(result);
String json = json_obj.toString();
In Android version of 4.3, the json variable contains:
{"message":"[I#4135f3b0"}
In other versions for the same exact code, the json variable contains:
{"message":[66,106]}
Can anyone explain this discrepancy?
I have a problem,
I'm trying to add images in my pdf with jsPDF. b64Tab is an array containing the base64 data of my jpg images that i want to add.
After the
doc.output();
The different pages are created with the text added, but the images are not displayed. I test this on a 4.2.2 Android phone.
Here is a piece of code :
for (var j = 0; j < b64Tab.length; j++) {
doc.addPage();
doc.setFontSize(22);
doc.text(130, 65, descriptions[j]);
doc.addImage(b64Tab[j], 'JPEG', 40, 100, 500, 500);
}
I'm using the latest jsPDF's build.
Any help would be welcomed.
Thanks.
If you are not using File plugin then replace pdf output with doc.output("blob");
If you are using File plugin then create a buffer to write on the file eg.
var data = getPDFFile();
var buffer = new ArrayBuffer(data.length);
var array = new Uint8Array(buffer);
for (var i = 0; i < data.length; i++) {
array[i] = data.charCodeAt(i);
}
writer.write(buffer); // here you write on file using File plugin
I've to read a stream from a rss feed on an Android application.
All work fine, but i'm not able to get the complete url, from the tag, because it's a selfclosed tag
somethings like
This's the xml page (i can't edit it) Xml source page
and this is the code to populate to create the single objet that I need
String titolo, descrizione, descrizione_breve, img, data, icona;
Notizia SitoDaAggiungere;
for (int i = 0; i < nodi.getLength(); i++) {
Node nodoItem = nodi.item(i);
if (nodoItem.getNodeType() == Node.ELEMENT_NODE) {
Element elemento = (Element) nodoItem;
titolo = elemento.getElementsByTagName("title").item(0).getTextContent();
descrizione_breve = elemento.getElementsByTagName("summary").item(0).getTextContent();
descrizione = elemento.getElementsByTagName("content").item(0).getTextContent();
img = elemento.getElementsByTagName("pic1").item(0).getTextContent();
data = elemento.getElementsByTagName("updated").item(0).getTextContent();
icona = elemento.getElementsByTagName("pic").item(0).getTextContent();
String link_sito = elemento.getElementsByTagName("link").item(0).getTextContent(); // <-- no error, but an empty string
SitoDaAggiungere = new Notizia(titolo, descrizione, descrizione_breve, data, img, icona, link_sito);
InserisciSito(SitoDaAggiungere);
}
}
Someone can help me?
thank's a lot!
finally I do it!!!
this's the code to get the url
String link_sito = elemento.getElementsByTagName("link").item(0).getAttributes().item(0).getTextContent();
now I simply use it to create the new objet
I have a list of HTTP links that are basically links for streaming videos (HLS). I was wondering if there was a simple and straightforward way to basically pick from a list of HTTP links from an Android app and have them stream on my TV via chromecast.
I've looked at some of the sample apps on the Google Cast github and couldn't find any examples.
Thanks
HLS support is Yes so, to accomodate the HLS/m3u8 playlist in terms of android chromecast api you might consider remapping the m3u8 to a MediaList/MediaInfo combo and then using the chromecast ccl calls to play a mediainfo entry from the new list...
details making a new list entry and adding to list:
mediaList = new ArrayList<MediaInfo>();
JSONObject jsonObj = new VideoProvider().parseUrl(url);
JSONArray categories = jsonObj.getJSONArray(TAG_RESULTS);
if (null != categories) {
for (int i = 0; i < categories.length(); i++) {
JSONObject category = categories.getJSONObject(i);
String title = category.getString(TAG_MSG);
if(title.length() > 25) title = title.substring(0, 24);
String subTitle = category.getString(TAG_MSG);
JSONObject media3 = category.getJSONObject(TAG_MEDIA3);
String videoUrl = media3.getString(TAG_URL);
JSONObject media1 = category.getJSONObject(TAG_MEDIA1);
String bigImageurl = media1.getString(TAG_URL);
JSONObject media4 = category.getJSONObject(TAG_MEDIA4);
String imageurl = media4.getString(TAG_URL);
String studio = category.getJSONObject(TAG_CREATEDBY).getString(TAG_USERNAME);
mediaList.add(buildMediaInfo(title, studio, subTitle, videoUrl, imageurl,
bigImageurl));
}
The above provides some type of 'media bundle' that can be provide to one of the many, types of calls to startCastControllerActivity(#Type) in the ccl class VideoCastManager
take a good look at the section /==VideoCastControllerActivity management ===/ in that class. It may help you out
I'm using the DOM parser to retrive information from a XML file that looks like this:
<data>
<metData>
<wantedInformation>
</metData>
<metData>
<Information>
</metData>
<metData>
<Information>
</metData>
<data>
The problem is because I don't know how to parse only the first part of <metData>. I don't need the second and the third part, but the parser displays them anyway.
The xml file is from a weather forcast site:
http://www.meteo.si/uploads/probase/www/fproduct/text/sl/fcast_SLOVENIA_MIDDLE_latest.xml
and I need just the following line: <nn_shortText>oblačno</nn_shortText>
Pls take care whether your XML file is well formed or not,
You have to the notice three methods which i had shown below, they are
1. getElementsByTagName - Mention the tag which you want to parse
2.getChildNodes - retervies the child node
3.getNodeValue()- with the help of this method you can access the
value of particular tag
Step 1: Create a Method to parse _Information_Value ,inorder to parse the data of Information tag
String[] infoId=null;
public void parse_Information_Value() throws UnknownHostException{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder builder = factory.newDocumentBuilder();
Document dom = builder.parse(this.getInputStream());
org.w3c.dom.Element root = dom.getDocumentElement();
NodeList items = root.getElementsByTagName("metData");
int a=items.getLength();
int k=0;
for (int i = 0; i < items.getLength(); i++) {
Message_category message = new Message_category();
Node item = items.item(i);
NodeList properties = item.getChildNodes();
for (int j = 0; j < properties.getLength(); j++) {
Node property = properties.item(j);
String name = property.getNodeName();
if (name.equalsIgnoreCase("wantedInformation")) {
message.setId(property.getFirstChild()
.getNodeValue());
infoId[k]=property.getFirstChild().getNodeValue();
k++;
}
}
}
} catch (Exception e) { }
}
Depending on the size of your document, you may also want to use at a streaming oriented parser like SAX or Stax, which does not pull the whole document into memory and thus needs less memory than DOM.
Good thing is that SAX is already built into Android, so you can use it right away.
See this link for a usage example.