android intent not work for wifi,sound,bluetooth?

拜拜、爱过 提交于 2019-12-12 22:15:21

问题


I'm try to call setting which display WiFi,sound and bluetooth but is not work: i will put my code here and also logcat i want this settings on button click event and display only selected icons if any other way to use this

i want to use like see image here

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    setContentView(R.layout.wifi);

    Button wifi =(Button)findViewById(R.id.wifi);
    wifi.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {


            Intent intent = new Intent(android.provider.Settings.AUTHORITY);
            intent.putExtra(Settings.EXTRA_AUTHORITIES, new String[] {                      

                    android.provider.Settings.ACTION_BLUETOOTH_SETTINGS
                                });
            intent.putExtra(Settings.EXTRA_AUTHORITIES, new String[] {                      

                    android.provider.Settings.ACTION_WIFI_SETTINGS
                                });
            startActivity(intent);
        }
    });
}

Logcat

12-13 10:36:04.229: E/AndroidRuntime(1167): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=authorities cat=[android.settings.BLUETOOTH_SETTINGS,android.settings.SOUND_SETTINGS,android.settings.WIRELESS_SETTINGS] }
12-13 10:36:04.229: E/AndroidRuntime(1167):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
12-13 10:36:04.229: E/AndroidRuntime(1167):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
12-13 10:36:04.229: E/AndroidRuntime(1167):     at android.app.Activity.startActivityForResult(Activity.java:3217)
12-13 10:36:04.229: E/AndroidRuntime(1167):     at android.app.Activity.startActivity(Activity.java:3324)
12-13 10:36:04.229: E/AndroidRuntime(1167):     at com.example.settings.WifiActivity$1.onClick(WifiActivity.java:30)
12-13 10:36:04.229: E/AndroidRuntime(1167):     at android.view.View.performClick(View.java:3511)
12-13 10:36:04.229: E/AndroidRuntime(1167):     at android.view.View$PerformClick.run(View.java:14109)
12-13 10:36:04.229: E/AndroidRuntime(1167):     at android.os.Handler.handleCallback(Handler.java:605)
12-13 10:36:04.229: E/AndroidRuntime(1167):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-13 10:36:04.229: E/AndroidRuntime(1167):     at android.os.Looper.loop(Looper.java:137)
12-13 10:36:04.229: E/AndroidRuntime(1167):     at android.app.ActivityThread.main(ActivityThread.java:4424)
12-13 10:36:04.229: E/AndroidRuntime(1167):     at java.lang.reflect.Method.invokeNative(Native Method)
12-13 10:36:04.229: E/AndroidRuntime(1167):     at java.lang.reflect.Method.invoke(Method.java:511)
12-13 10:36:04.229: E/AndroidRuntime(1167):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-13 10:36:04.229: E/AndroidRuntime(1167):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-13 10:36:04.229: E/AndroidRuntime(1167):     at dalvik.system.NativeStart.main(Native Method)

回答1:


You need to use the EXTRA_AUTHORITIES like this:

intent.putExtra(Settings.EXTRA_AUTHORITIES, new String[] {
    Calendar.AUTHORITY
});

and intent.addCategory is not used for this. use only one android.provider.Settings. type per intent.




回答2:


It is saying ActivityNotFound. So problem must be in this line.

Intent intent = new Intent(android.provider.Settings.EXTRA_AUTHORITIES);

I think you should try

startActivity(new Intent(Settings.ACTION_SETTINGS));



回答3:


No Activity found to handle Intent { 
    act=android.settings.WIFI_DISPLAY_SETTINGS 
}

onCreate    XT1706
onCreate    MobileName=XT1706
onCreate    WIFI_DISPLAY_SETTINGS is null
onCreate    android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.WIFI_DISPLAY_SETTINGS }
onCreate    XT1706
onCreate    MobileName=XT1706
onCreate    WIFI_DISPLAY_SETTINGS is null
onCreate    android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.WIFI_DISPLAY_SETTINGS }
onCreate    XT1706


来源:https://stackoverflow.com/questions/13846143/android-intent-not-work-for-wifi-sound-bluetooth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!