冰浪

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

          日歷

          <2010年2月>
          31123456
          78910111213
          14151617181920
          21222324252627
          28123456
          78910111213

          公告


          public class PM(){
          String tag = "移動互聯網,產品經理,80后,深圳";
          }

          文章檔案

          IT友人

          搜索

          •  

          積分與排名

          • 積分 - 100033
          • 排名 - 578

          最新評論

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

          Posted on 2010-02-01 17:23 冰浪 閱讀(11031) 評論(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
          總結的真好,謝謝
          主站蜘蛛池模板: 高要市| 宁蒗| 佛山市| 高邮市| 松原市| 新平| 莲花县| 宁乡县| 紫阳县| 黄骅市| 定南县| 大冶市| 康马县| 高州市| 永兴县| 汤阴县| 德格县| 荣成市| 夏津县| 庆云县| 海安县| 新源县| 广宁县| 鄂托克前旗| 洛浦县| 襄樊市| 长治县| 赫章县| 抚顺市| 衡南县| 武山县| 大余县| 延安市| 准格尔旗| 阜新| 三河市| 友谊县| 建瓯市| 宁乡县| 桐柏县| 南安市|