GithubHelp home page GithubHelp logo

matrixy / signalstrengths Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fennifith/signalstrengths

0.0 1.0 0.0 62 KB

Sample app to test different methods of getting the cell signal strength from 0-4.

License: Apache License 2.0

Java 100.00%

signalstrengths's Introduction

SignalStrengths

A library and sample application with the purpose of getting an accurate signal strength on different Android phones.

For testing and experimentation purposes, a sample apk can be downloaded here.

Usage

Setup

The Gradle dependency is available through jCenter, which is used by default in Android Studio. To add the module to your project, copy this line into the dependencies section of your build.gradle file.

compile 'james.signalstrengths:signalstrengths:0.0.4'

Listening for Signal Changes

To get your app to listen for a signal change, use [TelephonyManager.listen](https://developer.android.com/reference/android/telephony/TelephonyManager.html#listen(android.telephony.PhoneStateListener, int)) with a PhoneStateListener. A working example of this can be seen in the sample application.

Getting a Signal Value

To obtain a signal value from a SignalStrength object, simply pass it to one of the methods in the SignalStrengths class, which will return a number from 0-4, or -1 if an error occurs. Some examples of this are below.

Using a Specific Method

This allows you to specify exactly which method you want to obtain a value from.

double level = SignalStrengths.get(SignalStrengths.METHOD_LEVEL, signalStrength);

First Valid Level

This gets the first valid signal level available from any method in order of accuracy. This is the most recommended way of getting a signal value, as it is the most consistently accurate across different phones and android versions. See Excluding Methods and Custom Methods for ways to change this method's behavior.

double level = SignalStrengths.getFirstValid(signalStrength);

Average Level

This gets the average of all the valid levels. To exclude a level, see Excluding Methods.

double level = SignalStrengths.getAverage(signalStrength);

Excluding Methods

The list of methods used by SignalStrengths can be accessed using SignalStrengths.getMethods(). An example of how to exclude a method is below.

SignalStrengths.getMethods().get(5).setExcluded(true);

Custom Methods

It is also possible to add your own method to the list of methods used by SignalStrengths. An example for how to create a new method is below.

SignalStrengths.getMethods().add(new SignalMethod("Method Id") {
  @Override
  public double getLevel(SignalStrength signalStrength) {
    return new Random().nextDouble();
  }
});

signalstrengths's People

Contributors

fennifith avatar theandroidmaster avatar matrixy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.