I tried creating a plugin but not working in unity.I do not have much idea about Android studio but watched this video to create an android plugin.I created a new android project without any activity.So I have written two classes UnityBinder.java and Gallery.java.They are given below
UnityBinder.java
package com.techripples.unityplugin;
import android.app.Activity;
import android.content.Intent;
public class UnityBinder {
public static void OpenGallery(Activity activity)
{
Intent intent =new Intent(activity,Gallery.class);
activity.startActivity(intent);
}
}
Gallery.java class given below
package com.techripples.unityplugin;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.MediaStore;
import android.net.Uri;
import android.database.*;
import com.unity3d.player.*;
public class Gallery extends Activity {
int PHOTO_GALLERY=1;
#Override
protected void onCreate(Bundle bundle)
{
super.onCreate(bundle);
Intent intent=new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent,PHOTO_GALLERY);
}
//it will run when user picks a photo from the gallery
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK && requestCode==PHOTO_GALLERY && data!=null)
{
Uri uri=data.getData();
String[] fileColoumn={MediaStore.Images.Media.DATA};
Cursor cursor=getContentResolver().query(uri,fileColoumn,null,null,null);
cursor.moveToFirst();
int coloumnIndex=cursor.getColumnIndex(fileColoumn[0]);
String photoPath=cursor.getString(coloumnIndex);
//Send path to unity to get photo
//GamObject Name,method name,argument
UnityPlayer.UnitySendMessage("Gallery","OnPhotoPick",photoPath);
Gallery.this.finish();//close activity
}
}
}
Next I have build and copied the jar file into Unity.The c# code written is as follows
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShowPicture : MonoBehaviour
{
Texture2D galleryImage;
bool isGalleryImageLoaded = false;
WWW www;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnGUI()
{
if(isGalleryImageLoaded)
{
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), galleryImage);
}
if(GUI.Button(new Rect(50,50,100,100),"Open"))
{
isGalleryImageLoaded = false;
AndroidJavaClass ajc = new AndroidJavaClass("com.unity.player.UnityPlayer");
//While asking question used AndroidJavaClass instead of AndroidJavaObject
AndroidJavaObject ajo = new AndroidJavaObject("com.techripples.unityplugin.UnityBinder");
ajo.CallStatic("OpenGallery", ajc.GetStatic<AndroidJavaObject>("currentActivity"));
}
if(www!=null && www.isDone)
{
galleryImage = new Texture2D(www.texture.width, www.texture.height);
galleryImage.SetPixels32(www.texture.GetPixels32());
galleryImage.Apply();
www = null;
isGalleryImageLoaded = true;
}
}
public void OnPhotoPick(string filePath)
{
Debug.Log(filePath);
www = new WWW("file://" + filePath);
}
}
The manifest file which I copied into the Unity folder.Assets>Plugins>Android. is as follows.
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="preferExternal">
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"/>
<application
android:theme="#style/UnityThemeSelector"
android:icon="#mipmap/app_icon"
android:label="#string/app_name">
<activity android:name="com.unity3d.player.UnityPlayerActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
<activity android:name="com.techripples.unityplugin.Gallery"></activity>
</application>
The error I got from terminal is as follows
01-28 13:25:06.305 27032 27061 E Unity : java.lang.ClassNotFoundException: Didn't find class "com/unity/player/UnityPlayer" on path: DexPathList[[zip file "/data/app/com.testing.androidplugin-Aq1j3vpTxsomWMvd4kK7NQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.testing.androidplugin-Aq1j3vpTxsomWMvd4kK7NQ==/lib/arm, /data/app/com.testing.androidplugin-Aq1j3vpTxsomWMvd4kK7NQ==/base.apk!/lib/armeabi-v7a, /system/lib, /system/vendor/lib]]
Video of plugin done.What I am doing wrong here.
Making Of Android plugin
I dont know how the calls are being made or what should I write in the manifest for the activity to run.
If you open UnityPlayerActivity, you can see, that its package name is "com.unity3d.player" and class name is "UnityPlayer"
So you should change you unity player class name in C# script to "com.unity3d.player.UnityPlayer".
Another solution is add to your android plugin Unity classes and extend your activity from UnityPlayerActivity and you can call your methods directly from your plugin
Related
So I just started working on this project and part of it is sending packages of information from an app in Java to another Unity app.
I have been trying to follow this tutorial but I have problems getting it to work and even somewhat understanding it a bit since I have not worked with Java before.
Here is the current code I have so far.
Main Activity Class
package com.example.service3;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
startService(new Intent(this, MyService.class));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
}
Sender class
package com.example.service3;
import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
public class MyService extends Service
{
private final Handler handler = new Handler();
private int numIntent;
// It's the code we want our Handler to execute to send data
private Runnable sendData = new Runnable() {
// the specific method which will be executed by the handler
public void run() {
numIntent++;
// sendIntent is the object that will be broadcast outside our app
Intent sendIntent = new Intent();
// We add flags for example to work from background
sendIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION|Intent.FLAG_FROM_BACKGROUND|Intent.FLAG_INCLUDE_STOPPED_PACKAGES );
// SetAction uses a string which is an important name as it identifies the sender of the itent and that we will give to the receiver to know what to listen.
// By convention, it's suggested to use the current package name
sendIntent.setAction("com.example.service3");
// Here we fill the Intent with our data, here just a string with an incremented number in it.
sendIntent.putExtra(Intent.EXTRA_TEXT, "Intent "+numIntent);
// And here it goes ! our message is send to any other app that want to listen to it.
sendBroadcast(sendIntent);
// In our case we run this method each second with postDelayed
handler.removeCallbacks(this);
handler.postDelayed(this, 1000);
}
};
#Override
public void onStart(Intent intent, int startid) {
numIntent = 0;
// We first start the Handler
handler.removeCallbacks(sendData);
handler.postDelayed(sendData, 1000);
}
#Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
}
XML for Sender
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.service3"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.service3.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>
<service android:enabled="true" android:name="com.example.service3.MyService" />
</application>
Receiver Class
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class Receiver extends BroadcastReceiver
{
private static Receiver instance;
public static String text ="1";
#Override
public void onReceive(Context context, Intent intent)
{
// TODO Auto-generated method stub
String sentIntent = intent.getStringExtra(Intent.EXTRA_TEXT);
text = "-1";
}
public static void createInstance()
{
if(instance == null)
{
instance = new Receiver();
}
}
}
Unity Android Manifest
<application android:theme="#android:style/Theme.NoTitleBar.Fullscreen" android:icon="#drawable/app_icon" android:label="#string/app_name" android:debuggable="false" android:isGame="true" android:banner="#drawable/app_banner">
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="#string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
<receiver android:name="com.example.receiver3.MyReceiver" >
<intent-filter>
<action android:name="com.example.receiver3" ></action>
</intent-filter>
</receiver>
</application>
I realise this is a massively large post but I simply do not know what to do at this point and am somewhat considering backing out of the project for the fact that I have no idea how to get Java to communicate with Unity.
Thanks in advance.
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!
I've been trying to make an application that uses lock screen concepts for which as a dry run I've created an app that locks the screen once the given button is clicked, well I've used the basic concepts nothing new here's my Java code
package com.example.gaurav.locknowtest2;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.app.admin.DevicePolicyManager;
import android.app.admin.DeviceAdminReceiver;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends DeviceAdminReceiver{
public class controller extends Activity{
DevicePolicyManager dpm;
ComponentName comname;
Button b1;
TextView display;
public void OnCreate(Bundle xyz){
super.onCreate(xyz);
dpm=(DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
comname=new ComponentName(this,MainActivity.class);
setContentView(R.layout.activity_main);
b1=(Button)findViewById(R.id.start);
display=(TextView)findViewById(R.id.xyz);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, comname);
startActivityForResult(intent,1);
display.setText("just to test the method");
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 1:
if (resultCode == Activity.RESULT_OK) {
dpm.lockNow();
} else {
Log.i("DeviceAdminSample", "Administration enable FAILED!");
}
return;
}
}
}
}
next up here's my manifest that I think is creating all the problems
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gaurav.locknowtest2" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity$controller"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".MainActivity"
android:permission="android.permission.BIND_DEVICE_ADMIN" >
<meta-data
android:name="android.app.device_admin"
android:resource="#xml/device_admin_sample" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
</application>
</manifest>
I need to get this done by this week so please take a look..
Your method is not written correcrt.
public void OnCreate(Bundle xyz){
you have a CAPITAL O
it should be like this:
#Override
public void onCreate(Bundle savedInstanceState) {
...
}
Java is case-sensitive, so naming your method
public void OnCreate(Bundle bundle) {
is not
protected void onCreate(Bundle bundle) {
use the #Override annotation to ensure that you actually are overriding a method.
Also, public class controller extends Activity { should be public static class controller extends Activity { apart from the fact that as per Java naming conventions, classes should start with a Capital letter.
A class extending Activity cannot be an inner class of another class because the android system needs to be able to create new instances of your Activity class without an instance of another class. Your controller class is an inner class of MainActivity so cannot be instantiated without an instance of MainActivity.
See this answer:
Nested inner Activity class in android
Also, as pointed out by others, you have a typo in onCreate. This means that you have made a completely separate method, not overridden onCreate. However this doesn't explain why the application crashes. (You can write an Activity class that doesn't override onCreate, and it works without any exceptions being thrown.)
I am new to programming and I am trying to figure out how Activities in android programming work by making a small app,which should let me know in which state of the activity I am.
I am getting an error in the setContentView because Android Studio says "cannot resolve symbol "R""
Here is my code:
package com.example.daniele.activity;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity {
String tag = "Lifecycle";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d(tag, "in the onCreate() event");
}
public void onStart() {
super.onStart();
Log.d(tag, "in the onStart() event");
}
public void onRestart() {
super.onRestart();
Log.d(tag, "in the onRestart() event");
}
public void onResume() {
super.onResume();
Log.d(tag, "in the onResume() event");
}
public void onPause() {
super.onPause();
Log.d(tag, "in the onPause() event");
}
public void onStop() {
super.onStop();
Log.d(tag, "in the onStop() event");
}
public void onDestroy() {
super.onDestroy();
Log.d(tag, "in the onDestroy() event");
}
}
here is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.daniele.activity" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".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>
</manifest>
Everyone is suggesting you the fix. Good. But since you are learning, you should also understand what is happening here:
All layout files are in xml
Every xml file is compiled and made available to java classes
The compiled class is called R.java
To make
R.java available to your class you need to import it
Under
import android.util.Log;
add this
import com.example.daniele.R;
Alternatively when you see a red underline under something, you can hover above it and Android Studio usually tells you what you need to do. In this case, "Optimize Imports" or something similar.
"R" errors usually happen when one or more of your XML files is corrupt. Start by seeing if your apps manifest looks correct!
You will need to import R because your activity is in a different package.
import com.example.daniele.R;
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();
}