पर सबमिट करने के लिए एंड्रॉइड का उपयोग करना पहली बार यहां एक प्रश्न पूछना। आम तौर पर मैं पूछने के बिना अपना जवाब पा सकता हूं, लेकिन इस बार मैं फंस गया हूं और यह पता नहीं लगा सकता कि मैं क्या खो रहा हूं।Google स्प्रेडशीट फ़ॉर्म
मैं बस अपना एंड्रॉइड ऐप वेबसाइट पर एक फॉर्म भरने की कोशिश कर रहा हूं और इसे सबमिट कर रहा हूं। मुझे किसी भी डेटा को वापस भेजने के साथ ऐप की आवश्यकता नहीं है, बस फॉर्म भरें और सबमिट करें। असल में मैं एक मतदान ऐप के परिणाम एकत्र करने की कोशिश कर रहा हूं। मैंने सोचा कि फ़ॉर्म सबमिशन सरल होगा इसलिए मैंने Google स्प्रेडशीट बनाई और इसका एक फॉर्म बनाया। मैंने सोचा कि मैं एंड्रॉइड ऐप को फॉर्म पर इंगित करूंगा और फिर बाद में देखने के लिए स्प्रेडशीट में सभी डेटा होगा। हालांकि एंड्रॉइड ऐप वास्तव में फॉर्म भरने के लिए नहीं मिल सकता है। यहां संसाधन हैं।
private void submitVote(String outcome) {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("https://spreadsheets.google.com/spreadsheet/formResponse?hl=en_US&formkey=dDlwZzh4bGFvNFBxUmRsR0d2VTVhYnc6MQ&ifq");
List<BasicNameValuePair> results = new ArrayList<BasicNameValuePair>();
results.add(new BasicNameValuePair("entry.0.single", cardOneURL));
results.add(new BasicNameValuePair("entry.1.single", outcome));
results.add(new BasicNameValuePair("entry.2.single", cardTwoURL));
try {
post.setEntity(new UrlEncodedFormEntity(results));
} catch (UnsupportedEncodingException e) {
// Auto-generated catch block
Log.e("YOUR_TAG", "An error has occurred", e);
}
try {
client.execute(post);
} catch (ClientProtocolException e) {
// Auto-generated catch block
Log.e("YOUR_TAG", "An error has occurred", e);
} catch (IOException e) {
// Auto-generated catch block
Log.e("YOUR_TAG", "An error has occurred", e);
}
}
मैं दोनों फार्म और स्प्रेडशीट सार्वजनिक तो यह के साथ चारों ओर गंदगी के लिए स्वतंत्र महसूस और कोशिश करते हैं और यह अपने आप को काम करने के लिए मिलता है बनाया है।
मुझे अपने प्रोग्राम से कोई त्रुटि नहीं है, कोई संकलन त्रुटियां नहीं हैं, डीडीएमएस में कोई त्रुटि नहीं है। जब मैं वास्तव में प्रोग्राम चलाता हूं और इस कोड को निष्पादित करने वाले बटन पर क्लिक करता हूं तो मैं देरी देख सकता हूं क्योंकि यह अभी यूआई थ्रेड में है, इसलिए मुझे पता है कि यह इसे निष्पादित कर रहा है। ऐसा प्रतीत होता है जैसे सबकुछ पूरी तरह से काम कर रहा है, लेकिन मेरी स्प्रेडशीट बिल्कुल अपडेट नहीं होती है।
कोई विचार? मुझे यकीन है कि यह कुछ बेवकूफ है कि मैं याद कर रहा हूं, लेकिन किसी भी मदद की सराहना की जाएगी।
यहां लॉगिंग और डिबगिंग सामग्री के साथ अद्यतन कोड है।
private void submitVote(String outcome) {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("https://spreadsheets.google.com/spreadsheet/formResponse?hl=en_US&formkey=dDlwZzh4bGFvNFBxUmRsR0d2VTVhYnc6MQ&ifq");
List<BasicNameValuePair> results = new ArrayList<BasicNameValuePair>();
results.add(new BasicNameValuePair("entry.0.single", cardOneURL));
results.add(new BasicNameValuePair("entry.1.single", outcome));
results.add(new BasicNameValuePair("entry.2.single", cardTwoURL));
try {
post.setEntity(new UrlEncodedFormEntity(results));
} catch (UnsupportedEncodingException e) {
// Auto-generated catch block
Log.e("YOUR_TAG", "An error has occurred", e);
}
try {
HttpResponse httpResponse = client.execute(post);
Log.e("RESPONSE", "info: " + httpResponse);
BufferedReader rd = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));
String line;
while ((line = rd.readLine()) != null) {
Log.i("words", line);
}
Intent intent = new Intent(this, ReadingView.class);
intent.putExtra("html", line);
startActivity(intent);
} catch (ClientProtocolException e) {
// Auto-generated catch block
Log.e("YOUR_TAG", "client protocol exception", e);
} catch (IOException e) {
// Auto-generated catch block
Log.e("YOUR_TAG", "io exception", e);
}
}
मैं अपने अनुप्रयोग में कुछ और के लिए ReadingView.class उपयोग करें, लेकिन यह प्रवेश प्रयोजन के लिए यह अभी अपहरण कर लिया। इसमें केवल ऑनक्रेट() विधि है, जो नीचे है।
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.readingview);
WebView mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
//mWebView.loadUrl(getIntent().getExtras().getString("url"));
mWebView.loadData(getIntent().getExtras().getString("html"), "text/html", "utf-8");
}
यह भी ध्यान देने योग्य है कि डीडीएमएस में यह केवल लाइन के एक आउटपुट को लॉग करता है। मेरा मानना है कि यह इसलिए है क्योंकि एचटीएमएल कोड सभी को एक पंक्ति के रूप में वापस कर दिया जाता है। यदि मैं गलत हूं तो मुझे सही करों।
यह एक अच्छा लेख है जो आपके लिए उपयोगी हो सकता है। http://www.morningcopy.com.au/tutorials/how-to-style-google-forms/ – JackyBoi