2013-07-25 34 views
8

我正在開發一種基於使用廣播接收器爲傳入SMS啓動服務的防盜應用程序。有沒有辦法在使用一些「幫助程序」安裝後立即啓動應用程序?

但是,如果手機已經丟失,當從Google Play遠程安裝應用程序時,廣播接收器將無法工作,因爲應用程序必須至少啓動一次才能接收3.0+版本的廣播。

那麼,有沒有一種方法可以在安裝後使用一些「幫助應用程序」啓動應用程序,或者使廣播接收器工作以進行遠程安裝?

+0

http://stackoverflow.com/questions/11872320/auto-launching-android-app-after-install – KOTIOS

+0

有對谷歌玩[Android的失落(https://play.google的應用程序。 com/store/apps/details?id = com.androidlost&hl = en)通過傳入的短信調用註冊服務的Google推送消息,無需啓動應用程序甚至一次3.0+版本 – test

回答

0

您的應用程序將需要清單中的android.permission.RECEIVE_SMS的用戶許可。

一旦你有了,你可以註冊一個android.provider.Telephony.SMS_RECEIVED廣播接收器。

然後你會想創建你的receiver。當您收到意向爲要檢索的消息,並確定它是否是您要注意一個android.provider.Telephony.SMS_RECEIVED_ACTION

<receiver android:name=".SMSBroadcastReceiver"> 
    <intent-filter> 
     <action android:name="android.provider.Telephony.SMS_RECEIVED" /> 
    </intent-filter> 
</receiver> 

接收機應延長BroadcastReceiver並在的onReceive()方法。

你的代碼可能看起來像這樣。

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. 
       } 
      } 
     } 
    } 
} 
+0

好友,你不明白這個問題。請再次閱讀該問題。 – test

+0

您正試圖在本機應用程序上加載您的解決方案,但考慮到該情形,用戶可能無法訪問其應用程序來註冊手機。相反,我會做遠程安裝,註冊接收器(自動完成),然後讓用戶在網站或其他平臺上輸入他們的號碼。一旦完成,等待幾分鐘發送文本到他們提供的數量,[啓動服務](http://developer.android.com/reference/android/content/Context.html#startService(android.content.Intent)),然後繼續你的快樂之路。 – David

+0

抱歉沒有找到你。您是否意識到如果應用程序至少未啓動一次(對於版本3.0的病房),廣播接收器將無法工作。 – test

相關問題