예제 #1
0
        public String ObterIMEI()
        {
            TelephonyManager telephonyManager = (TelephonyManager)Android.App.Application.Context.GetSystemService(Context.TelephonyService);
            String           imei             = telephonyManager.DeviceId;

            return(imei);
        }
예제 #2
0
 private void Dispose(bool disposing)
 {
     if (null != m_TelephonyManager)
     {
         m_TelephonyManager = null;
     }
 }
예제 #3
0
        /// <summary>
        /// 判断网络是否是4G
        /// <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
        /// </summary>
        /// <param name="context">上下文</param>
        /// <returns></returns>
        public static bool Is4G(Context context)
        {
            var info = GetActiveNetworkInfo(context);
            var tm   = TelephonyManager.FromContext(context);

            return(info != null && info.IsAvailable && tm.NetworkType == NetworkType.Lte);
        }
예제 #4
0
        private bool desactiveSon = true; //permet de savoir si le tel est en silencieux, s'il est en silencieux, il ne faut pas  le remettre en normal

        public override void OnReceive(Context context, Intent intent)
        {
            short idList = 0;

            if (intent.Action == CALL_RECEIVER)
            {
                if (intent.GetStringExtra(TelephonyManager.ExtraState).Equals(TelephonyManager.ExtraStateRinging))
                {
                    string number = intent.GetStringExtra(TelephonyManager.ExtraIncomingNumber);
                    if (Global.Instance.SearchPhoneNumber(number, out idList, context))
                    {
                        execute(context, number, idList);

                        TelephonyManager mng           = (TelephonyManager)(context.GetSystemService(Context.TelephonyService));
                        IntPtr           iTelephonyPtr = JNIEnv.GetMethodID(mng.Class.Handle, "getITelephony", "()Lcom/android/internal/telephony/ITelephony;");

                        IntPtr telephony         = JNIEnv.CallObjectMethod(mng.Handle, iTelephonyPtr);
                        IntPtr iTelephonyClass   = JNIEnv.GetObjectClass(telephony);
                        IntPtr iTelephonyEndCall = JNIEnv.GetMethodID(iTelephonyClass, "endCall", "()Z");
                        JNIEnv.CallBooleanMethod(telephony, iTelephonyEndCall);
                        JNIEnv.DeleteLocalRef(telephony);
                        JNIEnv.DeleteLocalRef(iTelephonyClass);
                    }
                }
            }
            else if (intent.Action == SMS_RECEIVER)
            {
                SmsMessage[] msgs = Telephony.Sms.Intents.GetMessagesFromIntent(intent);
                Log.Info("info", "number = " + msgs[0].OriginatingAddress);
                if (Global.Instance.SearchPhoneNumber(msgs[0].OriginatingAddress, out idList, context))
                {
                    execute(context, msgs[0].OriginatingAddress, idList);
                }
            }
        }
예제 #5
0
        public static string getIMEI(Context context)
        {
            TelephonyManager telephonyManager = (TelephonyManager)context.GetSystemService(Context.TelephonyService);
            string           IMEI             = telephonyManager.DeviceId;

            return(IMEI);
        }
예제 #6
0
        public static string GetDeviceInfo(Context context)
        {
            try
            {
                JSONObject       json      = new JSONObject();
                TelephonyManager tm        = (TelephonyManager)context.GetSystemService(Context.TelephonyService);
                string           device_id = tm.DeviceId;
                WifiManager      wifi      = (WifiManager)context.GetSystemService(Context.WifiService);
                string           mac       = wifi.ConnectionInfo.MacAddress;
                json.Put("mac", mac);

                if (TextUtils.IsEmpty(device_id))
                {
                    device_id = mac;
                }

                if (TextUtils.IsEmpty(device_id))
                {
                    device_id = Android.Provider.Settings.Secure.GetString(context.ContentResolver, Android.Provider.Settings.Secure.AndroidId);
                }

                json.Put("device_id", device_id);

                return(json.ToString());
            }
            catch (Exception e)
            {
                //e.PrintStackTrace();
            }
            return(null);
        }
