53 votes

Comment lancer l'écran d'information d'une application Android de manière programmatique ?

Est-il possible de lancer l'écran "info sur l'application" (c'est-à-dire, MenuSettingsApplicationsManage Applications → sélectionner n'importe quelle application) d'une autre application ?

81voto

ZhengZhiren Points 619

Dans les versions 2.2 et inférieures, il n'y a pas d'API publiques auxquelles vous pouvez accéder. Mais vous pouvez toujours lancer le InstalledAppDetails tout comme l'activité ManageApplications voit. ici

 // 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);
 }

Conclusion Vous pouvez démarrer l'écran "info sur l'application" comme je l'ai écrit :

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);
}

65voto

Paolo Rovelli Points 892

De Niveau 9 de l'API (Android 2.3), vous pouvez démarrer un Intent avec Paramètres Android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS . Ainsi :

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);

}

15voto

Jared Rummler Points 661

Vieille question, réponse améliorée :

/**
 * <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;
}

8voto

CommonsWare Points 402670

Sous Android 2.3, vous pouvez utiliser startActivity() sur un ACTION_APPLICATION_DETAILS_SETTINGS Intent , avec un Uri pour faire apparaître l'écran "gérer" de votre application. Cependant, ceci est une nouveauté d'Android 2.3 -- je ne suis pas au courant d'un moyen de faire cela dans les versions précédentes d'Android.

6voto

Mathias Lin Points 16035
startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_SETTINGS));

vous amènera à la liste des paramètres / applications. Si vous voulez ouvrir une application spécifique, je pense que dans les versions 2.2 et inférieures, il n'y a pas de moyen, donc vous devez suivre un chemin (pas nécessairement suggéré, car non officiel) :

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);

Mais notez que cela n'est pas recommandé car il ne s'agit pas d'une API / intention (filtre) officielle et pourrait donc changer à l'avenir.

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X