I'm trying to retrieve image from the images folder of the firebase. However, Its show the "Failed to retrieve the image" meessage. May I know where have I do wrong ?
<ImageView
android:id="#+id/restaurant_image"
android:layout_width="300dp"
android:layout_height="200dp"
android:layout_gravity="start"
android:contentDescription="#string/logo_description"
android:layout_marginEnd="40dp"
/>
val imageName = restaurant.imageName
val imageRef = FirebaseStorage.getInstance().reference.child("images/$imageName.jpg")
val localfile = File.createTempFile("TempImage","jpg")
imageRef.getFile(localfile).addOnSuccessListener {
val bitmap = BitmapFactory.decodeFile(localfile.absolutePath)
binding.restaurantImage.setImageBitmap(bitmap)
}.addOnFailureListener{
Toast.makeText(this,"Failed to retrieve the image",Toast.LENGTH_SHORT).show()
}
Related
In my app I have listed all the SMS messages that are available inside my phone, I added it but
I wish to add contact name (whatever saved in my phone) at the place where contact number is showing.
I also added all the required permission to show SMS in Android Manifest file
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
if anyone know how to achieve this in android studio, it will be very helpfull for me
Thankyou in advance.
I have attached an image below
public void showSMSData() {
ContentResolver contentResolver = getContentResolver();
Cursor smsInboxCursor = contentResolver.query(Uri.parse("content://sms/"), null, null, null, null);
int indexBody = smsInboxCursor.getColumnIndex("body");
int indexAddress = smsInboxCursor.getColumnIndex("address");
if (indexBody < 0 || !smsInboxCursor.moveToFirst()) return;
arrayList.clear();
addresses.clear();
do {
if (!addresses.contains(smsInboxCursor.getString(indexAddress))) {
String str = smsInboxCursor.getString(indexBody) + "\n";
SMSModel smsModel = new SMSModel(smsInboxCursor.getString(indexAddress), str);
addresses.add(smsInboxCursor.getString(indexAddress));
arrayList.add(smsModel);
}
} while (smsInboxCursor.moveToNext());
}
I wish to add contact name (whatever saved in my phone) at the place where contact number is showing
if anyone know how to achieve this in android studio
I am trying to read values from XML to swf file ,so i have a xml file like this :
<?xml version="1.0" encoding="utf-8"?>
<GALLERY>
<IMAGE TITLE="ssasa">image1.jpg</IMAGE>
<IMAGE TITLE="oooo">image2.jpg</IMAGE>
<IMAGE TITLE="shop">image3.jpg</IMAGE>
</GALLERY>
In my AS3 flash file i have this code :
import flash.system.SecurityDomain;
import flash.system.Security;
var xml:XML;
var xmlList:XMLList;
var xmlLoader:URLLoader = new URLLoader();
Security.loadPolicyFile("http://localhost:15979/crossdomain.xml");
xmlLoader.load(new URLRequest("http://localhost:15979/default.aspx"));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
function xmlLoaded(event:Event):void
{
xml = XML(event.target.data);
xmlList = xml.children();
trace(xml.IMAGE[1].#TITLE);
txtname.text=xml.IMAGE[1].#TITLE;
}
In my timeline i have this :
As you can see i call my acionscript code in frame 22,but my problem is when i changed the data in xml file the swf file ,it doesn't apply to swf file and the swf file shows the old text on the screen ,but after closing the file it works fine and the new text appears.
I think it is because the iis cachs the data .!!!
best regards
I finally add this value to my request :
var request:URLRequest = new URLRequest("http://localhost:15979/default.aspx");
var variables:URLVariables = new URLVariables();
variables.nocache = new Date().getTime();
// set up other URLVariables here
request.data = variables;
I am sure that title of my question doesn't makes much sense, but i couldn't think better now.
Problem: My main task is to show all pages of a SSRS report in a popup inside one of the pages of a ASP.NET MVC application.
To achieve this I used below approach:
Add a jQuery popup in MyPage.cshtml(i need report contents inside this popup)
When this popup opens(on some client action), I make a jquery ajax request to second page proxyPage.aspx
On proxy page I make a webrequest to reportserver with network credentials and get report html
WebRequest request = WebRequest.Create( "http://MyReportServer/ReportServer?/ MyReportName&rs:Command=Render&rs:Format =HTML4.0&rc:Toolbar=false&Param1=blabla123");
request.Credentials = new NetworkCredential(MYUSERNAME, MYPASSWORD);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, System.Text.Encoding.UTF8);
string str = readStream.ReadToEnd();
Response.Write(str);
HTML from proxyPage I write in a div inside popup or using iframe to show full proxy page inside it.
Till here things go well and thereafter I get yet another problem for which I am writing this question
When report's HTML gets rendered in popup it makes request to report server to retrieve images embedded in report.
Since these requests to report server doesn't send network credentials as I did in step 3, I get prompt for entering credentials.
I need a approach through which these image request may somehow get authenticated by credentials that I have already supplied earlier.
SSRS will stream the resources in a location you specify.
private byte[] InternalRenderReport(Report report, List<ReportParameter> parameters, string format, int pageNumber, ref int totalPages, string virtualTempFolder, string physicalTempFolder)
{
CheckConnection();
byte[] result = null;
ReportExecution2005.ReportExecutionService _execService=new ReportExecution2005.ReportExecutionService();
sys = _systemService.GetCurrentSystem();
_execService.Url = sys.ReportingServices.ServiceRootURL+"/ReportExecution2005.asmx";
NetworkCredential credentials = new NetworkCredential(sys.ReportingServices.Credentials.UserName,
sys.ReportingServices.Credentials.Password,
sys.ReportingServices.Credentials.Domain);
_execService.Credentials=credentials;
ReportExecution2005.ParameterValue[] rsParams = null;
if (parameters != null)
{
rsParams = new ReportExecution2005.ParameterValue[parameters.Count];
int x = 0;
foreach (ReportParameter p in parameters)
{
rsParams[x] = new ReportExecution2005.ParameterValue();
rsParams[x].Name = p.ParameterName;
rsParams[x].Value = p.SelectedValue;
x++;
}
}
StringBuilder devInfo = new StringBuilder();
if (format.ToUpper().StartsWith("HTML"))
{
devInfo.Append("<DeviceInfo>");
devInfo.Append("<HTMLFragment>True</HTMLFragment>");
devInfo.Append("<Section>" + pageNumber.ToString() +"</Section>");
devInfo.Append("<StreamRoot>" + virtualTempFolder + "</StreamRoot>");
/*devInfo.Append("<Zoom>200</Zoom>");*/
devInfo.Append("</DeviceInfo>");
}
else
devInfo.Append("<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>");
string extension;
string mimeType;
string encoding;
string[] streamIDs = null;
ReportExecution2005.Warning[] warnings = null;
ReportExecution2005.ExecutionHeader execHeader = new ReportExecution2005.ExecutionHeader();
ReportExecution2005.ExecutionInfo rpt = _execService.LoadReport(report.ReportPath, null);
if(rsParams!=null)
_execService.SetExecutionParameters(rsParams, "en-us");
_execService.ExecutionHeaderValue = execHeader;
_execService.ExecutionHeaderValue.ExecutionID = rpt.ExecutionID;
//result = _execService.Render2(format, devInfo, ReportExecution2005.PageCountMode.Actual, out extension, out mimeType, out encoding, out warnings, streamIDs);
result = _execService.Render(format, devInfo.ToString(), out extension, out mimeType, out encoding, out warnings, out streamIDs);
if (format.ToUpper().StartsWith("HTML"))
{
// For each image stream returned by the call to render,
// render the stream and save it to the application root
string FilePath = physicalTempFolder;
byte[] image;
// For each image stream returned by the call to render,
// render the stream and save it to the application root
foreach (string streamID in streamIDs)
{
image = _execService.RenderStream("HTML4.0", streamID, null, out encoding, out mimeType);
FileStream stream = File.OpenWrite(FilePath + streamID);
stream.Write(image, 0, image.Length);
stream.Close();
}
}
rpt = _execService.GetExecutionInfo();
totalPages = rpt.NumPages;
return result;
}
This will return either raw HTML or the contents to push a file. I added a Temp folder to the solution to be deployed to the server. you can place a web.config file in the temp folder with the following contents to allow extension less contents as ssrs will render when using streams:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".*" mimeType="image/png" />
</staticContent>
<handlers>
<clear />
<add name="StaticFile" path="*" verb="*" type="" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" scriptProcessor="" resourceType="Either" requireAccess="Read" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
</handlers>
</system.webServer>
</configuration>
Then use the following to functions to get the physical and Virtual Temp folders:
PhyscicalTempFolder= AppDomain.CurrentDomain.BaseDirectory + #"Temp\";
VirtualTempFolder=return Url.Content("~/Temp/");
And finally to clean up after each day you can add a powershell command similar to:
Remove-Item D:\xxx\WebApplications\ExternalReports\Temp\* -exclude *.config
Then add a .bat that calls the PS script:
powershell -command "& 'C:\xxx\Scripts\SSRSCleanTempFiles\SSRSCleanTempFiles.ps1'"
With this you can configure a scheduled task on the server to call the .bat file everyday and clean the temp folder of your application.
How can I add an item to a repeatable property programmatically in c#:
let's say I have a node (node id 1234) and in it companies list property, where each item has comapny name and image (media picker).
how do I add an item programmtically ?
Here's what I have so far:
XPathNodeIterator xpathIterator = umbraco.library.GetXmlNodeById(NodeId.ToString());
XElement node = XElement.Parse(xpathIterator.Current.OuterXml);
var list = node.Descendants(propertyAlias).FirstOrDefault();
// how do I add items here ? something like:
list.Descendants().Add(...)
thanks.
The package I'm referring to is:
Repeatable Custom Content
update:
I think the solution is to update the xml in umbraco.config.
I have the following xml in umbraco.config:
<Companies id="1176" parentID="1447" ...>
<umbracoNaviHide>0</umbracoNaviHide>
<companyList>
<item>
<data alias="title">Company1</data>
<data alias="image" />
<data alias="text" />
<data alias="date" />
</item>
<item>
<data alias="title">Company2</data>
<data alias="image">1943</data>
<data alias="text" />
<data alias="date" />
</item>
</items>
</companyList>
</Companies>
I am able to update umbraco.config programmatically, but the results are not updated in the backend, so that when I publish the companies node again, the changes are deleted. How can I update the umbraco.config and publish the node ?
Maybe I sh should update the database directly instead ?
My code:
Document companiesDoc = new Document(COMPANIESNODEID);
XmlDocument document = content.Instance.XmlContent;
XmlNode n = document.SelectSingleNode("//Companies[#id=" + COMPANIESNODEID.ToString() + "]").SelectSingleNode("//items");
XmlNode newItem = document.CreateNode(XmlNodeType.Element, "item", null);
XmlNode dName = document.CreateNode(XmlNodeType.Element, "data", null);
XmlAttribute xn = document.CreateAttribute("alias");
xn.Value = "title";
dName.Attributes.Append(xn);
dName.InnerText = companyName;
XmlNode dImage = document.CreateNode(XmlNodeType.Element, "data", null);
XmlAttribute xi = document.CreateAttribute("alias");
xi.Value = "image";
dImage.Attributes.Append(xi);
dImage.InnerText = companyImage;
XmlNode dText = document.CreateNode(XmlNodeType.Element, "data", null);
XmlAttribute xt = document.CreateAttribute("alias");
xt.Value = "text";
dText.Attributes.Append(xt);
XmlNode dDate = document.CreateNode(XmlNodeType.Element, "data", null);
XmlAttribute xd = document.CreateAttribute("alias");
xd.Value = "date";
dDate.Attributes.Append(xd);
newItem.AppendChild(dName);
newItem.AppendChild(dImage);
newItem.AppendChild(dText);
newItem.AppendChild(dDate);
n.AppendChild(newItem);
I am able to update umbraco.config programmatically, but the results
are not updated in the backend, so that when I publish the companies
node again, the changes are deleted. How can I update the
umbraco.config and publish the node ?
You are going about it the wrong way. The umbraco.config file is a read-only XML representation of the Umbraco database that is generated by Umbraco and then cached. It isn't intended to be written to or accessed directly. Every time you publish a page in Umbraco this file is regenerated, hence the reasons your updates are not persisted.
You also don't want to try and write to the Umbraco database directly, either. It is very complex and requires lots of relations. Again, it isn't intended to be written to.
To update nodes directly what you really need to do is use the Umbraco Document API. This allows you direct write access to nodes which you can the programatically publish. Simple example:
Document doc = new Document(1234);
doc.getProperty("bodyText").Value = "<p>Your body text</p>";
doc.getProperty("articleDate").Value = DateTime.Now;
User author = User.GetUser(0);
doc.Publish(author);
umbraco.library.UpdateDocumentCache(doc.Id);
I'd suggest posting on http://our.umbraco.org/forum if you need more help.
I managed to solve the problem using this code:
var doc = new Document(COMPANIESNODEID);
XDocument xdoc = XDocument.Parse(doc.getProperty("companyList").Value.ToString());
xdoc.Element("items").Add(new XElement("item",
new XElement("data", new XAttribute("alias", "title"), companyName),
new XElement("data", new XAttribute("alias", "image"), companyImage)));
doc.getProperty("companyList").Value = xdoc.ToString();
doc.Save();
doc.Publish(new User(0));
umbraco.library.UpdateDocumentCache(doc.Id);
<?xml version="1.0"?>
<Image>
<Overview>13</Overview>
<Gallery1>1</Gallery1>
<Gallery2>4</Gallery2>
<Gallery3>6</Gallery3>
<Gallery4>1</Gallery4>
</Image>
This is my xml file.
I have a dropdown value with values (gallery1, gallery2, gallery3 and so on).
If user selects gallery2 and types 5 in the text box
and clicks the OK button, then I need to load my above XML file and check what gallery value we need to update. But first we need to get the value from XML.
Here I am trying to update gallery2 so first I need get the gallery2 value (4)
then add the new value with old value (5+4=9) and then save. So now gallery2 will contain the value 9.
result
<?xml version="1.0"?>
<Image>
<Overview>13</Overview>
<Gallery1>1</Gallery1>
**<Gallery2>9</Gallery2>**
<Gallery3>6</Gallery3>
<Gallery4>1</Gallery4>
</Image>
I think what you are looking is
protected void Button12_Click(object sender, EventArgs e)
{
lbl = GetLabel(275, 20);
//Declare and load new XmlDocument
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(MapPath("XmlSample.xml"));
//delete a mode
XmlNode node;
node = xmlDoc.SelectSingleNode("//Image");
node.ParentNode.RemoveChild(node);
//create a node and add it
XmlElement newElement =
xmlDoc.CreateElement("myNewElement");
node = xmlDoc.SelectSingleNode("//Image");
node.ParentNode.InsertAfter(newElement, node);
xmlDoc.Save(MapPath("XmlSampleModified.xml"));
}
A more general-purpose version of this method would take the entire XPath to the element you want to change, instead of just assuming that it's a child of a top-level Image element.
private void AddElementValue(XmlDocument doc, string tagName, int valueToAdd)
{
XmlElement elm = doc.SelectSingleElement("/Image/" + tagName);
Debug.Assert(elm != null, "Didn't find " + tagName);
int currentValue;
if (int.TryParse(elm.InnerText, out currentValue))
{
elm.InnerText = (currentValue + valueToAdd).ToString();
return;
}
Debug.Fail(elm.InnerText + " can't be parsed as an integer.");
}