fork download
  1. package info.androidhive.smsverification.service;
  2.  
  3. import android.app.IntentService;
  4. import android.content.Intent;
  5. import android.util.Log;
  6. import android.widget.Toast;
  7.  
  8. import com.android.volley.Request;
  9. import com.android.volley.Response;
  10. import com.android.volley.VolleyError;
  11. import com.android.volley.toolbox.StringRequest;
  12.  
  13. import org.json.JSONException;
  14. import org.json.JSONObject;
  15.  
  16. import java.util.HashMap;
  17. import java.util.Map;
  18.  
  19. import info.androidhive.smsverification.activity.MainActivity;
  20. import info.androidhive.smsverification.app.Config;
  21. import info.androidhive.smsverification.app.MyApplication;
  22. import info.androidhive.smsverification.helper.PrefManager;
  23.  
  24. /**
  25.  * Created by Ravi on 04/04/15.
  26.  */
  27. public class HttpService extends IntentService {
  28.  
  29. private static String TAG = HttpService.class.getSimpleName();
  30.  
  31. public HttpService() {
  32. super(HttpService.class.getSimpleName());
  33. }
  34.  
  35. @Override
  36. protected void onHandleIntent(Intent intent) {
  37. if (intent != null) {
  38. String otp = intent.getStringExtra("otp");
  39. verifyOtp(otp);
  40. }
  41. }
  42.  
  43. /**
  44.   * Posting the OTP to server and activating the user
  45.   *
  46.   * @param otp otp received in the SMS
  47.   */
  48. private void verifyOtp(final String otp) {
  49. StringRequest strReq = new StringRequest(Request.Method.POST,
  50. Config.URL_VERIFY_OTP, new Response.Listener<String>() {
  51.  
  52. @Override
  53. public void onResponse(String response) {
  54. Log.d(TAG, response.toString());
  55.  
  56. try {
  57.  
  58. JSONObject responseObj = new JSONObject(response);
  59.  
  60. // Parsing json object response
  61. // response will be a json object
  62. boolean error = responseObj.getBoolean("error");
  63. String message = responseObj.getString("message");
  64.  
  65. if (!error) {
  66. // parsing the user profile information
  67. JSONObject profileObj = responseObj.getJSONObject("profile");
  68.  
  69. String name = profileObj.getString("name");
  70. String email = profileObj.getString("email");
  71. String mobile = profileObj.getString("mobile");
  72.  
  73. PrefManager pref = new PrefManager(getApplicationContext());
  74. pref.createLogin(name, email, mobile);
  75.  
  76. Intent intent = new Intent(HttpService.this, MainActivity.class);
  77. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  78. startActivity(intent);
  79.  
  80. Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
  81.  
  82. } else {
  83. Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
  84. }
  85.  
  86. } catch (JSONException e) {
  87. Toast.makeText(getApplicationContext(),
  88. "Error: " + e.getMessage(),
  89. Toast.LENGTH_LONG).show();
  90. }
  91.  
  92. }
  93. }, new Response.ErrorListener() {
  94.  
  95. @Override
  96. public void onErrorResponse(VolleyError error) {
  97. Log.e(TAG, "Error: " + error.getMessage());
  98. Toast.makeText(getApplicationContext(),
  99. error.getMessage(), Toast.LENGTH_SHORT).show();
  100. }
  101. }) {
  102.  
  103. @Override
  104. protected Map<String, String> getParams() {
  105. Map<String, String> params = new HashMap<String, String>();
  106. params.put("otp", otp);
  107.  
  108. Log.e(TAG, "Posting params: " + params.toString());
  109. return params;
  110. }
  111.  
  112. };
  113.  
  114. // Adding request to request queue
  115. MyApplication.getInstance().addToRequestQueue(strReq);
  116. }
  117.  
  118.  
  119. }
  120.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:27: error: class HttpService is public, should be declared in a file named HttpService.java
public class HttpService extends IntentService {
       ^
Main.java:3: error: package android.app does not exist
import android.app.IntentService;
                  ^
Main.java:4: error: package android.content does not exist
import android.content.Intent;
                      ^
Main.java:5: error: package android.util does not exist
import android.util.Log;
                   ^
Main.java:6: error: package android.widget does not exist
import android.widget.Toast;
                     ^
Main.java:8: error: package com.android.volley does not exist
import com.android.volley.Request;
                         ^
Main.java:9: error: package com.android.volley does not exist
import com.android.volley.Response;
                         ^
Main.java:10: error: package com.android.volley does not exist
import com.android.volley.VolleyError;
                         ^
Main.java:11: error: package com.android.volley.toolbox does not exist
import com.android.volley.toolbox.StringRequest;
                                 ^
Main.java:13: error: package org.json does not exist
import org.json.JSONException;
               ^
Main.java:14: error: package org.json does not exist
import org.json.JSONObject;
               ^
Main.java:19: error: package info.androidhive.smsverification.activity does not exist
import info.androidhive.smsverification.activity.MainActivity;
                                                ^
Main.java:20: error: package info.androidhive.smsverification.app does not exist
import info.androidhive.smsverification.app.Config;
                                           ^
Main.java:21: error: package info.androidhive.smsverification.app does not exist
import info.androidhive.smsverification.app.MyApplication;
                                           ^
Main.java:22: error: package info.androidhive.smsverification.helper does not exist
import info.androidhive.smsverification.helper.PrefManager;
                                              ^
Main.java:27: error: cannot find symbol
public class HttpService extends IntentService {
                                 ^
  symbol: class IntentService
Main.java:36: error: cannot find symbol
    protected void onHandleIntent(Intent intent) {
                                  ^
  symbol:   class Intent
  location: class HttpService
Main.java:35: error: method does not override or implement a method from a supertype
    @Override
    ^
Main.java:49: error: cannot find symbol
        StringRequest strReq = new StringRequest(Request.Method.POST,
        ^
  symbol:   class StringRequest
  location: class HttpService
Main.java:49: error: cannot find symbol
        StringRequest strReq = new StringRequest(Request.Method.POST,
                                   ^
  symbol:   class StringRequest
  location: class HttpService
Main.java:49: error: package Request does not exist
        StringRequest strReq = new StringRequest(Request.Method.POST,
                                                        ^
Main.java:50: error: cannot find symbol
                Config.URL_VERIFY_OTP, new Response.Listener<String>() {
                ^
  symbol:   variable Config
  location: class HttpService
Main.java:50: error: package Response does not exist
                Config.URL_VERIFY_OTP, new Response.Listener<String>() {
                                                   ^
Main.java:93: error: package Response does not exist
        }, new Response.ErrorListener() {
                       ^
Main.java:115: error: cannot find symbol
        MyApplication.getInstance().addToRequestQueue(strReq);
        ^
  symbol:   variable MyApplication
  location: class HttpService
25 errors
stdout
Standard output is empty