我知道如何在普通Android设备中提取安装的Android应用列表,但是是否可以在Chromebook中获取已安装的Android应用程序列表?
这是我要安装软件包的代码...
public static List<String> getInstalledAppsPackages(Context context) {
List<String> packages = new ArrayList<>();
List<PackageInfo> packs = context.getPackageManager().getInstalledPackages(0);
for (int i = 0; i < packs.size(); i++) {
PackageInfo packageInfo = packs.get(i);
packages.add(packageInfo.packageName);
}
}
return packages;
}
我将您的代码包裹在活动中:
package com.commonsware.myapplication;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.Bundle;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for (String s : getInstalledAppsPackages(this)) {
Log.e("20171004", s);
}
}
public static List<String> getInstalledAppsPackages(Context context) {
List<String> packages = new ArrayList<>();
List<PackageInfo> packs = context.getPackageManager().getInstalledPackages(0);
for (int i = 0; i < packs.size(); i++) {
PackageInfo packageInfo = packs.get(i);
packages.add(packageInfo.packageName);
}
return packages;
}
}
我在Acer Chromebook R11 C738T上运行它,然后我得到了:
10-04 07:07:24.478 1512-1512/com.commonsware.myapplication E/20171004: android.autoinstalls.config.google.cheets
10-04 07:07:24.478 1512-1512/com.commonsware.myapplication E/20171004: com.android.cts.priv.ctsshim
10-04 07:07:24.478 1512-1512/com.commonsware.myapplication E/20171004: com.google.android.ext.services
10-04 07:07:24.478 1512-1512/com.commonsware.myapplication E/20171004: com.android.providers.telephony
10-04 07:07:24.478 1512-1512/com.commonsware.myapplication E/20171004: com.android.providers.calendar
10-04 07:07:24.478 1512-1512/com.commonsware.myapplication E/20171004: com.android.providers.media
10-04 07:07:24.478 1512-1512/com.commonsware.myapplication E/20171004: com.google.android.ext.shared
10-04 07:07:24.478 1512-1512/com.commonsware.myapplication E/20171004: com.commonsware.android.envdump
10-04 07:07:24.478 1512-1512/com.commonsware.myapplication E/20171004: com.android.wallpapercropper
10-04 07:07:24.478 1512-1512/com.commonsware.myapplication E/20171004: org.chromium.arc.view_downloads_handler
10-04 07:07:24.478 1512-1512/com.commonsware.myapplication E/20171004: com.android.documentsui
10-04 07:07:24.478 1512-1512/com.commonsware.myapplication E/20171004: org.chromium.arc.default_intent
10-04 07:07:24.478 1512-1512/com.commonsware.myapplication E/20171004: com.android.externalstorage
10-04 07:07:24.478 1512-1512/com.commonsware.myapplication E/20171004: com.android.htmlviewer
10-04 07:07:24.478 1512-1512/com.commonsware.myapplication E/20171004: com.rhmsoft.edit
10-04 07:07:24.478 1512-1512/com.commonsware.myapplication E/20171004: com.android.providers.downloads
10-04 07:07:24.478 1512-1512/com.commonsware.myapplication E/20171004: org.chromium.arc.crash_collector
10-04 07:07:24.478 1512-1512/com.commonsware.myapplication E/20171004: com.commonsware.myapplication
10-04 07:07:24.478 1512-1512/com.commonsware.myapplication E/20171004: com.android.defcontainer
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.android.vending
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.android.pacprocessor
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.android.certinstaller
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.google.android.marvin.talkback
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: org.chromium.arc.cast_receiver
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: android
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.android.camera2
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: org.chromium.arc.file_system
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.android.backupconfirm
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.android.statementservice
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.android.providers.settings
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.android.printspooler
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: org.chromium.arc.gms
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: org.chromium.arc.ime
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: org.chromium.arc.tts
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.google.android.apps.cloudprint
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.android.musicfx
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.google.android.webview
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.google.android.contacts
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.google.android.syncadapters.contacts
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.android.keychain
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.google.android.packageinstaller
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.google.android.gms
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.google.android.gsf
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.google.android.tts
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.commonsware.android.sensor.monitor
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.android.proxyhandler
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.google.android.feedback
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.google.android.printservice.recommendation
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.android.managedprovisioning
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: org.chromium.arc.applauncher
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.google.android.gsf.login
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: org.chromium.arc.accessibilityhelper
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.amaze.filemanager
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.android.storagemanager
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.android.settings
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.google.android.apps.work.clouddpc.arc
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.android.cts.ctsshim
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: org.chromium.arc.intent_helper
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: org.chromium.arc.removablemediaprovider
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.android.vpndialogs
10-04 07:07:24.479 1512-1512/com.commonsware.myapplication E/20171004: com.android.shell
所以,您的代码似乎很好。
如果这在您的特定Chrome OS设备上不起作用,则可能会有特定于设备的错误。您可以创建可重现的测试用例并在其上提出问题。