Ejemplo n.º 1
0
 @Override
 protected Void doInBackground(Void... params) {
   try {
     DefaultHttpClient httpclient = new DefaultHttpClient();
     String reqURL = Constants.BASE_URL + Constants.MESSAGE_COUNT;
     HttpPost httpPost = new HttpPost(reqURL);
     String json = "";
     JSONObject reqparams = new JSONObject();
     reqparams.accumulate("appId", "1966477342111");
     reqparams.accumulate("secret", Constants.secret);
     reqparams.accumulate("access_token", AppController.getToken(AfterLoginActivity.this));
     reqparams.accumulate("device_id", AppController.getRegistrationId(AfterLoginActivity.this));
     reqparams.accumulate("os_type", "android");
     json = reqparams.toString();
     StringEntity se = new StringEntity(json);
     httpPost.setEntity(se);
     httpPost.setHeader("Accept", "application/json");
     httpPost.setHeader("Content-type", "application/json");
     HttpResponse httpResponse = httpclient.execute(httpPost);
     inputStream = httpResponse.getEntity().getContent();
     if (inputStream != null) result = AppController.convertInputStreamToString(inputStream);
     else result = "Did not work!";
   } catch (Exception e) {
     Log.d("InputStream", e.getLocalizedMessage());
   }
   try {
     JSONObject object = new JSONObject(result);
     JSONArray array = object.getJSONArray("data");
     message_count = array.length();
     runOnUiThread(
         new Runnable() {
           @Override
           public void run() {
             actionBarMessagesTV.setText(String.valueOf(message_count));
             Log.v("XXXXXXXXXXXX", "data sayısını bastı");
           }
         });
   } catch (JSONException e) {
     e.printStackTrace();
     runOnUiThread(
         new Runnable() {
           @Override
           public void run() {
             actionBarMessagesTV.setText("0");
             Log.v("XXXXXXXXXXXX", "data sayısını basamaıd");
           }
         });
   }
   return null;
 }
Ejemplo n.º 2
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);
   String token = AppController.getToken(this);
   if (!token.isEmpty()) {
     if (getIntent().hasExtra("reDirectUrl")) {
       Intent afterLoginActivity = new Intent(MainActivity.this, AfterLoginActivity.class);
       afterLoginActivity.putExtra(
           "reDirectUrl", getIntent().getExtras().getString("reDirectUrl"));
       startActivity(afterLoginActivity);
       finish();
     }
     Intent i = new Intent(this, AfterLoginActivity.class);
     startActivity(i);
     finish();
   }
   if (checkPlayServices()) {
     // If this check succeeds, proceed with normal processing.
     // Otherwise, prompt user to get valid Play Services APK.
     gcm = GoogleCloudMessaging.getInstance(this);
     regid = AppController.getRegistrationId(MainActivity.this);
     if (regid.isEmpty()) {
       registerInBackground();
     }
     LandingFragment landingFragment = LandingFragment.newInstance();
     android.support.v4.app.FragmentTransaction fragmentTransaction =
         getSupportFragmentManager().beginTransaction();
     fragmentTransaction.replace(R.id.activityMainFragmentContainer, landingFragment);
     fragmentTransaction.commit();
   } else {
     AlertDialog.Builder builder = new AlertDialog.Builder(this);
     builder.setTitle("Error");
     builder.setMessage(
         "You can not use this application without Google Play Service. Please get Google Play Services to use Hobtime Application");
     builder.setPositiveButton(
         "OK",
         new DialogInterface.OnClickListener() {
           @Override
           public void onClick(DialogInterface dialog, int which) {
             finish();
           }
         });
     AlertDialog dialog = builder.create();
     dialog.show();
   }
 }