2012-07-02 18 views
8

不工作了果凍豆(安卓4.1):Android的 - 移動網絡設置菜單(Jelly Bean)的下面的代碼

final ComponentName cn = new ComponentName("com.android.phone","com.android.phone.Settings"); 
final Intent intent=new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS); 
intent.addCategory(Intent.CATEGORY_LAUNCHER); 
intent.setComponent(cn); 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
startActivity(intent); 

而是開始設置,它沒有doesn't,任何想法如何解決呢?

這裏是解決方案:

final ComponentName cn = new ComponentName("com.android.phone","com.android.phone.MobileNetworkSettings"); 
final Intent intent = new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS); 
intent.addCategory(Intent.ACTION_MAIN); 
intent.setComponent(cn); 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
startActivity(intent); 

謝謝你們:)

+0

嘗試添加FLAG_A CTIVITY_NEW_TASK標誌 –

回答

5

嘗試爲:

final Intent intent=new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS); 
intent.addCategory(Intent.CATEGORY_LAUNCHER); 
final ComponentName cn = new ComponentName("com.android.phone","com.android.phone.Settings"); 
intent.setComponent(cn); 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
startActivity(intent); 
+0

如果這不起作用,那麼簡單的方法將您的設備連接到調試器並手動啓動ACTION_DATA_ROAMING_SETTINGS設置,然後在日誌中查看包名和活動名稱由系統啓動 –

+0

在日誌中檢查活動名稱sonething like com.android.phone/.Settings? ? –

0

下面的代碼是更加簡單和薑餅測試(2.3.7)和JB(4.1.2)

startActivityForResult(new Intent(android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS), 0); 
相關問題