2010-06-26 79 views
1

在developer.android.com中,我讀到了android的核心功能,就是可以在自己的應用程序中使用其他應用程序的元素。對此行感興趣。 1)我們如何使用從Android市場下載的.apk應用程序? 2)我們如何將我們自己創建的應用程序用於新創建的應用程序?我如何使用.apk文件進入我自己的應用程序android?

請給我這個指導,如果可能的話樣本片段?

問候, Rajendar

回答

0

Android使用Intents允許應用程序請求的工作由居住在其它應用軟件來完成。請參閱my answer to this question瞭解Intents的更多詳細信息,以及您的應用程序如何讓瀏覽器應用程序顯示網頁的示例。

1

我猜你的意思that

的Android的核心特徵是 一個應用程序可以使用其他應用程序 元素(所提供的應用程序允許 它)。例如,如果你的應用程序 需要顯示 圖像的滾動列表和其他應用程序具有 開發出了適合滾動並取得 提供給別人,你可以調用 在該卷軸做的工作, 而不是發展自己的擁有。您的 應用程序不包含其他應用程序的 代碼或鏈接 。相反,它只是在需要時啓動 那件其他應用程序 。

最後兩句是至關重要的。鏈接提供了更多關於它的信息。但是簡單地說:應用程序作者可以以其可以被其他人重用的方式編寫他的代碼。他/她可以通過將「意圖過濾器」放入他/她的應用程序的AndroidManifest.xml中來做到這一點。例如。谷歌的相機應用程序(也提供相機功能和圖庫的應用程序 - 是的,應用程序可以「暴露」主屏幕中的許多「入口點」=圖標)具有活動定義(許多中的一個),如下所示:

<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> 

這意味着,可以使用它通過發送意圖裁剪圖像的功能:

/* 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()中提供在「遠程」應用程序完成時調用的od - 例如:

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。

如果您有任何疑問,請不要猶豫。

相關問題