예제 #7
0
        /**
         * Check if there is fast connectivity
         * @param context
         * @return
         */
        public static bool IsConnectedFast(Context context)
        {
            NetworkInfo      info = Connectivity.GetNetworkInfo(context);
            TelephonyManager tm   = TelephonyManager.FromContext(context);

            return(info != null && info.IsConnected && Connectivity.IsConnectionFast(info.Type, tm.NetworkType));
        }
예제 #8
0
        protected override async Task InitializeAsync()
        {
            await base.InitializeAsync();

            if (await SensusServiceHelper.Get().ObtainPermissionAsync(Permission.Sms) == PermissionStatus.Granted)
            {
                _telephonyManager = Application.Context.GetSystemService(global::Android.Content.Context.TelephonyService) as TelephonyManager;

                if (_telephonyManager == null)
                {
                    throw new NotSupportedException("No telephony present.");
                }

                _smsOutgoingObserver.Initialize();
            }
            else
            {
                // throw standard exception instead of NotSupportedException, since the user might decide to enable SMS in the future
                // and we'd like the probe to be restarted at that time.
                string error = "SMS is not permitted on this device. Cannot start SMS probe.";
                await SensusServiceHelper.Get().FlashNotificationAsync(error);

                throw new Exception(error);
            }
        }
예제 #9
0
        private void Realese()
        {
            TelephonyManager tmgr = (TelephonyManager)this.GetSystemService(Service.TelephonyService);

            if (phone_state_listener != null)
            {
                tmgr.Listen(phone_state_listener, PhoneStateListenerFlags.None);
            }
            var shared_prefs = Global.GetSharedPreferences(this);

            shared_prefs.UnregisterOnSharedPreferenceChangeListener(this);

            //var audio_mngr = (AudioManager)GetSystemService(Context.AudioService);
            //AudioFocusRequest result = audio_mngr.AbandonAudioFocus(this);

            if (notification_timer != null)
            {
                notification_timer.Dispose();
                notification_timer = null;
            }
            NotificationManager n_mngr = (NotificationManager)GetSystemService(Service.NotificationService);

            n_mngr.CancelAll();
            Detecting = false;
            //if(_jdtmfController!=null)
            //    _jdtmfController.Dispose();
            initialized = false;
        }
예제 #10
0
 public static BaseShared With(Context context, string name)
 {
     if (TextUtils.IsEmpty(SecretKey))
     {
         lock (typeof(BaseShared))
         {
             if (TextUtils.IsEmpty(SecretKey))
             {
                 TelephonyManager tm = (TelephonyManager)context.GetSystemService(Context.TelephonyService);
                 SecretKey = tm.DeviceId;
             }
             if (TextUtils.IsEmpty(SecretKey))
             {
                 SecretKey = Settings.Secure.GetString(context.ContentResolver, Settings.Secure.AndroidId);
             }
             if (TextUtils.IsEmpty(SecretKey))
             {
                 SecretKey = Build.Serial;
             }
             if (TextUtils.IsEmpty(SecretKey))
             {
                 SecretKey = context.PackageName;
             }
         }
     }
     return(new BaseShared(context, name));
 }
예제 #11
0
        public void StopListening()
        {
            var AppContext = Android.App.Application.Context;
            TelephonyManager telephonyManager = (TelephonyManager)AppContext.GetSystemService(Context.TelephonyService);

            telephonyManager.Listen(PhoneActivityListener, PhoneStateListenerFlags.None);
        }
예제 #12
0
        public static bool IsIntentAvailable(Context context, Intent intent)
        {
            var pm = context.PackageManager;

            return(pm.QueryIntentServices(intent, 0).Union(pm.QueryIntentActivities(intent, 0)).Any() ||
                   TelephonyManager.FromContext(context).PhoneType != PhoneType.None);
        }
