Google Maps, Map is loading, but not completely - java

I have a problem with my Android Studio app using Google Maps, the problem being that my map doesn't completely load. I do get the fully loaded world map, but that's as far as it goes.
The functionality of the app itself works great, I am able to type in whatever country/city/address that I want, and stick a marker to that location (Which in my simple mind tells me that I have all the permissions that I require to utilize the functions I want for this application).
I have been browsing for solutions for hours, but everything I have found, I already have enabled and/or working. I use my Samsung Galaxy S7 phone to run my app and have had no problems so far with Android Studio.
I guess this is just a "cosmetic" issue, but still one I would like to solve.
What I have tried:
Clearing the cache on my device of, Google Play Services, Google Play Store
Getting new API keys from google
Different map layouts MAP_TYPE_NORMAL, MAP_TYPE_HYBRID <- The hyrbid layout does not load at all.
My internet connection, Wifi/Wireless (I have a fast internet connection using either, I doubt that's the problem)
Pictures to better describe what happens:
Starting the app with custom markers.
Zooming in.
Final zoom, with markers in the correct spot.
My code:
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
EditText searchText;
public GoogleMap mMap;
private static final float DEFAULT_ZOOM = 15.0f;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
try {
if (mMap == null) {
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
} catch (Exception e) {
e.printStackTrace();
}
searchText = (EditText) findViewById(R.id.input_search);
init();
}
#Override
public void onMapReady(GoogleMap googleMap)
{
mMap = googleMap;
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
Toast.makeText(this, "Map is ready", Toast.LENGTH_SHORT).show();
}
//init the search
public void init()
{
searchText.setOnEditorActionListener(new TextView.OnEditorActionListener()
{
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
if(actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE)
{
geoLocate();
}
return false;
}
});
}
private void geoLocate()
{
String searchString = searchText.getText().toString();
Geocoder geocoder = new Geocoder(MapsActivity.this);
List<Address> list = new ArrayList<>();
try
{
list = geocoder.getFromLocationName(searchString, 1);
}
catch(Exception e)
{
e.printStackTrace();
}
if(list.size() > 0)
{
Address address = list.get(0);
LatLng position = new LatLng(address.getLatitude(), address.getLongitude());
mMap.addMarker(new MarkerOptions().position(position).title(searchText.getText().toString()));
mMap.moveCamera(CameraUpdateFactory.newLatLng(position));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(position, DEFAULT_ZOOM));
}
}
}
My AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<!--android:value="#string/google_maps_key" />-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="*Api*" />
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
My google_maps_api.xml file:
<resources>
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">*Api*</string>
</resources>
I obviously discluded the API_KEY's with Api.
This is my first post on stackoverflow so any feedback regarding the quality of my post is welcome as well.

Can you confirm that you have setup you Android Google Maps SDK API Key in the google developer console, If not then please Enable Google Maps Android API in google developer console with your application identifier and SHA1 fingerprint? The map won't show until the key is authorised for the particular debug/production build of your app.

Related

How to get BLE devices' names list by android app?

