如何使通过互联网同步为Android的应用程序 [英] How to make an app that syncs via internet for Android
问题描述
我需要一点帮助,易于理解的方式表述。我试着问在多个论坛这个问题,但是一直得到的答案是回假设即使我指定我在建筑的Android和Java只有基本的技能知识。
用户天网是非常有益的,当我问我的最初的问题在这里,但研究的他/她促使我做证明难以跟进。
如何使通过互联网 <同步一个应用程序/ p>
我想要与通过网络更新,每次用户打开应用程序TextView中的应用程序。
什么是做到这一点的最好方法是什么?而我必须做的去做呢?
感谢你在前进!
要得到我该怎么新来这是一个想法,这里是我所发布的应用:的 https://play.google.com/store/apps/details?id=theveshtheva.debatebreaker
编辑:我想的东西,但它似乎并没有工作。有人能告诉我什么,我做错了吗?
我想从中提取数据的网页是在这里:
http://ktjdaily.blogspot.com/2015/02/menu-of -day.html
下面是我的活动的Java文件:
包theveshtheva.practice;\r
\r
进口android.support.v7.app.ActionBarActivity;\r
进口android.os.Bundle;\r
进口android.view.Menu;\r
进口android.view.MenuItem;\r
\r
进口java.io.BufferedReader中;\r
进口java.io.IOException异常;\r
进口java.io.InputStreamReader中;\r
进口android.widget.TextView;\r
\r
进口org.apache.http.Htt presponse;\r
进口org.apache.http.client.HttpClient;\r
进口org.apache.http.client.methods.HttpGet;\r
进口org.apache.http.impl.client.DefaultHttpClient;\r
进口org.apache.http.protocol.BasicHttpContext;\r
进口org.apache.http.protocol.HttpContext;\r
\r
\r
公共类onlinetext扩展ActionBarActivity {\r
\r
\r
私人字符串HTML;\r
\r
@覆盖\r
公共无效的onCreate(捆绑savedInstanceState){\r
super.onCreate(savedInstanceState);\r
的setContentView(R.layout.activity_onlinetext);\r
\r
/*从这里*/\r
TextView的输出文本=(的TextView)findViewById(R.id.textView);\r
\r
尝试{\r
getHTML();\r
}赶上(例外五){\r
e.printStackTrace();\r
}\r
outtext.setText(+ HTML);\r
/*到这里*/\r
}\r
\r
私人无效getHTML()抛出IOException异常\r
\r
{\r
HttpClient的HttpClient的=新DefaultHttpClient();\r
HttpContext的localContext =新BasicHttpContext();\r
HTTPGET HTTPGET =新HTTPGET(http://ktjdaily.blogspot.com/2015/02/menu-of-day.html); // URL!\r
HTT presponse响应= httpClient.execute(HTTPGET,localContext);\r
字符串结果=;\r
\r
读者的BufferedReader =新的BufferedReader(新的InputStreamReader(response.getEntity()的getContent()));\r
\r
串线;\r
而((行= reader.readLine())!= NULL){\r
结果+ =行+\\ n;\r
HTML =结果;\r
}\r
\r
}\r
\r
@覆盖\r
公共布尔onCreateOptionsMenu(菜单菜单){\r
//充气菜单;如果是present这增加了项目操作栏。\r
。getMenuInflater()膨胀(R.menu.menu_onlinetext,菜单);\r
返回true;\r
}\r
\r
@覆盖\r
公共布尔onOptionsItemSelected(菜单项项){\r
//处理动作栏项目点击这里。操作栏会\r
//自动处理上点击主页/向上按钮,只要\r
//你在AndroidManifest.xml中指定一个父活动。\r
INT ID = item.getItemId();\r
\r
// noinspection SimplifiableIfStatement\r
如果(ID == R.id.action_settings){\r
返回true;\r
}\r
\r
返回super.onOptionsItemSelected(项目);\r
}\r
}
\r
和这里的清单文件,在这里我设置权限:
&LT;?XML版本=1.0编码=UTF-8? &GT;\r
&LT;清单的xmlns:机器人=http://schemas.android.com/apk/res/android包=theveshtheva.practice&GT;\r
\r
&LT;使用许可权的android:NAME =android.permission.INTERNET对/&GT;\r
\r
&lt;应用机器人:allowBackup =真正的机器人:图标=@绘制/ ic_launcher机器人:标签=@字符串/ APP_NAME机器人:主题=@风格/ AppTheme&GT;\r
&LT;活动机器人:名字=机器人onlinetext:标签=@字符串/ APP_NAME&GT;\r
&所述;意图滤光器&gt;\r
&lt;作用机器人:名字=android.intent.action.MAIN/&GT;\r
\r
&LT;类机器人:名字=android.intent.category.LAUNCHER/&GT;\r
&所述; /意图滤光器&gt;\r
&LT; /活性GT;\r
&LT; /用途&gt;\r
\r
&LT; /清单&GT;
\r
你要更新什么:布局或内容?你知道如何连接到一个网站,使一个GET请求?
I need a bit of help phrased in easy to understand terms. I've tried asking this question on multiple forums, but keep getting answers back that assume some knowledge even though I specified that I have only rudimentary skills in Android building and Java.
The user Skynet was very helpful when I asked my initial question here, but the research he/she prompted me to do proved difficult to follow up on. How to make an app that syncs via internet
I want to make an app with a textview that updates via internet everytime the user open the app.
What is the best way to do this? And what would I have to do to do it?
Thank you in advance!
To get an idea of how new to this I am, here's an app I've published: https://play.google.com/store/apps/details?id=theveshtheva.debatebreaker
EDIT: I'm trying something but it doesn't seem to work. Could someone tell me what I'm doing wrong?
The webpage I'm trying to pull data from is here: http://ktjdaily.blogspot.com/2015/02/menu-of-day.html
Here's my activity java file:
package theveshtheva.practice;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import android.widget.TextView;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
public class onlinetext extends ActionBarActivity {
private String HTML;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_onlinetext);
/*FROM HERE*/
TextView outtext = (TextView) findViewById(R.id.textView);
try {
getHTML();
} catch (Exception e) {
e.printStackTrace();
}
outtext.setText("" + HTML);
/*TO HERE*/
}
private void getHTML() throws IOException
{
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet("http://ktjdaily.blogspot.com/2015/02/menu-of-day.html"); //URL!
HttpResponse response = httpClient.execute(httpGet, localContext);
String result = "";
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line;
while ((line = reader.readLine()) != null) {
result += line + "\n";
HTML = result;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_onlinetext, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
And here's the Manifest file, where I've set permissions:
<?xml version="1.0" encoding="utf-8" ?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="theveshtheva.practice">
<uses-permission android:name="android.permission.INTERNET" />
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme">
<activity android:name=".onlinetext" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
What do you want to update: layout or content? Do you know how to connect to a site and make a get request?
这篇关于如何使通过互联网同步为Android的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!