バックグラウンド サービスを開始する必要がある AIR ネイティブ拡張に取り組んでいます。
サービスを開始するさまざまな方法を試しました。
これが私の AIR Android マニフェスト セクションです (私の -app.xml ファイルから)
//AIR android manifest section
<manifest android:installLocation="auto">
<application>
<activity android:name=".TestActivity">
<intent-filter>
<action android:name=".TestActivity"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<service android:name=".TestService">
<intent-filter>
<action android:name="test.default.service"/>
</intent-filter>
</service>
</application>
</manifest>
Service Class は Activity と同じパッケージにあります。アクティビティは問題なく実行され、アクティビティの onStart() メソッドで、次のメソッドを使用してサービスを開始しようとしました。
方法 1:
import android.app.Activity;
public class TestActivity extends Activity
{
@Override
protected void onStart()
{
super.onStart();
Intent intent = new Intent("test.default.service");
//clearly the classes are available because this compiles!
intent.setClass(TestActivity.this, TestService.class);
startService(intent);
}
}
結果:
Unable to start service Intent { act=test.default.service cmp=air.com.my.company/com.my.company.TestService } U=0: not found
方法 2:
import android.app.Activity;
public class TestActivity extends Activity
{
@Override
protected void onStart()
{
super.onStart();
//start a service with intent
startService(new Intent("test.default.service"));
}
}
結果:
FATAL EXCEPTION: main
java.lang.RuntimeExeption: Unable to instantiate service air.com.my.company.TestService:
java.lang.ClassNotFoundException:
Didn't find class "air.com.my.company.TestService" on path: /data/app/air.com.my.company-1.apk
問題はその「空気」にあるようです。サービスを開始しようとすると、パッケージ名にプレフィックスが付けられます。独自のカスタム サービスを実行しているときに、このパッケージ名の混乱を回避するにはどうすればよいですか?
私はアドビのフォーラムだけでなく、スタック オーバーフローにも遭遇しましたが、この問題に対する完全な解決策を見つけることができないようです。
このトピックに触れている他の投稿がいくつかありますが、ソースを使用して実際に実行中のソリューションを提供するものはありません。
問題の原因となる余分な可動部分がないことを確認するために、これをできる限り単純なケースに切り詰めました。
AIR で実行されている拡張コンテキストから Android サービスを開始する方法に関する公式情報は役に立ちます。Adobe でさえ、この問題について口を閉ざしているようです。