मेरे आवेदन में, मुझे विभिन्न मुद्राओं के लिए वर्तमान विनिमय दर प्राप्त करने की आवश्यकता है। जैसा कि this, this और this द्वारा यह सुझाव देने का एक अच्छा तरीका है, याहू वित्त सेवा का उपयोग करना है।एंड्रॉइड में याहू मुद्रा विनिमय दरें 4
तो, जब मैं खोजना चाहते हैं, उदाहरण के लिए, अमरीकी डालर और कनाडा डॉलर के बीच दर, मैं बस यह लिंक भेजें: http://download.finance.yahoo.com/d/quotes.csv?s=USDCAD=X&f=sl1d1t1ba&e=.csv
यह एंड्रॉयड 2.3.4 के साथ अपने दोनों मोटोरोला Atrix फोन के लिए ठीक काम कर रहा है और Google API 2.3.3 के साथ फिर से एमुलेटर। हालांकि, जब मैं एंड्रॉइड आईसीएस 4.0 के साथ एक गैलेक्सी एसआईआई और Google एपीआई 4.0 के साथ एक एमुलेटर से सटीक वही लिंक आज़माता हूं, तो दोनों मामलों में quotes.csv फ़ाइल में केवल "गायब प्रतीक सूची" होती है।
चारों ओर खोदने के बाद, मुझे पता चला कि यह प्रतिक्रिया मिलने के मामले में यह प्रतिक्रिया हो सकती है। लेकिन यह प्रतिक्रिया एंड्रॉइड 4.0 (या तो गैलेक्सी एसआईआई या एम्यूलेटर) के तहत कोशिश की जाने वाली किसी भी मुद्रा के लिए है। इसलिए, मुझे एंड्रॉइड 4.0 के साथ दरें नहीं मिल सकती हैं, लेकिन मैं एंड्रॉइड 2.x के साथ कर सकता हूं।
क्या किसी को भी एक ही समस्या का अनुभव किया है? क्या कोई कामकाज है?
संपादित करें:
//show the progress dialog
downloadingDialog.show();
Runnable getRates = new Runnable() {
public void run(){
dataNotFound = false;
final String baseDir = getApplicationContext().getFilesDir().getAbsolutePath();
//download the rates from yahoo to a CSV file
downloadFileViaHTTP (baseDir);
//read the file line
String filePath = baseDir + "/" + "quotes.csv";
Log.d(tag, "-> filePath = " + filePath);
try {
// open the file for reading
InputStream instream = new FileInputStream(filePath);
// if file the available for reading
if (instream != null) {
// prepare the file for reading
InputStreamReader inputreader = new InputStreamReader(instream);
BufferedReader buffreader = new BufferedReader(inputreader);
//read the line
String fileLine = buffreader.readLine();
Log.d(tag, "fileLine = " + fileLine);
instream.close();
}
}
catch (Exception ex) {
// print stack trace.
}
}
};
final Thread t = new Thread(getRates);
t.start();
और यह याहू साइट से quotes.csv फ़ाइल डाउनलोड करने के लिए मेरे समारोह है:
public void downloadFileViaHTTP (String localPath) {
Log.d(tag, "downloadFileViaHTTP...");
try {
//this is the Yahoo url
String urlFile = "http://download.finance.yahoo.com/d/quotes.csv?s=" + fromCurrency + toCurrency + "=X&f=sl1d1t1ba&e=.csv";
Log.d(tag,"urlFile = " + urlFile);
URL url = new URL(urlFile);
//create the new connection
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.connect();
//pointer to the downloaded file path
String localFileName = localPath + "/" + "quotes.csv";
//this is the actual downloaded file
File MyFilePtrDest = new File(localFileName);
Log.d(tag,"localFileName = " + localFileName);
//this will be used in reading the data from the Internet
InputStream inputStream = urlConnection.getInputStream();
//this will be used to write the downloaded data into the file we created
FileOutputStream fileOutput = new FileOutputStream(MyFilePtrDest);
byte[] buffer = new byte[1024];
int bufferLength = 0; //used to store a temporary size of the buffer
//write buffer contents to file
while ((bufferLength = inputStream.read(buffer)) > 0) {
//add the data in the buffer to the file in the file output stream (the file on the sd card
fileOutput.write(buffer, 0, bufferLength);
}
inputStream.close();
//close the output stream when done
fileOutput.flush();
fileOutput.close();
urlConnection.disconnect();
}
catch (IOException e) {
//data were not found
dataNotFound = true;
// TODO Auto-generated catch block
e.printStackTrace();
}
}
यह धागा कोड है कि याहू मुद्रा सेवा से डाउनलोड दरों से संबंधित है
12-18 11:04:24.091: D/CurrencyConverter(414): downloadFileViaHTTP...
12-18 11:04:24.091: D/CurrencyConverter(414): urlFile = http://download.finance.yahoo.com/d/quotes.csv?s=EURUSD=X&f=sl1d1t1ba&e=.csv
12-18 11:04:24.282: D/CurrencyConverter(414): localFileName = /data/data/com.myapps.currencyconverter/files/quotes.csv
12-18 11:04:24.461: D/CurrencyConverter(414): -> filePath = /data/data/com.myapps.currencyconverter/files/quotes.csv
12-18 11:04:24.461: D/CurrencyConverter(414): fileLine = "EURUSD=X",1.3172,"12/18/2012","4:03am",1.317,1.3174
और यह:
यह गूगल एपीआई 2.3.3 एमुलेटर से लॉग है
12-18 11:47:36.130: D/CurrencyConverter(668): downloadFileViaHTTP...
12-18 11:47:36.130: D/CurrencyConverter(668): urlFile = http://download.finance.yahoo.com/d/quotes.csv?s=EURUSD=X&f=sl1d1t1ba&e=.csv
12-18 11:47:36.449: D/dalvikvm(668): GC_CONCURRENT freed 306K, 4% free 11714K/12167K, paused 5ms+10ms
12-18 11:47:36.951: D/CurrencyConverter(668): localFileName = /data/data/com.myapps.currencyconverter/files/quotes.csv
12-18 11:47:37.159: D/CurrencyConverter(668): -> filePath = /data/data/com.myapps.currencyconverter/files/quotes.csv
12-18 11:47:37.159: D/CurrencyConverter(668): fileLine = Missing Symbols List.
आप "fileLine" स्ट्रिंग वैरिएबल, पहला मामला यह उचित दरों हो जाता है, देख सकते हैं दूसरे पर, quotes.csv फ़ाइल केवल शामिल करते हुए: गूगल API 4.0 एमुलेटर से लॉग है "गुम प्रतीक सूची"। मूल्य।
EDIT2: मैंने पूरी एंड्रॉइड प्रोजेक्ट shared folder पर अपलोड किया है, इसलिए हर कोई इसे आजमा सकता है। आप एंड्रॉइड 2.x और 4 अनुकरणकर्ताओं (या यदि आपके पास हैं तो फोन :-))
EDIT3: हालांकि यह प्रत्यक्ष उत्तर नहीं है, फिर भी यह एक कामकाज है। मैं याहू के बजाय Google मुद्रा कैलक्यूलेटर का उपयोग करता हूं। Google मुद्रा कैलक्यूलेटर का उपयोग करने के लिए, बस इस यूआरएल यूआरएल को इस के साथ बदलें: http://www.google.com/ig/calculator?hl=en&q=1 "+ से कुरेंसी +" =? "+ टू कूरेंसी। 78 यूरो से यूएसडी में कनवर्ट करने का उदाहरण देखने के लिए this link पर क्लिक करें। मैंने जांच की और यह एंड्रॉइड संस्करणों दोनों के साथ काम करता है हालांकि, अगर कोई यह पता लगाता है कि यह याहू साइट के साथ क्यों हो रहा है, तो यह हमारे साथ साझा करना अच्छा होगा ..
बताया जाता है पोस्ट अपने कोड। –
मैं संपादित किया है मेरा उत्तर (EDIT3) एक कार्यवाही के साथ जो Google मुद्रा कैलक्यूलेटर का उपयोग करता है। – Dimitris