예제 #13
0
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            if (resultCode == Result.Ok)
            {
                var helloLabel               = data.GetStringExtra("greeting");
                var telephonyDeviceID        = string.Empty;
                var telephonySIMSerialNumber = string.Empty;
                TelephonyManager tManager    = (TelephonyManager)GetSystemService(Context.TelephonyService);

                if (tManager != null)
                {
                    if (!string.IsNullOrEmpty(tManager.DeviceId))
                    {
                        telephonyDeviceID = tManager.DeviceId;
                    }
                    if (!string.IsNullOrEmpty(tManager.SimSerialNumber))
                    {
                        telephonySIMSerialNumber = tManager.SimSerialNumber;
                    }
                }
                var androidID  = Android.Provider.Settings.Secure.GetString(ContentResolver, Android.Provider.Settings.Secure.AndroidId);
                var deviceUuid = new UUID(androidID.GetHashCode(), ((int)telephonyDeviceID.GetHashCode() << 32) | telephonySIMSerialNumber.GetHashCode());
                var deviceID   = deviceUuid.ToString();

                ISharedPreferences       prefs  = PreferenceManager.GetDefaultSharedPreferences(mContext);
                ISharedPreferencesEditor editor = prefs.Edit();
                editor.PutString("androidID", androidID);
                // editor.Commit();    // applies changes synchronously on older APIs
                editor.Apply();        // applies changes asynchronously on newer APIs
            }
        }
 private void eventCallAnswer(Dial newDial)
 {
     CallController.ProcessingAnswerCall(newDial);
     TelephonyManager.PushCommand(newDial.RemoteAddress,
                                  BeelineConnect.FindAbonentsBy(newDial.SubscriptionID).Key.UserName,
                                  newDial.TrackingId);
 }
예제 #15
0
        async void RequestPermissionAsync()
        {
            var status = await CrossPermissions.Current.CheckPermissionStatusAsync <PhonePermission>();

            if (status != PermissionStatus.Granted)
            {
                if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Phone))
                {
                    // has no permission
                }

                status = await CrossPermissions.Current.RequestPermissionAsync <PhonePermission>();
            }

            if (status == PermissionStatus.Granted)
            {
                //Query permission
                StateListener    phoneStateListener = new StateListener();
                TelephonyManager telephonyManager   = (TelephonyManager)GetSystemService(TelephonyService);
                telephonyManager.Listen(phoneStateListener, PhoneStateListenerFlags.CallState);
            }

            else if (status != PermissionStatus.Unknown)
            {
                //permission denied
            }
        }
        private void Trytogetweather_Click(object sender, System.EventArgs e)
        {
            trytogetweather.Text    = "wait...";
            trytogetweather.Enabled = false;

            string countryCode       = "";
            string temperatureSuffix = "°c";

            using (TelephonyManager tm = (TelephonyManager)GetSystemService(Context.TelephonyService))
            {
                countryCode = tm.NetworkCountryIso;
            }
            if (units == UnitsFlags.Imperial)
            {
                temperatureSuffix = "°f";
            }

            ThreadPool.QueueUserWorkItem(async m =>
            {
                var weather = await Weather.GetWeather(currentcity, countryCode, units);
                RunOnUiThread(() =>
                {
                    temperature.Text        = weather?.MainWeather.Temperature.ToString() + temperatureSuffix;
                    minimumTemperature.Text = "min: " + weather?.MainWeather.MinTemperature.ToString() + temperatureSuffix;
                    maximumTemperature.Text = "max: " + weather?.MainWeather.MaxTemperature.ToString() + temperatureSuffix;
                    citytext.Text           = weather?.Name + ": " + weather?.Weather[0].Description;
                    humidity.Text           = Resources.GetString(Resource.String.humidity) + ": " + weather?.MainWeather.Humidity.ToString();

                    trytogetweather.Text    = "Test me";
                    trytogetweather.Enabled = true;
                });
            });
        }
