使Android服务可用于其他应用程序

使Android服务可用于其他应用程序,android,android-service,Android,Android Service,我已经浏览了StackOverflow和其他论坛,到目前为止,我所看到的一切对我都没有帮助。我的公司有一个带有活动和服务的应用程序,我们的一个客户希望能够使用他们自己的应用程序使用服务部分。所以我正在尝试编写一个单独的应用程序来测试它是如何工作的,但我无法让它工作。这是舱单的相关部分 <service android:name="com.gpssolutions.rtrover.RTRoverService" android:process=":RTRoverServic

我已经浏览了StackOverflow和其他论坛,到目前为止,我所看到的一切对我都没有帮助。我的公司有一个带有活动和服务的应用程序,我们的一个客户希望能够使用他们自己的应用程序使用服务部分。所以我正在尝试编写一个单独的应用程序来测试它是如何工作的,但我无法让它工作。这是舱单的相关部分

<service android:name="com.gpssolutions.rtrover.RTRoverService"
         android:process=":RTRoverServiceProcess"
         android:exported="true"
         android:enabled="true">
</service>
我尝试只指定服务的名称和完整路径。我尝试了setComponent和setClassName。我尝试了不同的XML设置组合,包括删除流程部分。什么都不管用

如果我运行“adb外壳服务列表”,则不会列出该服务。当我尝试从活动启动服务时,我得到以下信息:

W/ActivityManager: Unable to start service Intent { cmp=com.gpssolutions.rtrover/.RTRoverService (has extras) } U=0: not found"
Android版本是4.4.4

多谢各位

编辑:

这是我的应用程序的全部清单,其中包含其他应用程序希望访问的服务

<?xml version='1.0' encoding='utf-8'?>
<manifest package="com.gpssolutions.RTRover"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:versionName="1.0"
    android:versionCode="1"
    android:installLocation="auto"
>
    <application android:hardwareAccelerated="true"
        android:name="org.qtproject.qt5.android.bindings.QtApplication"
        android:icon="@drawable/app_rtrover"
        android:label="RTRover"
    >
        <activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation"
            android:name="com.gpssolutions.rtrover.RTRoverActivity"
            android:label="RTRover"
            android:icon="@drawable/app_rtrover"
            android:screenOrientation="portrait"
            android:launchMode="singleTop"
        >
           <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
            <meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
            <meta-data android:name="android.app.repository" android:value="default"/>
            <meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
            <meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
            <!-- Deploy Qt libs as part of package -->
            <meta-data android:name="android.app.bundle_local_qt_libs" android:value="-- %%BUNDLE_LOCAL_QT_LIBS%% --"/>
            <meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
            <meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
            <!-- Run with local libs -->
            <meta-data android:name="android.app.use_local_qt_libs" android:value="-- %%USE_LOCAL_QT_LIBS%% --"/>
            <meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
            <meta-data android:name="android.app.load_local_libs" android:value="-- %%INSERT_LOCAL_LIBS%% --"/>
            <meta-data android:name="android.app.load_local_jars" android:value="-- %%INSERT_LOCAL_JARS%% --"/>
            <meta-data android:name="android.app.static_init_classes" android:value="-- %%INSERT_INIT_CLASSES%% --"/>
            <!--  Messages maps -->
            <meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
            <meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
            <meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
            <meta-data android:name="android.app.background_running" android:value="false"/>
        </activity>
        <service android:name="com.gpssolutions.rtrover.RTRoverService"
             android:process=":RTRoverServiceProcess"
             android:exported="true"
             android:enabled="true">
        </service>
    </application>
    <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="14"/>
    <supports-screens android:largeScreens="true"
        android:normalScreens="true"
        android:anyDensity="true"
        android:smallScreens="true"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</manifest>

在清单中,您可以指定

package="com.gpssolutions.RTRover"
但是,当您的其他应用程序尝试启动您的
服务
时,它会使用以下程序包名称创建
意图
“com.gpssolutions.rtrover”
,代码如下:

intent.setComponent(new ComponentName("com.gpssolutions.rtrover", 
                  "com.gpssolutions.rtrover.RTRoverService"));
注意:包名称区分大小写。

尝试按以下方式启动服务:

intent = new Intent();
intent.setComponent(new ComponentName("com.gpssolutions.RTRover",
              "com.gpssolutions.rtrover.RTRoverService"));
intent.putExtra("inpStr", input);
startService(intent);

所以你想让一个应用在另一个应用中启动服务?你看过广播接收机了吗?安卓表示它找不到你的服务。未安装带有该服务的应用程序,或者您的
意图
对象与
元素不匹配。FWIW,演示远程服务。在我的例子中,我使用的是
bindService()
而不是
startService()
,并且在
元素中没有使用
android:process
。另外,我使用隐式的
意图
引导查找正确的服务(而不是让客户端硬编码服务名称)。请发布应用程序中包含服务的整个清单。@Shmuel为什么需要使用
广播接收器
来启动
服务
?这毫无意义。那么,一项服务是否需要一个意图过滤器供其他应用程序使用呢?我可以通过应用程序自己的活动使用该服务。只是我的另一个应用程序似乎看不到服务。这就解决了它。谢谢
intent = new Intent();
intent.setComponent(new ComponentName("com.gpssolutions.RTRover",
              "com.gpssolutions.rtrover.RTRoverService"));
intent.putExtra("inpStr", input);
startService(intent);