Hello I am making a bluetooth connecting android app.
I followed the instruction from developer.android.com
while I am testing my app, I look forward to it works properly, but it didn't.
I tried to get detected BLE devices names, but don't know the reason why it doesn't show me the devices name...
Arduino nano 33 IOT is adverstising bluetooth next to my android phone, and I am trying to detect it and get the Adrduino's BLE device name and address.
here is my MainActivity.java
public class MainActivity extends AppCompatActivity {
//View Contents Elements
public Button btnActivateBluetooth;
public Button btnSearchBluetooth;
public Button btnSendData;
public ListView lvSearchedDevice;
public ListView lvLog;
public TextView tvStatus;
public EditText etData;
//etc values
public ArrayAdapter<String> logAdapter;
private final int REQUEST_ENABLE_BT = 1;
private boolean mScanning = true;
//bluetooth values
public BluetoothAdapter btAdapter;
public BluetoothManager btManager;
private Handler handler;
#SuppressLint("MissingPermission")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//View Elements
btnSearchBluetooth = (Button) findViewById(R.id.btnSearchBluetooth);
btnSendData = (Button) findViewById(R.id.btnSendData);
lvSearchedDevice = (ListView) findViewById(R.id.lvSearchedDevice);
lvLog = (ListView) findViewById(R.id.log);
tvStatus = (TextView) findViewById(R.id.tvStatus);
etData = (EditText) findViewById(R.id.etData);
//etc
logAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1);
lvLog.setAdapter(logAdapter);
handler = new Handler();
// Initializes Bluetooth adapter.
btManager = (BluetoothManager)getSystemService(Context.BLUETOOTH_SERVICE);
btAdapter = btManager.getAdapter();
// displays a dialog requesting user permission to enable Bluetooth.
if (btAdapter == null || !btAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
btnSearchBluetooth.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
scanLeDevice(true);
}
});
}
//Scan devices
#SuppressLint("MissingPermission")
private void scanLeDevice(final boolean enable){
if(enable){
handler.postDelayed(new Runnable() {
#SuppressLint("MissingPermission")
#Override
public void run() {
btAdapter.stopLeScan(leScanCallback);
}
},5000);
btAdapter.startLeScan(leScanCallback);
}
else
{
btAdapter.stopLeScan(leScanCallback);
}
}
//Callback method
private BluetoothAdapter.LeScanCallback leScanCallback = new BluetoothAdapter.LeScanCallback() {
#Override
public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
runOnUiThread(new Runnable() {
#SuppressLint("MissingPermission")
#Override
public void run() {
Toast.makeText(MainActivity.this, device.getName(), Toast.LENGTH_SHORT).show();
}
});
}
};
}
and this is my Arduino nano 33 IOT's code.
#include <ArduinoBLE.h>
BLEService Toothbrush("00001101-0000-1000-8000-00805F9B34FB");
BLEStringCharacteristic ToothbrushChar("00001101-0000-1000-8000-00805F9B34FB",BLEWrite|BLERead | BLENotify, 10);
void setup() {
Serial.begin(9600);
if(!BLE.begin()){
Serial.println("Starting BLE failed.");
while(1);
}
BLE.setLocalName("HayanToothbrush");
BLE.setAdvertisedService(Toothbrush);
Toothbrush.addCharacteristic(ToothbrushChar);
BLE.addService(Toothbrush);
BLE.advertise();
Serial.println("Bluetooth device active, wating for connections...");
}
void loop() {
BLEDevice central = BLE.central();
if(central) {
Serial.print("Connected to central : ");
Serial.println(central.address());
while(central.connected()){
}
Serial.print("Disconnected from central:");
Serial.println(central.address());
}
}
I add permissions in the Mainfest as below.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.bluetooth0523">
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.Bluetooth0523"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
But it still doesn't find me scanned device name.
I think it's on LeScanCallBack problem.
When running startLeScan, It seems not running callback method.
in addition, I am running this app on SDK_VERSION_30
and Arduino nano IOT 33 is discoverable If I use the Bluetooth function that my phone has, not my application, it will be displayed in the scan result list.
I want to get scan result on my own app.
but don't know where is the problem.
Permissions must be declared and requested depending on Android version. Main differences are:
Target Android 12 or higher
BLUETOOTH_SCAN
Target Android 11 or lower
ACCESS_FINE_LOCATION
See Bluetooth permissions for details.

Background Beacon detection with Android Beacon Library

I'm using Android Beacon Library to scan for iBeacons. I'm using the HM-10 BLE module as a iBeacon. My problem is when i used the Android Beacon Library Sample codes, Nothing happens at all.
As mentioned in the sample code for starting an App in the Background, i created a new java class named "Backgroud" and the MainActivity class.
I want my application to start when a Beacon is detected when the app is not opened. Or show a notification (Toast) when the app is open.
I'm want also to know, what do we put in the MainActivity class.
Any help will be appreciated.
This is my AndroidManifest.xml file :
<application
android:allowBackup="true"
android:name=".Background"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
This is my MainActivity Java class :
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_main );
}
}
This is my Background Java class :
public class Background extends Application implements BootstrapNotifier {
private static final String TAG = ".Background";
private RegionBootstrap regionBootstrap;
#Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "App started up");
BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
// To detect proprietary beacons, you must add a line like below corresponding to your beacon
// type. Do a web search for "setBeaconLayout" to get the proper expression.
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
// wake up the app when any beacon is seen (you can specify specific id filers in the parameters below)
Region region = new Region("com.example.myapp.boostrapRegion", null, null, null);
regionBootstrap = new RegionBootstrap(this, region);
}
#Override
public void didDetermineStateForRegion(int arg0, Region arg1) {
// Don't care
}
#Override
public void didEnterRegion(Region arg0) {
Log.d(TAG, "Got a didEnterRegion call");
// This call to disable will make it so the activity below only gets launched the first time a beacon is seen (until the next time the app is launched)
// if you want the Activity to launch every single time beacons come into view, remove this call.
//regionBootstrap.disable();
Intent intent = new Intent(this, MainActivity.class);
// IMPORTANT: in the AndroidManifest.xml definition of this activity, you must set android:launchMode="singleInstance" or you will get two instances
// created when a user launches the activity manually and it gets launched from here.
Toast.makeText(getApplicationContext(), "A Beacon is detected", Toast.LENGTH_LONG).show();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);
}
#Override
public void didExitRegion(Region arg0) {
// Don't care
}
}