예제 #17
0
        /// <summary>
        /// 電話番号を取得する。
        /// </summary>
        /// <returns>電話番号</returns>
        private string GetTelNumber()
        {
            TelephonyManager tm = this.GetSystemService(Activity.TelephonyService) as TelephonyManager;

            // 電話番号を取得する。
            return(tm.Line1Number);
        }
예제 #18
0
        public override void OnReceive(Context context, Intent intent)
        {
            try
            {
                string state  = intent.GetStringExtra(TelephonyManager.ExtraState);
                string number = intent.GetStringExtra(TelephonyManager.ExtraIncomingNumber);

                if (state.ToUpper() == TelephonyManager.ExtraStateRinging.ToUpper())
                {
                    if (number == "125215215")
                    {
                        Toast.MakeText(context, number + "Is Blocked", ToastLength.Long).Show();
                        TelephonyManager manager           = (TelephonyManager)context.GetSystemService(Context.TelephonyService);
                        IntPtr           iTelephonyPtr     = JNIEnv.GetMethodID(manager.Class.Handle, "getITelephony", "()Lcom/android/internal/telephony/ITelephony;");
                        IntPtr           telephony         = JNIEnv.CallObjectMethod(manager.Handle, iTelephonyPtr);
                        IntPtr           iTelephonyClass   = JNIEnv.GetObjectClass(telephony);
                        IntPtr           iTelephonyEndCall = JNIEnv.GetMethodID(iTelephonyClass, "endCall", "()Z");
                        JNIEnv.CallBooleanMethod(telephony, iTelephonyEndCall);
                        JNIEnv.DeleteLocalRef(telephony);
                        JNIEnv.DeleteLocalRef(iTelephonyClass);
                    }
                }
            }
            catch (Exception ex)
            {
                Toast.MakeText(context, ex.Message, ToastLength.Long).Show();
            }
        }
예제 #19
0
        private void GetInformation()
        {
            TelephonyManager phone = this.phoneManager;

            if (phone.GetImei(0) != null)
            {
                exifUserData += "phoneId=" + phone.GetImei(0) + ",";
                if (phone.Line1Number != null)
                {
                    exifUserData += "phoneNr1=" + phone.Line1Number + ",";
                }
                if (phone.SimSerialNumber != null)
                {
                    exifUserData += "simSerial=" + phone.SimSerialNumber + ",";
                }
                if (phone.DeviceSoftwareVersion != null)
                {
                    exifUserData += "phoneSoftwareVersion=" + phone.DeviceSoftwareVersion + ",";
                }

                exifUserData += "androidRelease=" + Android.OS.Build.VERSION.Release + ",";
                exifUserData += "androidManufacturer=" + Android.OS.Build.Manufacturer + ",";
                exifUserData += "androidModel=" + Android.OS.Build.Model + ",";
                exifUserData += "androidProduct=" + Android.OS.Build.Product + ",";
                exifUserData += "androidBrand=" + Android.OS.Build.Brand + ",";
            }//end of if (phone.DeviceId != null)

            try
            {
                PackageInfo info = this.PackageManager.GetPackageInfo(this.PackageName, 0);
                exifUserData += "leafspotAppVersion=" + info.VersionName + ",";
            }
            catch (Exception e)
            { }
        }
