我正在尝试打开蓝牙设置的标准窗口(设备名称,可发现性等)。
但是,startActivity(intent)的一般方法以指向BluetoothSettings.java onCreate:135的NullPointerException结束。
使用Android代码进行检查,我发现在第135行,他们从意图中获得了一些额外内容。所以我准备了相同的附加功能(我在android核心BluetoothDevicePicker接口中找到的名称)并发出它 - 与NullPointerException效果相同。
可能是我准备的额外内容的错误名称?
当我打开手动操作的蓝牙设置时,有没有一种方法可以从系统本身提交的意图中看到那些额外的(特别是名字)?
非常感谢。
我的代码是:
Intent settingsIntent = new Intent(); settingsIntent.setClassName(“com.android.settings”,“com.android.settings.bluetooth.BluetoothSettings”); settingsIntent.putExtra(“android.bluetooth.devicepicker.extra.LAUNCH_PACKAGE”,“mypackage.bttoggle”); settingsIntent.putExtra(“android.bluetooth.devicepicker.extra.DEVICE_PICKER_LAUNCH_CLASS”,“mypackage.bttoggle.BluetoothWidget”); PendingIntent settingsPendingIntent = PendingIntent.getActivity(context,0,settingsIntent,0); views.setOnClickPendingIntent(R.id.btnSettings,settingsPendingIntent);
这是一个小部件,所以我需要使用PendingIntent。
此代码在运行时获得以下异常:
ERROR / AndroidRuntime(4905):未捕获的处理程序:由于未捕获的异常而导致主线程退出 ERROR / AndroidRuntime(4905):java.lang.RuntimeException:无法启动活动ComponentInfo {com.android.settings / com.android.settings.bluetooth.BluetoothSettings}:java.lang.NullPointerException ERROR / AndroidRuntime(4905):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596) ERROR / AndroidRuntime(4905):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621) 错误/ AndroidRuntime(4905):在android.app.ActivityThread.access $ 2200(ActivityThread.java:126) ERROR / AndroidRuntime(4905):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1932) 错误/ AndroidRuntime(4905):在android.os.Handler.dispatchMessage(Handler.java:99) ERROR / AndroidRuntime(4905):在android.os.Looper.loop(Looper.java:123) 错误/ AndroidRuntime(4905):在android.app.ActivityThread.main(ActivityThread.java:4595) ERROR / AndroidRuntime(4905):at java.lang.reflect.Method.invokeNative(Native Method) ERROR / AndroidRuntime(4905):at java.lang.reflect.Method.invoke(Method.java:521) ERROR / AndroidRuntime(4905):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:860) ERROR / AndroidRuntime(4905):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) ERROR / AndroidRuntime(4905):at dalvik.system.NativeStart.main(Native Method) ERROR / AndroidRuntime(4905):引起:java.lang.NullPointerException ERROR / AndroidRuntime(4905):at com.android.settings.bluetooth.BluetoothSettings.onCreate(BluetoothSettings.java:135) ERROR / AndroidRuntime(4905):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) ERROR / AndroidRuntime(4905):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544) 错误/ AndroidRuntime(4905):... 11更多
经过调查,我发现在BluetoothSettings.java的第135行有:
公共类BluetoothSettings扩展了PreferenceActivity {
... 132 mNeedAuth = intent.getBooleanExtra(BluetoothDevicePicker.EXTRA_NEED_AUTH,false); 133 mFilterType = intent.getIntExtra(BluetoothDevicePicker.EXTRA_FILTER_TYPE, 134 BluetoothDevicePicker.FILTER_TYPE_ALL); 135 mLaunchPackage = intent.getStringExtra(BluetoothDevicePicker.EXTRA_LAUNCH_PACKAGE); 136 mLaunchClass = intent.getStringExtra(BluetoothDevicePicker.EXTRA_LAUNCH_CLASS); ...
我查看了BluetoothDevicePicker以找到附加内容的名称:
public interface BluetoothDevicePicker { public static final String EXTRA_NEED_AUTH = “android.bluetooth.devicepicker.extra.NEED_AUTH”; public static final String EXTRA_FILTER_TYPE = “android.bluetooth.devicepicker.extra.FILTER_TYPE”; public static final String EXTRA_LAUNCH_PACKAGE = “android.bluetooth.devicepicker.extra.LAUNCH_PACKAGE”; public static final String EXTRA_LAUNCH_CLASS = “android.bluetooth.devicepicker.extra.DEVICE_PICKER_LAUNCH_CLASS”;
所以我在我的代码中使用它们来准备那些特殊的演员。
感谢。