I'm trying to turn off the cell radio whenever the phone is idle. But the following error pops up on building the project.
Error:(41, 23) error: cannot find symbol method setRadioPower(boolean)
I have referred to a lot of resources and everywhere the way is followed its not working for me.
I am posting my Java files here:
MainActivity.java
public class MainActivity extends AppCompatActivity {
private Phone ph = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TelephonyManager telephonyManager =
(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
ph = com.example.vk9621.radiocall.PhoneFactory.getDefaultPhone();
PhoneStateListener callStateListener = new PhoneStateListener() {
public void onCallStateChanged(int state, String incomingNumber)
{
if(state==TelephonyManager.CALL_STATE_RINGING){
Toast.makeText(getApplicationContext(),"Phone Is Ringing",
Toast.LENGTH_LONG).show();
}
if(state==TelephonyManager.CALL_STATE_OFFHOOK){
Toast.makeText(getApplicationContext(),"Phone is Currently in A call",
Toast.LENGTH_LONG).show();
}
if(state==TelephonyManager.CALL_STATE_IDLE){
ph.setRadioPower(false);
}
}
};
telephonyManager.listen(callStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
}
My PhoneFactory.java is:
import android.content.Context;
import android.os.Looper;
import android.provider.ContactsContract;
/**
* Created by VK9621 on 1/18/2018.
*/
public class PhoneFactory {
static final String LOG_TAG = "PhoneFactory";
static final int SOCKET_OPEN_RETRY_MILLIS = 2 * 1000;
static final int SOCKET_OPEN_MAX_RETRY = 3;
//***** Class Variables
static private ContactsContract.CommonDataKinds.Phone sProxyPhone = null;
static private boolean sMadeDefaults = false;
static private Looper sLooper;
static private Context sContext;
public static ContactsContract.CommonDataKinds.Phone getDefaultPhone() {
if (sLooper != Looper.myLooper()) {
throw new RuntimeException(
"PhoneFactory.getDefaultPhone must be called from Looper thread");
}
if (!sMadeDefaults) {
throw new IllegalStateException("Default phones haven't been made yet!");
}
return sProxyPhone;
}
}
Can someone tell me what is the problem with the code??