0

私はphpを持っています..誰かがwebviewによって私のアプリケーションにログインします。Android アプリケーションは、5 秒ごとにwww.website.com/notification.phpをチェックする必要があります。

 if notification php ==> echo 1 ; .. show notification.
 if notification php ==> echo 0 ; .. dont do anything..

Androidで0または1の値を確認したい..

4

1 に答える 1

0

AsynchTask、専用thread、またはでネットワーク コードを実行する必要があります。コードIntentService例を次に示します。

Thread networkThread = new Thread() {
   public void run() {
        HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet("http://www.website.com/notification.php");
        HttpResponse response = httpclient.execute(httppost);
        String result = EntityUtils.toString(httpresponse.getEntity());

        if("1".equals(result.trim()){
            showNotification(); // You have to implement this
        }
    }
}
networkThread.start();

5 秒ごとにネットワーク要求を行うと、GSM/3G が常にアクティブなままになるため、バッテリーが急速に消耗することに注意してください。

于 2013-02-25T03:29:41.000 に答える