質問

I have been using Google service in my project, but Amazon tablets don't support Google service so that if I want to publish app to Amazon Store, I need to remove Google service. I don't want to divide project to "For Google Play" and "For Amazon Store".
I get device name using android.os.Build.MODEL but I'm not sure it's safe?
Can I detect Amazon tablets in project?

if(is Amazon) {
    //do something
}
else {
    //do something
}
役に立ちましたか?

解決

Yes, you can use Build.MODEL and Build.MANUFACTURER.

As per Amazon documentation, Build.MANUFACTURER always returns "Amazon", and Build.MODEL returns different strings, depending on the model.

If you don't need to distinguish between each Amazon tablet, you can just use:

if (Build.MANUFACTURER.equals("Amazon")) {
    //we have an Amazon tablet
}
else {
    //some other device
}

If you need to know exactly which device it is, you can use Build.MODEL, for example:

  • Kindle Fire HDX 8.9 (3rd Gen)

    if (Build.MODEL.equals("KFAPWI")) {
        //WiFi version
    }
    else if (Build.MODEL.equals("KFAPWA")) {
        //WAN version
    }
    

    etc.

他のヒント

You can use ..

String deviceName = android.os.Build.MODEL;
String deviceMan = android.os.Build.MANUFACTURER;

For more details please visit android.os.Build

I would suggest you to detect wether google Play is installed. Because a few Custom Roms do not have intsalled Google Play either. So try it with this lines of code:

private static final String GooglePlayStorePackageNameOld = "com.google.market";
private static final String GooglePlayStorePackageNameNew = "com.google.vending";

public boolean serviceAvailable(Context ctx) {
    boolean googlePlayStoreInstalled= false;
    packageManager = ctx.getPackageManager();
    List<PackageInfo> packages = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
    for (PackageInfo packageInfo : packages) {
        if (packageInfo.packageName.equals(GooglePlayStorePackageNameOld) ||
            packageInfo.packageName.equals(GooglePlayStorePackageNameNew)) {
            googlePlayStoreInstalled = true;
            break;
        }
    }
    return googlePlayStoreInstalled;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top