小编sna*_*man的帖子

如何在Android源代码中访问setPreferredNetworkType

我有一个问题,我想在Android手机上选择首选网络类型.您可以通过执行以下步骤来执行此操作:

  1. ##4636# #
  2. 选择"手机信息"
  3. 走到最底
  4. 在菜单上选择首选网络类型

所以在对源代码进行一些搜索后,我找到了正确的类:Phone.java((frameworks\base\telephony\java\com\android\internal\telephony)

所以有了Vinay的好技巧:如何禁用Android上的移动数据 谁使用java反射来访问隐藏的类,我也尝试过这样做:

Method setPrefNetmethod;
Class telephonyManagerClass;
Object ITelephonyStub;
Class ITelephonyClass;

TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
telephonyManagerClass = Class.forName(telephonyManager.getClass().getName());
Method getITelephonyMethod = telephonyManagerClass.getDeclaredMethod("getITelephony");
getITelephonyMethod.setAccessible(true);
ITelephonyStub = getITelephonyMethod.invoke(telephonyManager);
ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName());

setPrefNetmethod = ITelephonyClass.getDeclaredMethod("setPreferredNetworkType",new Class[] { Integer.class, Message.class });

Message response = Message.obtain();
setPrefNetmethod.setAccessible(false);

setPrefNetmethod.invoke(ITelephonyStub, new Object[] { network_mode, response });
Run Code Online (Sandbox Code Playgroud)

但问题是我在DDMS上有这个错误:

03-25 18:18:45.937:WARN/System.err(2989):java.lang.NoSuchMethodException:setPreferredNetworkType 03-25 18:18:45.937:WARN/System.err(2989):at java.lang.ClassCache. findMethodByName(ClassCache.java:308)

那么你有想法访问setPreferredNetworkType或选择programmaticaly我的首选网络类型吗?

有关信息(在RILConstants.java中):

/* NETWORK_MODE_* See ril.h RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE */
int NETWORK_MODE_WCDMA_PREF     = 0; /* …
Run Code Online (Sandbox Code Playgroud)

java reflection android

9
推荐指数
1
解决办法
1万
查看次数

在Python 3中将二进制文件转换为字节数组

目前我正在尝试使用pygatt将数据发送到 ble 特征,但它使用 bytearray 作为参数。我的输入是一个二进制文件,例如:

$ xxd file.bin 
00000000: 0300 1100 0022 0100 0021 8ff6 82ce 8dad  ....."...!......
00000010: 54                                       T
Run Code Online (Sandbox Code Playgroud)

我想要的是:

>>> bytearray([0x03, 0x00, 0x11, 0x00, 0x00, 0x22, 0x01, 0x00, 0x00, 0x21, 0x8f, 0xf6, 0x82, 0xce, 0x8d, 0xad, 0x54])
Run Code Online (Sandbox Code Playgroud)

所以也许我对这种低级方法的理解是错误的,但我所做的是:

import binascii
import hexdump

my_file = "file.bin"
with open(my_file, 'rb') as file_t:

    # read the file as xxd do
    blob_data = hexdump.hexdump(file_t, result='return')
    print(blob_data)


with open(my_file, 'rb') as file_t:
    blob_data = binascii.hexlify(file_t.read())
    print(blob_data)

with open(my_file, 'rb') as …
Run Code Online (Sandbox Code Playgroud)

python arrays hex file python-3.x

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

arrays ×1

file ×1

hex ×1

java ×1

python ×1

python-3.x ×1

reflection ×1