2

I can't seem to start my android service when the service code is in another package that is not the same package as the MainActivity of the main app.

I have tried many many ways, even the AIDL method, and I can't get it to work at all.

MainActivity code

ServiceIntent.setComponent(new ComponentName("com.service.luna","com.service.luna.VService" ));
bindService(ServiceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);

MainActivty Manifest

<?xml version="1.0" encoding="utf-8"?>

<!-- <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> This is set from Gradle -->
<!-- Needed for camera passthrough -->
<!--<uses-permission android:name="android.permission.CAMERA" />-->
<!-- Needed to write thumbs -->

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Needed to for volume -->
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<!-- Needed for Google Play Services GPS -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.usb.host" />
<!-- Needed for uploading crash reports -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

<uses-feature android:glEsVersion="0x00030000" android:required="true" />
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name"
    android:hardwareAccelerated="true" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
    <meta-data android:name="com.samsung.android.vr.application.mode" android:value="vr_only" />
    <!-- singleTask launchMode because we never want multiple copies of the app running, -->
    <!-- but we might want to internally spawn other activities -->
    <!-- Theme.DeviceDefault.NoActionBar.Fullscreen gives solid black instead of a (bad stereoscopic) gradient on app transition -->
    <activity android:name="com.main.luna.MainActivity"
              android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
              android:label="@string/app_name"
              android:launchMode="singleTask"
              android:screenOrientation="landscape"
              android:configChanges="screenSize|orientation|keyboardHidden|keyboard"
              >
        <!-- this filter lets the apk show up as a launchable icon -->
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <action android:name="com.service.luna.VService" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <service android:name="com.service.luna.VService" android:process=":VServiceRemote" android:exported="true" android:enabled="true">
        <intent-filter>

            <action android:name="com.service.luna.VService"/>
            <action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
            <action android:name="android.intent.action.USER_PRESENT" />
            <action android:name="android.intent.action.BOOT_COMPLETED" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </service>

    <receiver android:name="com.main.luna.ConnectivityChangeReceiver" >
        <intent-filter>
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
        </intent-filter>
    </receiver>

</application>

Service Code

public class VService extends Service implements Serializable{

....

Service Manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.service.luna">

<application
    android:allowBackup="true"
    android:label="@string/app_name"
    android:supportsRtl="true">


</application>

When My code finally runs, I receive a

bindService callerProcessName:com.main.luna, calleePkgName: com.service.luna, action: null
Unable to start service Intent { pkg=com.service.luna cmp=com.service.luna/.VService } U=0: not found

The name of the main package is com.main.luna and the service is in package com.service.luna

If someone has solved this before, please let me know.

Perjia
  • 31
  • 1
  • 2
  • I solved this retardation.....that is google android developement. I had to start the intent inside the mainactivity package as ServiceIntent.setComponent(new ComponentName("com.main.luna","com.service.luna.VService" )); – Perjia Jan 26 '16 at 22:35
  • that was already in you original post above - unless you edited afterwards –  Jan 06 '21 at 11:43
  • solved already then? Please post the ans for others might get helped too... – gumuruh Jan 11 '21 at 16:01

1 Answers1

0

Try to enable the exported option in your manifest while adding your service ( android:exported="true")

  <service android:enabled=["true" | "false"]
     android:exported=["true" | "false"]
     android:icon="drawable resource"
     android:isolatedProcess=["true" | "false"]
     android:label="string resource"
     android:name="string"
     android:permission="string"
     android:process="string" >
. . .
  </service>

and make sure you are using the Correct name of your Package name

Also check this post having similar situation

How do I start a service which is defined in a different package?

Community
  • 1
  • 1
  • If you looked at my service tag in the main's manifest, it is already there. Doesn't work. – Perjia Jan 26 '16 at 20:26
  • maybe the problem is inside your service code that prevents it from starting – Tamer Hatoum Jan 26 '16 at 20:31
  • I was using the service code for a while and it was working before I decided to move it to another package to make it more module. I just to know the solution to this problem. I can't find a solution anywhere. – Perjia Jan 26 '16 at 20:40
  • could you please check this link : http://stackoverflow.com/questions/8359786/android-unable-to-start-service-intent-not-found – Tamer Hatoum Jan 26 '16 at 20:50