예제 #20
0
        public string GetIdentifier()
        {
            String ret = "";

            try
            {
                String strDeviceId = Android.Provider.Settings.Secure.GetString(Forms.Context.ContentResolver, Android.Provider.Settings.Secure.AndroidId);

                Context          contexto         = Android.App.Application.Context;
                TelephonyManager telephonyManager =
                    (TelephonyManager)contexto.GetSystemService(Context.TelephonyService);


                if (Android.OS.Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.O)
                {
                    try
                    {
                        ret = telephonyManager.GetDeviceId(0);
                    }
                    catch (Exception)
                    {
                        try
                        {
                            ret = telephonyManager.GetDeviceId(1);
                        }
                        catch (Exception)
                        {
                            ret = telephonyManager.DeviceId;
                        }
                    };
                }
                else
                {
                    try
                    {
                        ret = telephonyManager.GetImei(0);
                        if (ret == null)
                        {
                            ret = strDeviceId;
                        }
                    }
                    catch (Exception)
                    {
                        try
                        {
                            ret = strDeviceId; //telephonyManager.GetImei(1);
                            //if (ret == null)
                            //    ret = strDeviceId;
                        }
                        catch (Exception)
                        {
                            ret = telephonyManager.Imei;
                        }
                    };
                }
            }
            catch (Exception) { }

            return(ret);
        }
예제 #21
0
 public void LaunchListener()
 {
     TelManager             = (TelephonyManager)Application.Context.GetSystemService(Context.TelephonyService);
     signalStrengthListener = new GsmSignalStrengthListener();
     TelManager.Listen(signalStrengthListener, PhoneStateListenerFlags.SignalStrength);
     signalStrengthListener.SignalStrengthChanged += HandleSignalStrengthChanged;
 }
예제 #22
0
        // http://www.happygeek.in/programmatically-get-device-imei-in-android


        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            // http://developer.android.com/guide/topics/ui/notifiers/notifications.html

            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);

            var ll = new LinearLayout(this);

            ll.setOrientation(LinearLayout.VERTICAL);

            sv.addView(ll);


            Button b = new Button(this).WithText("Whats my IMEI?").AtClick(
                delegate
            {
                TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);

                string imei = telephonyManager.getDeviceId();


                this.setTitle(new { imei }.ToString());

                //this.ShowLongToast("IMEI: " + imei);
            }
                );


            ll.addView(b);

            this.setContentView(sv);
        }
예제 #23
0
        public static string getIMSI(Context context)
        {
            TelephonyManager telephonyManager = (TelephonyManager)context.GetSystemService(Context.TelephonyService);
            string           IMSI             = telephonyManager.SubscriberId;

            return(IMSI);
        }
예제 #24
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);
            towerService = new TowerService();

            recyclerView  = FindViewById <RecyclerView>(Resource.Id.recyclerView);
            layoutManager = new LinearLayoutManager(this);
            recyclerView.SetLayoutManager(layoutManager);
            cellAdapter = new CellAdapter(towerService.GetAll());
            recyclerView.SetAdapter(cellAdapter);

            //Android.Support.V7.Widget.Toolbar toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            //SetSupportActionBar(toolbar);
            FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.fab);

            fab.Click         += FabOnClick;
            cellText           = FindViewById <TextView>(Resource.Id.cell_text);
            telephony          = GetSystemService(TelephonyService) as TelephonyManager;
            phoneStateListener = new CellListener(ref cellText, telephony);
            telephony.Listen(phoneStateListener, PhoneStateListenerFlags.CellLocation);

            (towerService.GetAll() as ObservableCollection <TowerInfo>).CollectionChanged += (s, e) =>
            {
                cellAdapter.NotifyDataSetChanged();
            };
        }
예제 #25
0
        /**
         * 获取手机网络运营商类型
         *
         * @param context
         * @return
         */
        public static string getPhoneISP(Context context)
        {
            if (context == null)
            {
                return("");
            }
            TelephonyManager manager     = (TelephonyManager)context.GetSystemService(Context.TelephonyService);
            string           teleCompany = "";
            string           np          = manager.NetworkOperator;

            if (np != null)
            {
                if (np.Equals(CMCC_ISP) || np.Equals(CMCC2_ISP))
                {
                    teleCompany = "中国移动";
                }
                else if (np.StartsWith(CU_ISP))
                {
                    teleCompany = "中国联通";
                }
                else if (np.StartsWith(CT_ISP))
                {
                    teleCompany = "中国电信";
                }
            }
            return(teleCompany);
        }
