我创建了短消息接收器应用程序... 但我想把它创建为一种服务, 它应该在背景中运行( 也就是说, 此应用程序没有单独的 UI, 想要像提醒程序一样工作), 即使移动重新启动自动启动... 任何人都能帮上忙吗?
My previous SMS Receiver app code was here Unable to instantiate activity ComponentInfo in Android Receive Sms App
我创建了短消息接收器应用程序... 但我想把它创建为一种服务, 它应该在背景中运行( 也就是说, 此应用程序没有单独的 UI, 想要像提醒程序一样工作), 即使移动重新启动自动启动... 任何人都能帮上忙吗?
My previous SMS Receiver app code was here Unable to instantiate activity ComponentInfo in Android Receive Sms App
它应该在背景中运行
您现有的Broadcast Recepier
, 用于 (未记录的) android. provider.telephony. SMS_RECEIVED
的 < broadcast Recepier , 用于( 未记录的) < code> 和roid. provider.tephon. SMS_ RECEIVED 。 已经在背景中运行 。
即使移动重新启动也自动启动
您现有的 Broadcast Recepier
用于 (未记录的) android. provider.telephony. SMS_RECEIVED
的 < roid. provider. telphony.. SMS_RECEIVED 在设备重新启动后已经可用 。
如果您想要在电话启动时运行您的服务, 您应该简单地声明一个带有此意向过滤器的广播接收器 :
<receiver android:name="MyStartupIntentReceiver">
<intent-filter>
<action
android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
在收件()方法的广播接收器中,请发射您的服务:
public void onReceive(Context context, Intent intent) {
Intent serviceIntent = new Intent();
serviceIntent.setAction("myPackage.MyService");
context.startService(serviceIntent);
}
且一定要将您在列表中的服务与您在广播接收器中启动的意向的相同名称联系起来:
<service android:name="MyService">
<intent-filter>
<action
android:name="myPackage.MyService" />
</intent-filter>
</service>
正如CommonsWare所说,无需在背景中实际运行“服务”来接收短消息广播,如果在您的列表中以“android.provider.telephony.SMS_RECEIVED.SMS_REEIVED”正确登记在您的广播接收器上,因为每次收到短消息时,只要没有收到其他必要行动,意图过滤器就会开火。
取决于您到底想做什么, 从那个广播接收器那里, 您可以通过一个实际的服务来工作, 或者可能更好的选择就是使用一个意图服务。 这是因为用于广播的线条在开始后不久就会被杀死, 所以您不应该在其中做任何广泛的工作 。
除非有明确要求, 否则一般建议不要使用实际的“服务”...如果这是你需要的...BUT, 那么你需要Davide 应该给你正确的方向.
I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...
I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...
I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...
I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...
To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?
When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...
I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...
I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...