冰浪

          哥已不再年輕 - 堅定夢想,畢生追求!
          posts - 85, comments - 90, trackbacks - 0, articles - 3
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          Android中外部程序調用方法總結

          Posted on 2010-02-01 17:23 冰浪 閱讀(11041) 評論(1)  編輯  收藏 所屬分類: Android
          要做一個android的播放器獨立應用程序,要求外部程序可以調用此播放器進行視頻播放。因此涉及到外部程序調用的知識點。經過多次測試,現總結方法如下:

          1.使用自定義Action

          A程序中調用的代碼為:
          1 Intent intent = new Intent();
          2 intent.setAction("com.test.action.PLAYER");               
          3 startActivity(intent);

          B程序中的AndroidManifest.xml中啟動Activity的intent-filter:
          1 <intent-filter>
          2                 <action android:name="android.intent.action.MAIN" />
          3                  <action android:name="com.test.action.PLAYER" />
          4                  <category android:name="android.intent.category.DEFAULT" /><!--必須,否則無效-->
          5                 <category android:name="android.intent.category.LAUNCHER" />
          6 </intent-filter>



          2.使用包類名
          A程序中調用的代碼為:
          1 Intent intent = new Intent();
          2 intent.setClassName("com.test""com.test.Player");
          3 startActivity(intent);
          intent.setClassName(arg1,arg2)中的arg1是被調用程序B的包名,arg2是B程序中目的activity的完整類名。

          又或者:
          1 Intent intent = new Intent();         
          2 ComponentName comp = new ComponentName("com.test""com.test.Player" ); 
          3 intent.setComponent(comp); 
          4 startActivity(intent);


          B程序(被調用)中的AndroidManifest.xml中啟動Activity的intent-filter不需要特別加入其它信息,如下即可:
          1 <intent-filter>
          2     <action android:name="android.intent.action.MAIN" />
          3     <category android:name="android.intent.category.LAUNCHER" />
          4 </intent-filter>


          建議使用第一種方式。

          評論

          # re: Android中外部程序調用方法總結  回復  更多評論   

          2010-02-08 15:05 by beeboo
          總結的真好,謝謝
          主站蜘蛛池模板: 巴里| 松原市| 黄梅县| 武陟县| 宣化县| 广宗县| 江西省| 怀柔区| 大英县| 南充市| 卢龙县| 云林县| 乌鲁木齐县| 肇源县| 永靖县| 宜黄县| 沛县| 敦化市| 磐安县| 屏东市| 绥江县| 普格县| 内黄县| 宁德市| 玉田县| 元谋县| 城口县| 赤峰市| 苍溪县| 肥东县| 蒲城县| 南澳县| 阿克陶县| 阿图什市| 临沂市| 资阳市| 两当县| 磐安县| 双桥区| 琼结县| 昌吉市|