Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.weltintegra;
- import android.app.Activity;
- import android.content.Context;
- import android.content.Intent;
- import android.location.Location;
- import android.location.LocationListener;
- import android.location.LocationManager;
- import android.net.Uri;
- import android.net.wifi.WifiInfo;
- import android.net.wifi.WifiManager;
- import android.os.Bundle;
- import android.telephony.TelephonyManager;
- import android.util.Log;
- import android.view.View;
- import com.google.android.gcm.GCMRegistrar;
- import com.google.android.maps.GeoPoint;
- import org.apache.http.client.HttpClient;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.impl.client.DefaultHttpClient;
- import java.security.MessageDigest;
- import java.util.UUID;
- public class home extends Activity {
- private LocationManager locationManager;
- public GeoPoint myLoc;
- public Double lat1;
- public Double lng1;
- protected static String deviceID;
- private String api_token = "b431e1f3aeda13305c155f8d26791f86";
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setLocationManager((LocationManager) getSystemService(Context.LOCATION_SERVICE));
- LocationManager locationManager = (LocationManager) this
- .getSystemService(Context.LOCATION_SERVICE);
- // Define a listener that responds to location updates
- LocationListener locationListener = new LocationListener() {
- public void onLocationChanged(Location location) {
- // Called when a new location is found by the network location
- // provider.
- lng1 = location.getLongitude();
- lat1 = location.getLatitude();
- }
- public void onStatusChanged(String provider, int status,
- Bundle extras) {
- Log.i("geo", "ok");
- }
- public void onProviderEnabled(String provider) {
- }
- public void onProviderDisabled(String provider) {
- }
- };
- // Register the listener with the Location Manager to receive location
- // updates
- locationManager.requestLocationUpdates(
- LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
- setContentView(R.layout.home);
- try {
- deviceID = getDeviceId(this.getBaseContext());
- } catch (Exception e) {
- e.printStackTrace(); // To change body of catch statement use File |
- // Settings | File Templates.
- }
- GCMRegistrar.checkDevice(this);
- GCMRegistrar.checkManifest(this);
- final String regId = GCMRegistrar.getRegistrationId(this);
- if (regId.equals("")) {
- GCMRegistrar.register(this, "181872115906");
- } else {
- HttpClient httpclient = new DefaultHttpClient();
- HttpPost httppost = new HttpPost(
- "http://apn.weltint.com/userdb/registerandroid/"
- + api_token + "/" + regId + "/" + deviceID);
- try {
- httpclient.execute(httppost);
- } catch (Exception ex) {
- }
- }
- }
- public void goToQr(View view) {
- Intent intent = new Intent(getParent(), rootqr.class);
- startActivity(intent);
- }
- public void shareit(View view) {
- final Intent emailIntent = new Intent(
- android.content.Intent.ACTION_SEND);
- emailIntent.setType("plain/text");
- // /emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new
- // String[]{"[email protected]"});
- emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Try "
- + getString(R.string.app_name));
- emailIntent
- .putExtra(
- android.content.Intent.EXTRA_TEXT,
- "I love this app and would like to share with you. https://play.google.com/store/search?q="
- + getString(R.string.app_name) + "=apps");
- home.this.startActivity(Intent.createChooser(emailIntent,
- "Send mail..."));
- }
- public void callUs(View view) {
- Intent sIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"
- + getString(R.string.mainphone)));
- startActivity(sIntent);
- }
- public void ourPhisican(View view) {
- Intent intent = new Intent(getParent(), rootWeb.class);
- intent.putExtra("url", "file:///android_asset/our_phisican.html");
- startActivity(intent);
- }
- public void goDirection(View view) {
- // Log.i("GEO",lat1.toString());
- String coordinates[] = { getString(R.string.lat),
- getString(R.string.lon) };
- double lat = Double.parseDouble(coordinates[0]);
- double lng = Double.parseDouble(coordinates[1]);
- String url = "http://maps.google.com/maps?saddr=" + lat1.toString()
- + "," + lng1.toString() + "&daddr=" + lat + "," + lng;
- Intent i = new Intent(Intent.ACTION_VIEW);
- i.setData(Uri.parse(url));
- startActivity(i);
- }
- protected static String getDeviceId(Context context) throws Exception {
- String imei = getImei(context);
- if (imei != null)
- return imei;
- String tid = getWifiMacAddress(context);
- return tid;
- }
- protected static String getImei(Context context) {
- TelephonyManager m = (TelephonyManager) context
- .getSystemService(Context.TELEPHONY_SERVICE);
- String imei = m != null ? m.getDeviceId() : null;
- return imei;
- }
- protected static String getWifiMacAddress(Context context) throws Exception {
- WifiManager manager = (WifiManager) context
- .getSystemService(Context.WIFI_SERVICE);
- WifiInfo wifiInfo = manager.getConnectionInfo();
- if (wifiInfo == null || wifiInfo.getMacAddress() == null)
- return md5(UUID.randomUUID().toString());
- else
- return wifiInfo.getMacAddress().replace(":", "").replace(".", "");
- }
- public void goToAppointment(View view) {
- Intent intent = new Intent(getParent(), rootAppointment.class);
- startActivity(intent);
- }
- public void goToMb(View view) {
- Intent intent = new Intent(getParent(), rootmb.class);
- startActivity(intent);
- }
- protected static String md5(String s) throws Exception {
- MessageDigest md = MessageDigest.getInstance("MD5");
- md.update(s.getBytes());
- byte digest[] = md.digest();
- StringBuffer result = new StringBuffer();
- for (int i = 0; i < digest.length; i++) {
- result.append(Integer.toHexString(0xFF & digest[i]));
- }
- return (result.toString());
- }
- public void setLocationManager(LocationManager locationManager) {
- this.locationManager = locationManager;
- }
- public LocationManager getLocationManager() {
- return locationManager;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment