开发者

Creating and using a "common platform" jar in Android - what works?

开发者 https://www.devze.com 2023-01-14 23:27 出处:网络
It am sub-dividing an app I have into \"platform\" and \"app\" layers so that I can distribute the platform as a jar for use by partners - while protecting my IP.

It am sub-dividing an app I have into "platform" and "app" layers so that I can distribute the platform as a jar for use by partners - while protecting my IP.

I now have two Eclipse projects. Building has no ability to compile any resources into a jar, so I moved all resource references into the app project (the platform project gen/ directory is empty). I compiled the platform and then manually used the jdk to to jar it, imported that jar into the app project, marked the jar for export in the app project, and successfully compiled and installed a test app:

public class NotifyService extends Service {
    ...
    @Override
    public void onStart(Intent intent, int startId) {
        myNotify(intent.getIntExtra(EXTRA_ICON),...));
    }

    private void myNotify(int iconResource, String s1, String s2, String s3) {
        Context c = getApplicationContext();
        if (H.VER开发者_高级运维BOSE) Log.d(TAG, "myNotify()"); //$NON-NLS-1$
        Notification n = new Notification(iconResource, s1, currentTime);
        Intent nextStep = new Intent(Intent.ACTION_VIEW,Uri));
        PendingIntent pending = PendingIntent.getActivity(c, 0, nextStep, 0);
        n.setLatestEventInfo(c, s2, s3, pending);
        mgr.notify(1, n);
    }... 

The test activity launches as expected and I get the LogCat() message from this service. But no notification is shown and no error is logged - its just silent. ...

Anyway, I want partner apps to make use of my platform which connects to services, content providers, the web, the works. Anyone offer some guidance?

UPDATE!

Hah... typical... when I moved all the resources out of my platform and into my app I did not properly pass these down from the app layer. Thus, the code example I gave had no error. Using an intent rather than linking decouples "arguments passed" from "arguments expected" of course - and the compiler does not complain. With a corrected app, this works.

Though I'd think creating a binary distribution platform is not uncommon, I'm not finding much doc on it so I'll keep adding any significant findings as I open the doors ... hope it's of use to someone.


You should look at the concept of a "Library project".

Working with Library Projects

[Edit]

@DJC - I see...in that case I would suggest looking at the AndEngine project. The output of that project is a JAR which is then used in the AndEngineExamples project (an example app that consumes it).

AndEngine - Standalone library, distributed as a JAR

AndEngineExamples - Examples app, which consumes the AndEngine JAR


Look into using parcels, its like a Jar only its android specific. I don't have much experience with them but I think they are pretty powerful in terms of re-using activities and views and things.

"It (parcel) wraps up a JAR and other Android-related files that you need to effectively use that JAR." -Advanced Android Develoment

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号