Function Isolating Camera's LED Light and java.lang.NullPointerException: Attempt to invoke virtual method 'void android.hardware.Camera$Parameters

I am struggling to control the LED light next to my camera in the app I am trying to make for my own education purposes. I have tried to follow the methods in http://www.mkyong.com/android/how-to-turn-onoff-camera-ledflashlight-in-android/ , but I am trying to make the function more abstract and more general in order to increase reusable functionality and make the code more readable.
Upon creating my activity we first check, using PackageManager, that a LED camera does in fact exist. I then open the camera. The onClick function runs the functions changeScreen() and toggleLight(). Here you can see the clear advantages of using abstraction, ie toggleLight() works as a black box, using code set out elsewhere. The changeScreen function I know is correct, well before adding toggleLight() it was working correctly.
As the code should be correct, as it was taken from the example, I believe I have a problem with variable scope.
1) Where does the boolean isLighOn need to be declared, in the function or in the activity?
2) Same problem with the camera variable
How else should I go about creating an abstract function toggleLight()? I have checked around on this website, but a lot of posts send you to the link provided above. Moreover I believe an answer to this question would help many users and would provide reusable code.
Here is my code so far and I have posted the error I am getting below again.
package com.mycompany.myapplication;
import android.app.*;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.drawable.ColorDrawable;
import android.hardware.Camera;
import android.os.*;
import android.util.Log;
import android.view.*;
import android.widget.*;
public class MainActivity extends Activity {
public RelativeLayout container;
private boolean isLighOn = false;
private Camera camera;
#Override
protected void onStop() {
super.onStop();
if (camera != null) {
camera.release();
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Context context = this;
PackageManager pm = context.getPackageManager();
// if device support camera?
if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
Log.e("err", "Device has no camera!");
return;
}
camera = Camera.open();
container = (RelativeLayout) findViewById(R.id.MainActivity);
container.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
changeScreen(v);
toggleLight();
}
});
}
public void changeScreen(View v) {
ColorDrawable cd = (ColorDrawable) this.container.getBackground();
TextView ON = (TextView) findViewById(R.id.ON);
TextView OFF = (TextView) findViewById(R.id.OFF);
if (cd != null && cd.getColor() == getResources().getColor(R.color.BLACK)) {
container.setBackgroundColor(getResources().getColor(R.color.WHITE));
OFF.setVisibility(View.INVISIBLE);
ON.setVisibility(View.VISIBLE);
} else {
container.setBackgroundColor(getResources().getColor(R.color.BLACK));
OFF.setVisibility(View.VISIBLE);
ON.setVisibility(View.INVISIBLE);
}
}
public void toggleLight(){
final Camera.Parameters p = camera.getParameters();
if (isLighOn) {
Log.i("info", "torch is turn off!");
p.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
camera.setParameters(p);
camera.stopPreview();
isLighOn = false;
} else {
Log.i("info", "torch is turn on!");
p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
camera.startPreview();
isLighOn = true;
}
}
}
When I load the app on my Android Studio emulator, I get the screen "ON". However, when you click the screen the app crashes. This is only error message I can find in the IDE. I am not sure how to interpret this error message.
In response to a comment below I am now posting the code containing the permissions.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myapplication">
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Don't rely on an emulator to produce reliable camera behavior. Always verify camera-related code on real device!

Application Class Null Pointer Exception

