开发者

starting service without application

I have a call blocking application. It has 3 files:

  1. class BlockMyCall e开发者_运维知识库xtends BroadcastReceiver
  2. class SimpleClass1 extends Service
  3. PhoneBlock extends Activity

I start "PhoneBlock " Activity to call Service "SimpleClass1", which eventually calls "BlockMyCall" intended to block outbound calls (by setting result to "null").

I want to know if I can run the class1 from service without starting activity. If so, how?


Put a broadcast receiver to READ_PHONE_STATE and on receiving this broadcast ,start the service.


In your AndroidManifest you can specify the receiver to start at boot like this:

    <receiver android:name="ProjectMonitorServiceManager"
            android:enabled="true"
            android:exported="false"
            android:label="ProjectMonitorServiceManager">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>

I'm not 100% sure that is what your looking to achieve or not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