2012-12-12 79 views
2

我試圖調用顯示WiFi,聲音和藍牙但不是工作的設置: 我將把我的代碼放在這裏,還有logcat我希望這個設置在按鈕點擊事件上,並且只顯示選定的圖標 如果有其他方式使用此Android意圖不適用於WiFi,聲音,藍牙?

我想使用像看到這裏enter image description 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) 

回答

3

您需要使用EXTRA_AUTHORITIES這樣的:

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

和intent.addCategory不用於此。只使用一個android.provider.Settings。按意圖鍵入。

+0

我想打開後buttonclick從我的應用程序的設置被重定向到設置,並只顯示WiFi,藍牙和聲音設置等設置不希望顯示不適用於此 – Mahesh

+0

Mahesh

+0

什麼是寫在logcat? –

1

這是說ActivityNotFound。所以問題必須在這一行。

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

我想你應該嘗試

startActivity(new Intent(Settings.ACTION_SETTINGS)); 
+0

是的,我會嘗試這個,但顯示設置中的所有選項,但我的客戶端要求是用戶只能看到三個選項設置WIFI,藍牙和聲音其他設置自動隱藏 – Mahesh