我如何使用的.apk文件到自己的应用程序的Andr​​oid? [英] how can i use .apk file into my own application android?

查看:189
本文介绍了我如何使用的.apk文件到自己的应用程序的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在developer.android.com我读的Andr​​oid的核心特点是,你可以使用其他应用程序在自己的application.Iam兴趣在此行的元素。 1)我们如何使用.apk文件下载的从Android Market在我们的应用设想? 2)我们如何利用我们自己创建的一个应用到新创建的应用程序?

In developer.android.com I read central feature of android is you can make use of elements of other applications in your own application.Iam interested in this line. 1)How can we use the .apk downloaded suppose from android market in to our application ? 2)How can we use our own created applicaton into newly created application?

请在这一点,如果可能的示例代码段给我指点一下?

please give me guidance on this and if possible sample snippet?

问候, Rajendar

Regards, Rajendar

推荐答案

我猜你的意思的

安卓的一个主要特点是,   一个应用程序可以使用   其他应用程序的元素   (前提是这些应用程序的许可证   它)。例如,如果你的应用程序   需要显示的滚动列表   图像和另一个应用程序有   开发出了适合卷轴,并提出   它提供给别人,你可以调用   在那卷轴做的工作,   而不是开发自己。您的   应用不配备   $ C $其他应用程序或链接了C   给它。相反,它只是启动   那件其他应用程序的   在需要时

A central feature of Android is that one application can make use of elements of other applications (provided those applications permit it). For example, if your application needs to display a scrolling list of images and another application has developed a suitable scroller and made it available to others, you can call upon that scroller to do the work, rather than develop your own. Your application doesn't incorporate the code of the other application or link to it. Rather, it simply starts up that piece of the other application when the need arises.

最后两句是至关重要的。和链接提供了有关它的更多信息。但简单:应用程序作者可以写上自己的code的方式,它可以重复使用的为别人着想。他/她可以做到这一点通过将意图过滤器到他/她的应用程序的的Andr​​oidManifest.xml 。例如。谷歌的相机应用程序(它提供相机功能和图片库,以及一个 - 是的,应用程序可以揭发多切入点=图标在主屏幕)的活动定义(其中之一),如下所示:

Two last sentences are crucial. And the link provides more information about it. But briefly: application author can write his code in a manner that it can be reusable for others. He/she can do that by putting "intent filters" into his/her application's AndroidManifest.xml . E.g. Google's Camera application (the one that provides camera functionality and image gallery as well - yeah, the application can "expose" many "entry points" = icons in the home screen) has activity definition (one of many) as follows:

<activity android:name="CropImage" android:process=":CropImage" android:configChanges="orientation|keyboardHidden" android:label="@string/crop_label">
    <intent-filter android:label="@string/crop_label">
        <action android:name="com.android.camera.action.CROP"/>
        <data android:mimeType="image/*"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.ALTERNATIVE"/>
        <category android:name="android.intent.category.SELECTED_ALTERNATIVE"/>
    </intent-filter>
</activity>

这意味着,你可以使用它的裁切图像功能,通过发送意图:

That means that one can use it's cropping the image functionality by sending intent:

/* prepare intent - provide options that allow 
Android to find functionality provider for you;
will match intent filter of Camera - for matching rules see: 
http://developer.android.com/guide/topics/intents/intents-filters.html#ires */
Intent i = new Intent("com.android.camera.action.CROP");
i.addCategory(Intent.CATEGORY_DEFAULT);
i.setType("image/*");
/* put "input paramters" for the intent - called intent dependent */
i.putExtra("data", /*... Bitmap object ...*/);
i.putExtra( /*... other options, e.g. desired dimensions ...*/ );
/* "call desired functionality" */
startActivityForResult(i, /* code of return */ CROPPING_RESULT_CODE);

CROPPING_RESULT_ code ,人们可以在一个人的活动定义用来区分哪些外部活动返回(有益的,如果一个叫几个外部函数),并呼吁提供活动的 onActivityResult()方法,该方法被调用的时候远程应用程序完成 - 下面的例子:

CROPPING_RESULT_CODE that one can define in one's Activity is used to distinguish which external activity returned (helpfull if one calls several external functions) and is provided in calling activity's onActivityResult() method which is called when "remote" application finishes - below an example:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case CROPPING_RESULT_CODE:
        /* ... crop returned ... */
        if (data != null) {
            /* get cropped bitmap */
            Bitmap bmp = data.getParcelableExtra("data");       
            /* ... and do what you want ... */
        }
    case ANOTHER_RESULT_CODE:
        /* ... another external content ... */

    }
}

其他选项使用:其它服务或ContentProviders

Other options are using: other Services or ContentProviders.

如果您有任何问题请不要犹豫。

If you have any more questions don't hesitate.

这篇关于我如何使用的.apk文件到自己的应用程序的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