是否有可能啓動「應用程序信息」屏幕(即Menu
→ Settings
→ Applications
→ Manage Applications
→選擇的任何應用程序)從另一個應用程序?如何以編程方式啓動android應用程序信息屏幕?
回答
在Android 2.3的,你可以在一個ACTION_APPLICATION_DETAILS_SETTINGS
Intent
使用startActivity()
,以適當Uri
,把你的應用程序的「管理」屏幕。然而,這對於Android 2.3來說是新的 - 我不知道在以前的Android版本中這樣做的方法。
startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_SETTINGS));
將帶您進入設置/應用程序列表。 如果你想打開一個特定的應用程序,我想在2.2以下沒有辦法,所以你需要去一個(不一定建議,因爲非官方)的方式:
final Intent i = new Intent("android.intent.action.VIEW");
i.setComponent(new ComponentName("com.android.settings","com.android.settings.InstalledAppDetails"));
i.putExtra(...); // need to figure out the correct extra, probably app package name
startActivity(i);
但是請注意,這是不推薦,因爲它不是官方的API /意圖(過濾器),因此可能會在未來發生變化。
在2.2及更低版本中,沒有可以訪問的公共API。但是,您仍然可以像ManageApplications一樣啓動InstalledApp詳細信息活動。看到here
// utility method used to start sub activity
private void startApplicationDetailsActivity() {
// Create intent to start new activity
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClass(this, InstalledAppDetails.class);
intent.putExtra(APP_PKG_NAME, mCurrentPkgName);
// start new activity to display extended information
startActivityForResult(intent, INSTALLED_APP_DETAILS);
}
結論:您可以啓動 「應用程序信息」 屏幕喜歡我寫道:
private static final String SCHEME = "package";
private static final String APP_PKG_NAME_21 = "com.android.settings.ApplicationPkgName";
private static final String APP_PKG_NAME_22 = "pkg";
private static final String APP_DETAILS_PACKAGE_NAME = "com.android.settings";
private static final String APP_DETAILS_CLASS_NAME = "com.android.settings.InstalledAppDetails";
public static void showInstalledAppDetails(Context context, String packageName) {
Intent intent = new Intent();
final int apiLevel = Build.VERSION.SDK_INT;
if (apiLevel >= 9) { // above 2.3
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts(SCHEME, packageName, null);
intent.setData(uri);
} else { // below 2.3
final String appPkgName = (apiLevel == 8 ? APP_PKG_NAME_22
: APP_PKG_NAME_21);
intent.setAction(Intent.ACTION_VIEW);
intent.setClassName(APP_DETAILS_PACKAGE_NAME,
APP_DETAILS_CLASS_NAME);
intent.putExtra(appPkgName, packageName);
}
context.startActivity(intent);
}
非常感謝你!這節省了我很多時間。如果評論「2.3以上」改爲「2.3以上」? – kristianlm 2011-09-14 18:31:04
這對任何已安裝的應用程序來說都是完美的。但是,如果我嘗試打開任何系統應用程序的設置,會出現空白屏幕。 – 2012-01-10 23:42:41
我們還需要添加intent.setFlags(意圖。FLAG_ACTIVITY_NEW_TASK);在這兩個聲明。即if(){... here ...} else {... here ...} – 2013-12-31 09:26:31
從API等級9(安卓2.3),你就可以開始與意向android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS。因此:
packageName = "your.package.name.here"
try {
//Open the specific App Info page:
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + packageName));
startActivity(intent);
} catch (ActivityNotFoundException e) {
//e.printStackTrace();
//Open the generic Apps page:
Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);
startActivity(intent);
}
老問題,提高了答案:
/**
* <p>Intent to show an applications details page in (Settings) com.android.settings</p>
*
* @param context The context associated to the application
* @param packageName The package name of the application
* @return the intent to open the application info screen.
*/
public static Intent newAppDetailsIntent(Context context, String packageName) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("package:" + packageName));
return intent;
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.FROYO) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName("com.android.settings",
"com.android.settings.InstalledAppDetails");
intent.putExtra("pkg", packageName);
return intent;
}
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName("com.android.settings",
"com.android.settings.InstalledAppDetails");
intent.putExtra("com.android.settings.ApplicationPkgName", packageName);
return intent;
}
我用保羅的解決方案,以打開SDK應用程序詳細信息設置23+當用戶拒絕在過去的許可請求和在權限請求系統對話框中選擇「不要再詢問」選項。
但在這種情況下,我直接使用getPackageName()
方法。
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivity(intent);
- 1. 如何在Android中以編程方式啓動主屏幕
- 2. 以編程方式在主屏幕上啓動Web應用程序?
- 3. Android屏幕以編程方式打開
- 4. 以編程方式啓用本機android密碼屏幕
- 5. 如何以編程方式啓動JNLP應用程序?
- 6. 如何以編程方式啓動掛架Web應用程序?
- 7. 如何以編程方式啓動應用程序?
- 8. 如何以編程方式啓動Facebook應用程序?
- 9. 以Android編程的屏幕截圖問題以編程方式
- 10. Android:啓動Flash應用程序作爲屏幕保護程序
- 11. 以編程方式啓動啓動程序選擇/ Android
- 12. 如何使pinterest android應用程序啓動屏幕?
- 13. 如何以編程方式安裝屏幕保護程序?
- 14. Android:如何以編程方式直接調用PIN屏幕?
- 15. 如何以編程方式在Android中啓動特定的應用程序?
- 16. 如何以編程方式重新啓動java web啓動應用程序
- 17. 如何以編程方式在UWP應用程序中調暗屏幕
- 18. 屏幕不啓動iphone應用程序
- 19. 如何將應用程序圖標以編程方式鎖定到Windows 8中的地鐵啓動屏幕
- 20. 以編程方式更改啓動屏幕圖像
- 21. 以編程方式啓動IE Mobile收藏夾屏幕
- 22. 以編程方式訪問啓動屏幕XIB或故事板
- 23. 以屏幕截圖(以編程方式)
- 24. 如何覆蓋Android的啓動器應用程序的信息?
- 25. 如何以編程方式關閉android中的屏幕?
- 26. 如何以編程方式在Android中鎖定屏幕?
- 27. 如何以編程方式進入Android的默認主屏幕?
- 28. 如何以編程方式在Android啓動器的主屏幕上爲特定頁面編寫快捷方式?
- 29. 如何以編程方式查詢iphone應用程序的安裝信息?
- 30. 如何以編程方式啓用和禁用USB在Android應用程序
我不會推薦後者。如果惡意應用程序使用該軟件包會怎麼樣:com.android.settings? – 2013-09-18 10:39:57
@PaoloRovelli我寫了「不一定推薦」,但出於不同的原因。我認爲你不能避免你提到的危險;如果兩個應用程序使用相同的意圖(字符串),則用戶將始終獲得一個對話框以選擇要使用的應用程序(這會降低風險)。但是,請注意,第一種方法中的參數也不過是一個字符串:http://developer.android.com/reference/android/provider/Settings.html#ACTION_APPLICATION_SETTINGS - 因此無法保護惡意應用程序如果它使用com.android.settings包名稱。 – 2013-09-18 12:33:15