[英]how can i use .apk file into my own application android?
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. 在developer.android.com中,我阅读了android的主要功能,即可以在自己的应用程序中使用其他应用程序的元素。 1)How can we use the .apk downloaded suppose from android market in to our application ? 1)我们如何在Android应用程序中使用从Android市场下载的.apk? 2)How can we use our own created applicaton into newly created application? 2)我们如何在新创建的应用程序中使用自己创建的应用程序?
please give me guidance on this and if possible sample snippet? 请为此提供指导,如果可能的话,请提供示例代码?
Regards, Rajendar 此致Rajendar
I guess you mean that : 我想你的意思是 :
A central feature of Android is that one application can make use of elements of other applications (provided those applications permit it). Android的主要功能是一个应用程序可以利用其他应用程序的元素(前提是这些应用程序允许)。 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. 相反,它只是在需要时启动其他应用程序的那一部分。
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
. 他/她可以通过将“意图过滤器”放入其应用程序的AndroidManifest.xml
。 Eg 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: 例如,Google的Camera应用程序(也提供相机功能和图片库的应用程序-是的,该应用程序可以在主屏幕上“暴露”许多“入口点” =图标)具有以下活动定义(其中之一):
<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
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: 可以在一个人的Activity中定义的CROPPING_RESULT_CODE
用于区分返回的外部活动(如果一个人调用了多个外部函数,则为onActivityResult()
),并在调用活动的onActivityResult()
方法中提供,该方法在“远程”应用程序完成时被调用-下面的示例:
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 ... */
}
}
Other options are using: other Services or ContentProviders. 其他选项正在使用:其他服务或ContentProvider。
If you have any more questions don't hesitate. 如果您还有其他疑问,请不要犹豫。
Android uses Intents to allow applications request work be done by software residing in other applications. Android使用Intents允许应用程序请求工作由其他应用程序中的软件完成。 See my answer to this question for more details on Intents and an example of how your application can ask the Browser application to display a webpage. 请参阅我对这个问题的回答,以获取有关Intent的更多详细信息,以及有关您的应用程序如何要求Browser应用程序显示网页的示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.