冰浪

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

          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
          總結的真好,謝謝
          主站蜘蛛池模板: 巩义市| 昌吉市| 东丰县| 麻栗坡县| 普洱| 波密县| 新泰市| 闻喜县| 湖南省| 南部县| 博乐市| 遵化市| 克东县| 东莞市| 女性| 宜章县| 隆德县| 将乐县| 黄山市| 新野县| 淮南市| 宜春市| 屏东市| 尼木县| 海门市| 和林格尔县| 白河县| 隆昌县| 临海市| 东阳市| 水城县| 通化市| 丰城市| 夏邑县| 格尔木市| 淳安县| 宝鸡市| 岗巴县| 饶河县| 嘉兴市| 襄城县|