2017-02-04 7 views
0

私は内部使用のための簡単なアンドロイドアプリを構築しました。このアプリは、単純なPHPスクリプトを介してmysqlに保存する数秒ごとにデータ(GPS座標)を送信します。 jsonからの特定の応答がある場合、プリセット通知を表示するには、ユーザーのAndroidデバイスが必要です(電話機がスタンバイ状態の場合は表示され、別のアプリケーションなどは表示されます)。json/phpを使用したAndroidスタジオの簡単な通知

私が見たチュートリアルのほとんどは、GCMを使用してこれを行うことをお勧めします。私は思っていただろう、 '自己押された'通知はこれより簡単にすべきである。

jsonが「notify:1」と応答すると、アンドロイド通知で「待機中のジョブがあります」と表示されます。

これを行う簡単な方法はありますか?もしそうなら、私を簡単な解決に導いてください。

new HttpRequestTask(
       new HttpRequest("https://www.autoflora.net/driver/gps.php?Driver_ID=" + driver_id + "&latlong=" + 
         location.getLatitude() + "*" + location.getLongitude(), HttpRequest.POST, "{ \"some\": \"data\" }"), 
       new HttpRequest.Handler() { 
        @Override 
        public void response(HttpResponse response) { 
         if (response.code == 200) { 
          Log.d(this.getClass().toString(), "Request successful!"); 
         } else { 
          Log.e(this.getClass().toString(), "Request unsuccessful: " + response); 
         } 
        } 
       }).execute(); 

答えて

0

httpresponseからレスポンス本文を取得したら、 は、例えば

... 
JSON response = new JSON(responseBody); //responseBody is what you received from server 

if(response.has("notify") && (response.getInt("notify") == 1)) 
{ 
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context); 
    notificationBuilder.setContentTitle(title); //Set notification title 
    notificationBuilder.setContentText(message); // set notification text 

    NotificationManager notificationManager = 
      (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

    notificationManager.notify(0 /* ID of notification */, 
    notificationBuilder.build()); 

} 
... 

希望、それからJSONオブジェクトを作成し、これは

に役立ちます
関連する問題