2017-03-02 33 views
-1
activity android:name=".MainActivity"> 
     <intent-filter android:priority="999999999"> 
      <action android:name="com.android.settings.Settings" /> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.DEFAULT" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 

這是AndroidManifest.xml內容。
然後在MainActivity.java我可以檢測意向過濾器中的活動啓動嗎? Android

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    // Do some actions that will be in `onCreate()` if detect working. 
+1

Emm其實問題不是很清楚。你究竟需要什麼? – DEADMC

回答

1

我可以檢測到意向過濾器的活動推出?

最簡單的方法將有不同的活動由上述過濾器,將在其onCreate()把一些數據包,然後鏈打電話給你MainActivityfinish()(所以暫時性的,沒有用戶界面)觸發。然後,您可以通過檢查Bundle中的內容來知道(如果getExtras()返回任何內容)。

您也可以檢查Intent本身的內容,但取決於您的過濾器,它可能需要比以前提到的瞬態活動更多的工作。

<intent-filter android:priority="999999999"> 

這使得沒有任何影響,這是因爲android:priority值必須是一個整數比SYSTEM_LOW_PRIORITY和小於SYSTEM_HIGH_PRIORITY更大,這意味着-10001000之間範圍內。任何其他值都將被忽略,並且優先級會降低爲默認值0(文檔號herehere)。

相關問題