Change the Network Operator with an Android App

2019-02-13 17:35发布

I'm trying to develop an Android App which shows the signal strength of various network operators on a map. The problem is that the only way to change the network operator is by doing it by hand.

Any ideas on how I can get this information without changing it manually? I think that there are internal/private Android classes to do this.

1条回答
Rolldiameter
2楼-- · 2019-02-13 18:15

You will need to use one or more of Google's internal APIs to do this. They are not, by default, available to Android applications for various (usually good) reasons. The API for turning tethering on and off and configuring it, for example, is not a public API and cannot be invoked directly by third party applications.

You will need to do two things. First, download the Android source code and find the API(s) you need to list and switch carrier. You can find the Android source code, and download instructions, here.

Second, you will need to use reflection to invoke the methods on those APIs. The best approach to this, and one I used myself to play with the tethering API, is to write a proxy class. Give it all the same methods as the API you want to use, and inside each method use reflection to invoke the API method. Any other technique will either (a) not compile without adding portions of the Android source code to your classpath and then (b) will compile but blow up when you deploy.

Be aware that you're best doing this on a Nexus branded device as this has the vanilla Android code on it. My (successful) attempt to write a home screen widget to turn tethering on and off worked on a Nexus One but did not work on a Samsung Galaxy Tab P1000. The device supported tethering, but Samsung had modified that part of the OS as part of their porting effort.

查看更多
登录 后发表回答