Php 在android中在MySQL中插入新数据时显示通知

Php 在android中在MySQL中插入新数据时显示通知,php,android,mysql,push-notification,Php,Android,Mysql,Push Notification,我试着 在通知中从Mysql db开发了一个简单的android应用程序视图消息 我的问题是,如果我想每隔2分钟从数据库中获取信息,或者检查是否有任何新数据已发布到数据库中,我如何在android中实现这一点? 我用这段代码拖了好几次托盘,但结果总是显示nothing Click图像 注意:数据库正在运行 sev_数据类: public class sev_data extends IntentService { public static boolean ServiceIsRun = fa

我试着 在通知中从Mysql db开发了一个简单的android应用程序视图消息 我的问题是,如果我想每隔2分钟从数据库中获取信息,或者检查是否有任何新数据已发布到数据库中,我如何在android中实现这一点? 我用这段代码拖了好几次托盘,但结果总是显示nothing Click图像 注意:数据库正在运行 sev_数据类:

  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;
}
公共类服务数据扩展IntentService{
公共静态布尔服务运行=false;
公共服务数据(){
超级(“MyWebRequestService”);
}
@凌驾
受保护的无效onHandleIntent(@Nullable Intent){
while(ServiceIsRun){
int id_s=0;
字符串url0=“”http://172.17.100.2/sendapp.php?co>“+id_s;
串味精;
试一试{
URL=新URL(url0);
HttpURLConnection urlConnection=(HttpURLConnection)url.openConnection();
InputStream in=new BufferedInputStream(urlConnection.getInputStream());
msg=Stream2String(in);
in.close();
JSONObject jsonRootObject=新的JSONObject(msg);
JSONArray JSONArray=jsonRootObject.optJSONArray(“日期”);
for(int i=0;i
}

sendapp.php:


我认为您的查询从未执行过,因为您的url格式不正确(您将而不是=),因此从未设置$\u GET['co'],请尝试替换

String url0 = ""http://172.17.100.2/sendapp.php?co>"+id_s;


在你的代码中加入两个
Log.e()
,看看问题出现在哪里。现在,替换后的应用程序会显示所有(id、用户名、图像、电子邮件)在id1、id2、id3等行中,我只想显示数据库中最后一个ID中的名称谢谢你的帮助,因此你必须将查询更改为
从mha1中选择名称,其中ID>
,然后将此值仅放在json数组或ObjectU是否可以编辑我的代码以显示来自最后一个ID而不是所有ID的名称php结果是什么Php结果是“日期”
String url0 = "http://172.17.100.2/sendapp.php?co="+id_s;