سؤال

I am working on an android application for my company which connects to a bluetooth video device. A 3rd party company that we are working with built the bluetooth camera and have built a service (android service) that our app connects to which we use to interact with the camera. This company did not want us to have access to the source code so they created an SDK in the form of a service which must be installed on the phone for interaction with the camera to take place. If the service (which is just an APK) is not installed our app won't work.

However, we can detect that the service does not exist and then proceed to get the apk and now we are trying to figure out the best way to do that. Is it possible we could have the other company publish this service in the android market even though it has no ui and when installed would appear to do nothing? Can you put something in the android market and not have it show up under normal filters (meaning the only way to get to it would be by going directly to the page?). I don't think they want people installing it since the 3rd party company does sell there own camera (almost the same as the one they make for us) and they have applications in the market for it.

The other possibility is we host the file ourselves and download it when the user first installs the app.. The problem with that though is we have to figure out our own methodology for upgrades.

Does anyone have experience with this or have any ideas what might be the best way to handle our situation?

هل كانت مفيدة؟

المحلول 2

I ended up solving the issue by bundling the service apk under the /assets folder of my application. You can read from that data as an inputstream and write it to sdcard where you can then launch the intent to have the apk installed. All the user has to do is click Install (as long as they have 3rd party apps allowed, which they will since our app is not in the market either.

public static final String SERVICE_APK_FILENAME = "SomeService.apk";

protected void installService() {

    File apk = getServiceFileOnDisk();
    if (!apk.exists()) {
        try {
            writeServiceToFile();
        } catch (Exception ex) {
            Log.e(TAG, "", ex);                
            return;
        }
    }

    Intent promptInstall = new Intent(Intent.ACTION_VIEW);
    promptInstall.setDataAndType(Uri.fromFile(getServiceFileOnDisk()),
            "application/vnd.android.package-archive");
    startActivityForResult(promptInstall, REQUEST_INSTALL_APK);
}

protected File getServiceFileOnDisk() {
    return new File(Util.getAppStorageDirectory(this), SERVICE_APK_FILENAME);
}

protected void writeServiceToFile() throws IOException {
    File apk = getServiceFileOnDisk();
    InputStream assetIs = mAssetMgr.open(SERVICE_APK_FILENAME);
    OutputStream out = new FileOutputStream(apk);
    // Transfer bytes from in to out
    byte[] buf = new byte[4 * 1024];
    int len;
    while ((len = assetIs.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    assetIs.close();
    out.close();       
}

So what happens is when the app first launches I check if the service needs to be installed (or upgraded).. That code is a bit more complex and outside the scope of what I'm doing here so I didn't post it. But if I determine the service needs to be installed I prompt the user with a dialog and if they click ok I then call the installService method shown above.

نصائح أخرى

If you are in that situation I would recommend hosting the apk from your company server.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top