Я пытаюсь разработать простое андроид-приложение для просмотра сообщения от Mysql db в уведомлении. Мой вопрос: хочу ли я получать информацию из БД каждые 2 минуты или проверить, были ли какие-либо новые данные опубликованы в БД, как я могу это сделать?сделано в андроиде?Я несколько раз перевожу с этим кодом, но в результате всегда получаю изображение «1001» * Frem explorer с android Примечание. База данных работает в классе sev_data:
public class sev_data extends IntentService {
public static boolean ServiceIsRun = false;
public sev_data() {
super("MyWebRequestService");
}
@Override
protected void onHandleIntent(@Nullable Intent intent) {
while (ServiceIsRun) {
int id_s=0;
String url0 = ""http://172.17.100.2/sendapp.php?co>"+id_s;
String msg;
try {
URL url = new URL(url0);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
msg = Stream2String(in);
in.close();
JSONObject jsonRootObject = new JSONObject(msg);
JSONArray jsonArray = jsonRootObject.optJSONArray("date");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String id= jsonObject.optString("id");
String title = jsonObject.optString("title");
String mess = jsonObject.optString("mess");
}
// creat new intent
intent = new Intent();
//set the action that will receive our broadcast
intent.setAction("com.example.Broadcast");
// add data to the bundle
intent.putExtra("msg", msg);
// send the data to broadcast
sendBroadcast(intent);
//delay for 50000ms
} catch (Exception e) {
}
try{
Thread.sleep(20000);
}catch (Exception ex){}
}
}
String date="";
public String Stream2String(InputStream inputStream) {
BufferedReader bureader=new BufferedReader( new InputStreamReader(inputStream));
String line ;
String Text="";
try{
while((line=bureader.readLine())!=null) {
Text+=line;
}
inputStream.close();
}catch (Exception ex){}
return Text;
}
}
sendapp.php:
<?php
$hostname_mus_db = "localhost";
$database_mus_db = "musdb2";
$username_mus_db = "root";
$password_mus_db = "";
$tf=@mysql_connect($hostname_mus_db,$username_mus_db,$password_mus_db);
if(!$tf)
die('Connection problem1 ..');
$tf_db=mysql_select_db($database_mus_db);
if(!$tf_db)
{
@mysql_close($tf_handle);
die('selection problem2 ..');
}
$co_array=array();
if (isset($_GET['co'])) {
$co=$_GET['co'];
$sql = mysql_query("SELECT * FROM mha1 where id>".$co);
while($row = mysql_fetch_assoc($sql)){
$co_array[]=$row;
}
}
header('Content-Type:application/json');
echo json_encode(array("date"=>$co_array));
?>