参见英文答案 > How to start a Service when .apk is Installed for the first time 10个
我正在开发一种防盗应用程序,该应用程序基于使用广播接收器为传入的 SMS启动服务.
但是如果手机已经丢失,则从 Google Play 远程安装应用程序时广播接收器将无法工作,因为必须至少启动一次应用程序才能接收3.0版的广播.
那么,有没有办法在安装后立即启动应用程序使用一些“帮助应用程序”或使广播接收器工作进行远程安装?
的使用权限.
一旦你有了,你就可以注册android.provider.Telephony.SMS_RECEIVED的广播接收器.
然后你会想要创建你的 receiver .
<receiver android:name=".SMSBroadcastReceiver"> <intent-filter> <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </intent-filter> </receiver>
接收机应该扩展 BroadcastReceiver ,并在的onReceive()方法时,您将收到您要检索的消息,并确定它是否是您要注意一个android.provider.Telephony.SMS_RECEIVED_ACTION的意图.
您的代码可能看起来像这样.
public class SMSBroadcastReceiver extends BroadcastReceiver { private static final String TAG = "SMSBroadcastReceiver"; private static final String SMS_RECEIVED_ACTION = "android.provider.Telephony.SMS_RECEIVED" @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(SMS_RECEIVED)) { Bundle bundle = intent.getExtras(); if (bundle != null) { Object[] pdus = (Object[]) bundle.get("pdus"); final SmsMessage[] messages = new SmsMessage[pdus.length]; for (int i = 0; i < pdus.length; i++) { messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); } if (messages.length > -1) { //You have messages, do something with them here to determine if you want to look at them and other actions. } } } } }
翻译自:https://stackoverflow.com/questions/17851221/is-there-a-way-to-start-the-application-right-after-installation-using-some-hel