1

ライブラリ プロジェクトを使用して、同じコード ベースから派生した 2 つの異なる Android アプリを構築しようとしています。

アプリはさまざまな操作にインテント サービスを使用していますが、同じコード ベースを使用する 2 つのアプリを同時にインストールすると失敗するようです。

インストールしたアプリの最初のバージョンのみが機能するようで、2 番目のバージョンではサービスが実行されないようです。

誰もこれを経験したことがありますか?これはどのように解決できますか?

編集:これらはマニフェストです

ベース:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.codebase"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <supports-screens android:largeScreens="true" android:anyDensity="true" android:resizeable="true" android:smallScreens="true" android:normalScreens="true"></supports-screens>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

    <application android:icon="@drawable/icon_launcher" android:label="CodeBase" android:process="@string/app_name" android:name="com.codebase.activity.Application" android:theme="@android:style/Theme.NoTitleBar" android:debuggable="false">
        <activity android:configChanges="orientation" android:name="com.codenase.activity.MainActivity" android:launchMode="singleTask">
        <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>
        <service android:name="com.codebase.service.UpdateService" android:process="@string/app_name">
            <intent-filter>
                <action
                    android:name="com.codebase.service.UpdateService" />
            </intent-filter>
        </service>

</manifest>

ターゲット 1:

    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="10" />

    <supports-screens android:largeScreens="true" android:anyDensity="true" android:resizeable="true" android:smallScreens="true" android:normalScreens="true"></supports-screens>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

    <application android:icon="@drawable/icon_launcher" android:label="Target One" android:name="com.codebase.activity.Application" android:theme="@android:style/Theme.NoTitleBar">
        <activity android:configChanges="orientation" android:name="com.codebase.activity.MainActivity" android:launchMode="singleTask">
        <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


        <service android:name="com.codebase.service.UpdateService" android:process="@string/app_name">
            <intent-filter>
                <action
                    android:name="com.codebase.service.UpdateService" />

            </intent-filter>
        </service>

        </activity>

    </application>

</manifest>

ターゲット 2:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.trg2"
    android:versionCode="1"
    android:versionName="1.0" >


    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="10" />

    <supports-screens android:largeScreens="true" android:anyDensity="true" android:resizeable="true" android:smallScreens="true" android:normalScreens="true"></supports-screens>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

    <application android:icon="@drawable/icon_launcher" android:label="Target 2" android:name="com.codebase.activity.Application" android:theme="@android:style/Theme.NoTitleBar">
        <activity android:configChanges="orientation" android:name="com.codebase.activity.MainActivity" android:launchMode="singleTask">
        <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <service android:name="com.codebase.service.UpdateService">
            <intent-filter>
                <action
                    android:name="com.codebase.service.UpdateService" />
            </intent-filter>
        </service>

    </application>


</manifest>
4

3 に答える 3

1

まず、この状況ではAndroidManifest.xmlでサービスのintent-filterを定義する必要はありません。アプリの外部から追加のアクセスポイントを提供する必要がない場合は、次の定義で十分です。

<service android:name="com.codebase.service.UpdateService"/>

次に、public Intent(Context packageContext、Class cls)を使用してサービスを開始します。

Intent intent = new Intent(getBaseContext(), UpdateService.class);
startService(intent);

次に、アプリの外部から追加のアクセスポイントを提供する必要がある場合は、複数のアプリで同じアクション名を使用しないでください。対応するサービスにインテントを渡そうとすると、Android OSがだまされてしまいます(パブリックを使用する場合)。サービスを開始するインテント(文字列アクション)):

ターゲット1:

<service android:name="com.codebase.service.UpdateService" android:process="@string/app_name">
  <intent-filter>
    <action android:name="com.codebase.service.UpdateService.TARGET_1" />
  </intent-filter>
</service>

ターゲット2:

<service android:name="com.codebase.service.UpdateService" android:process="@string/app_name">
  <intent-filter>
    <action android:name="com.codebase.service.UpdateService.TARGET_2" />
  </intent-filter>
</service>

お役に立てれば。

于 2012-04-16T01:57:31.717 に答える
0

あなたと同じコードベースに基づいて、同じ Android アプリの 2 つのバージョンがあります。

問題はありません。両方のアプリのパッケージ名が異なります

ただし、両方のユーザー ID が同じ (共有) であることを確認します。多分それはトリックです

http://developer.android.com/guide/topics/manifest/manifest-element.html

(ちなみに、私の記憶が正しければ、userId の間にドットが必要でした)

于 2012-04-13T14:42:01.823 に答える
0

マニフェストでサービスを正しく修飾していることを確認してください。

例えば

あなたが持っていた場合:

主なプロジェクトのパッケージ名 = com.johan.p1

ライブラリ プロジェクトのパッケージ名 = com.johan.library

サービスがライブラリ プロジェクトにあると仮定すると、メイン プロジェクトはサービスを次のように定義します。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.johan.p1"

     <service android:name="com.johan.library.MyServiceName" />

</manifest>
于 2012-04-13T15:09:01.027 に答える