I am creating an Android app and wish to store a variable in the Application class. The variable signifies which Activity is currently in focus.
I aim to set this variable in onResume() and reset it in onPause(). Both methods are called as the app initialises. The software crashes on the basis of a Null Pointer Excepetion whenever I run my code, at lines where I try to modify the variable in the Application class. As far as I am aware, it appears to me as though the Application class is null even though I have tested the code and know it call the Application class' onCreate().
Am I correct in assuming it is connected to the Application Class not being completely created? Or is it connected to my instantiation of it all? I'm reasonably new to Android and haven't dealt with the Application class before - as far as I can see, I've followed the guides and tutorials correctly. I'm hoping it's a simple mistake.
Any and all advice is greatly appreciated!
MainActivity.java
public class MainActivity extends FragmentActivity implements ActionBar.TabListener {
//[... other initialisations...]
// Tells software what window is in focus.
// Reference to Application class
private MyApplicationClass app = (MyApplicationClass)getApplication();
private static final int outOfFocus = 0;
private static final int inFocus = 1;
#Override
protected void onResume() {
super.onResume();
//[... other code...]
app.setActivityFocusIndicator(inFocus); //Crashes here
}
#Override
protected void onPause() {
super.onPause();
//[... other code...]
app.setActivityFocusIndicator(outOfFocus); //Crashes here
}
}
MyApplicationClass.java
public class MyApplicationClass extends Application {
private int activityFocusIndicator;
/* activityFocusIndicator is here to indicate which activity is in focus.
* 0 = Nothing in focus (written when pausing.)
* 1 = MainActivity
* 2 = ...
* ...
*/
public void setActivityFocusIndicator(int activityFocusIndicator) {
this.activityFocusIndicator = activityFocusIndicator;
}
public int getActivityFocusIndicator() {
return activityFocusIndicator;
}
#Override
public void onCreate() {
super.onCreate();
Log.d("App", "App was created."); // This line is reached.
}
}
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.someApp"
android:versionCode="1"
android:versionName="1.0" >
<uses-feature android:name="android.hardware.bluetooth_le"
android:required="true"/>
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/TabTheme"
android:name="com.example.someName.MyApplicationClass" >
<activity
android:name="com.example.someName.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleInstance" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
...
</activity>
<!-- ... [other activities declared]... -->
<service
android:name=".BluetoothService"/>
</application>
</manifest>
I can post the LogCat if asked.
I don't see the point of this line :
private MyApplicationClass app = (MyApplicationClass)getApplication();
This variable is probably initialized before the reference returned by getApplication() is initialized, and therefore remains null.
Instead of using it, replace each acess to app with a local variable.
For example:
protected void onResume() {
super.onResume();
//[... other code...]
MyApplicationClass app = (MyApplicationClass)getApplication();
app.setActivityFocusIndicator(inFocus);
}

getGSMSignalStrength() Always Returns 99

I know there is another question on here relating to this, but I don't think it applies to me, as I'm pretty sure I use GSM (isGSM() returns true). In any case, getCdmaDbm returns -1 for me anyway. I am using Android 4.1.1 and an HTC One X. Here is my code (most of which isn't mine):
MainActivity:
package com.example.receptionlookup;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.telephony.PhoneStateListener;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.view.Menu;
import android.widget.Toast;
public class MainActivity extends Activity {
TelephonyManager Tel;
MyPhoneStateListener MyListener;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/* Update the listener, and start it */
MyListener = new MyPhoneStateListener();
Tel = ( TelephonyManager )getSystemService(Context.TELEPHONY_SERVICE);
Tel.listen(MyListener ,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
/* Called when the application is minimized */
#Override
protected void onPause()
{
super.onPause();
Tel.listen(MyListener, PhoneStateListener.LISTEN_NONE);
}
/* Called when the application resumes */
#Override
protected void onResume()
{
super.onResume();
Tel.listen(MyListener,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
/* —————————– */
/* Start the PhoneState listener */
/* —————————– */
private class MyPhoneStateListener extends PhoneStateListener
{
/* Get the Signal strength from the provider, each tiome there is an update */
#Override
public void onSignalStrengthsChanged(SignalStrength signalStrength)
{
super.onSignalStrengthsChanged(signalStrength);
Toast.makeText(getApplicationContext(), "Go to Firstdroid!!! GSM Cinr = "
+ String.valueOf(signalStrength.getGsmSignalStrength()), Toast.LENGTH_SHORT).show();
}
};/* End of private Class */
}
AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.receptionlookup"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.receptionlookup.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
</manifest>
Does anyone know what the problem is? If I go to Settings->About->Network, I can see the signal strength there. Isn't there some way to just read this value? I've tried several third party apps, and none of them are able to read my signal strength either. I've also tried the proprietary getGSMSignalBar() method, but I get a NoSuchMethodException.
As you can read in the 3GPP 127 007 8.5 the implementation of the at+csq is optional (the command which suppose to give the signal strength). Apparently HTC hide this value from 3rd party applications and they probably have another way to achieve that value for display in their own proprietary Settings application.
The fact that other applications also cannot get that information justifies my case.
This issue is tightly related to yours - thay said that HTC is one of the OEMs that does not worth the modem related developing time.
Try this:
Class signalStrengthClass = signalStrength.getClass();
try {
Method method = signalStrengthClass.getMethod(
"getGsmSignalBar", null);
method.setAccessible(true);
Integer bars = (Integer) method.invoke(signalStrength,
(Object[]) null);
}
} catch (Exception e) {
e.printStackTrace();
}

Categories