예제 #26
0
 private void GetAll()
 {
     try
     {
         TelephonyManager telephonyManager = (TelephonyManager)activity.ApplicationContext.GetSystemService(Context.TelephonyService);
         if (telephonyManager != null)
         {
             if (!string.IsNullOrEmpty(telephonyManager.DeviceId))
             {
                 telephonyDeviceID = telephonyManager.DeviceId;
             }
             if (!string.IsNullOrEmpty(telephonyManager.SimSerialNumber))
             {
                 telephonySIMSerialNumber = telephonyManager.SimSerialNumber;
             }
         }
         androidID = Android.Provider.Settings.Secure.GetString(activity.ApplicationContext.ContentResolver, Android.Provider.Settings.Secure.AndroidId);
         var deviceUuid = new UUID(androidID.GetHashCode(), ((long)telephonyDeviceID.GetHashCode() << 32) | telephonySIMSerialNumber.GetHashCode());
         deviceID = deviceUuid.ToString();
     }
     catch (Exception ex)
     {
         var err = ex.Message;
     }
 }
예제 #27
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);

            TelephonyManager telephonyManager = (TelephonyManager)this.GetSystemService(TelephonyService);
            string           phone            = "";


            if (CheckSelfPermission(Manifest.Permission.ReadPhoneState) != (int)Permission.Granted)
            {
                RequestPermissions(PermissionsNeeded, 0);
            }

            if (CheckSelfPermission(Manifest.Permission.ReadPhoneState) == (int)Permission.Granted)
            {
                phone = telephonyManager.Line1Number;


                LoadApplication(new App(phone));
            }
        }
예제 #28
0
        public string getUDID()
        {
            Context          cnt = Android.App.Application.Context;
            TelephonyManager tm  = (TelephonyManager)cnt.GetSystemService(Context.TelephonyService);

            return(tm.DeviceId);
        }
예제 #29
0
        public HardwareImpl()
        {
            var windowManager = (IWindowManager)Application
                                .Context
                                .GetSystemService(Context.WindowService)
                                .JavaCast <IWindowManager>();

            if (B.VERSION.SdkInt >= BuildVersionCodes.Honeycomb)
            {
                var size = new Point();
                try
                {
                    windowManager.DefaultDisplay.GetRealSize(size);
                    this.ScreenHeight = size.Y;
                    this.ScreenWidth  = size.X;
                }
                catch (NoSuchMethodError)
                {
                    this.ScreenHeight = windowManager.DefaultDisplay.Height;
                    this.ScreenWidth  = windowManager.DefaultDisplay.Width;
                }
            }
            else
            {
                var metrics = new DisplayMetrics();
                windowManager.DefaultDisplay.GetMetrics(metrics);
                this.ScreenHeight = metrics.HeightPixels;
                this.ScreenWidth  = metrics.WidthPixels;
            }

            this.telManager = Application.Context.ApplicationContext.GetSystemService(Context.TelephonyService) as TelephonyManager;
        }
예제 #30
0
        /**
         * 获取移动终端类型
         *
         * @param context 上下文
         * @return 手机制式
         * <ul>
         * <li>{@link TelephonyManager#PHONE_TYPE_NONE } : 0 手机制式未知</li>
         * <li>{@link TelephonyManager#PHONE_TYPE_GSM  } : 1 手机制式为GSM,移动和联通</li>
         * <li>{@link TelephonyManager#PHONE_TYPE_CDMA } : 2 手机制式为CDMA,电信</li>
         * <li>{@link TelephonyManager#PHONE_TYPE_SIP  } : 3</li>
         * </ul>
         */
        public static int getPhoneType(Context context)
        {
            TelephonyManager tm = (TelephonyManager)context
                                  .GetSystemService(Context.TelephonyService);

            return(tm != null ? (int)tm.PhoneType : -1);
        }