0

If an app has an exported service in the android manifest that means I can run that service from within another app right? For example the service looks like this in the manifest file.

<service
            android:name=".account.contactsync.ContactsSyncAdapterService"
            android:exported="true"
            android:process=":contacts" >
            <intent-filter>
                <action android:name="android.content.SyncAdapter" />
            </intent-filter>

            <meta-data
                android:name="android.content.SyncAdapter"
                android:resource="@xml/sync_contacts" />
            <meta-data
                android:name="android.provider.CONTACTS_STRUCTURE"
                android:resource="@xml/contacts" />
        </service>

As you can see the service is set to android:exported="true" which means I should be able to run it from outside of the app right? How do I do that

I tried this and it didn't work

final Intent intent = new Intent();

                    ComponentName cName = new ComponentName
                            ("com.myapp","com.myapp.ContactsSyncAdapterService");

                    intent.setComponent(cName);
                    startActivity(intent);

1 Answers1

0

You're missing an .account.contactsync in your component name:

ComponentName cName = new ComponentName("com.myapp",
    "com.myapp.account.contactsync.ContactsSyncAdapterService");

And you'd need to use startService() instead of startActivity() - startActivity() only starts activities.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • Hi there, thanks for your response. But it's still failing to run the sync service. I'd like to make the app refresh it's contacts by running the service from outside of the app. It still seems to not respond to it – shoriwa-shaun-benjamin Nov 03 '14 at 23:27
  • I assume you've already read the [running a sync adapter training](http://developer.android.com/training/sync-adapters/running-sync-adapter.html) and evaluated each method of starting your sync adapter? – ianhanniballake Nov 03 '14 at 23:31
  • Yes I have. Its actually the sync adapter for this app [link](https://github.com/mar-v-in/XMPP-for-Android/blob/master/AndroidManifest.xml) – shoriwa-shaun-benjamin Nov 03 '14 at 23:38
  • I figured ContentResolver.requestSync(ACCOUNT, AUTHORITY, null); wouldng work because I'd be running it from another app – shoriwa-shaun-benjamin Nov 03 '14 at 23:39