2016-02-27 34 views
1

我只有一個CallBroadcastReceiver擴展BroadcastReceiver和宣佈的宣言。應用程序只有BroadcastReceiver不工作

仍然沒有顯示吐司,而我正在打出電話。 你能幫忙嗎?

其表示

[2016-02-27 10:02:20 - OnlyReciever] No Launcher activity found! 
[2016-02-27 10:02:20 - OnlyReciever] The launch will only sync the application package on the device! 

代碼下面 -

CallBroadcastReceiver.class

import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.widget.Toast; 

/** 
* @author Cosmos 
* 
*/ 
public class CallBroadcastReceiver extends BroadcastReceiver 
{ 
    public CallBroadcastReceiver() {} 

    @Override 
    public void onReceive(Context context, Intent intent) 
    { 
     Toast.makeText(context, intent.getAction(), Toast.LENGTH_LONG).show(); 
    } 
} 

的Manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="ind.example.onlyreciever" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" /> 

    <uses-sdk 
     android:minSdkVersion="22" 
     android:targetSdkVersion="22" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <receiver 
      android:name="ind.example.onlyreciever.CallBroadcastReceiver" 
      android:enabled="true" 
      android:exported="true" > 
      <intent-filter> 
       <action android:name="android.intent.action.NEW_OUTGOING_CALL" /> 
      </intent-filter> 
     </receiver> 
    </application> 

</manifest> 
+0

你不需要在這個項目中的任何活動,是嗎? – astuter

+0

@astuter是的,我認爲是這樣的......我只需要在打出電話時顯示祝詞。我需要一個這樣的活動嗎? – Bharat

+0

@astuter可以做到。但我認爲這不是必需的。看看這個鏈接[沒有mainActivity的應用程序示例](https://www.youtube.com/watch?v=htU_Rd-DW2U) – Bharat

回答

1

對於甲ndroid 3.1及更高版本,

你必須啓動你的活動之一,讓您的應用程序在停止狀態的任何明顯的註冊廣播接收器之前將工作,如3.1 release notes詳細說明。

當應用程序第一次安裝或手動強制關閉時,它處於「停止狀態」。在這種狀態下,只有具有FLAG_INCLUDE_STOPPED_PACKAGES標誌的廣播意圖纔會到達您的廣播接收機;此標誌未包含在默認系統廣播中,因此應用程序無法在停止狀態下接收它們。

請注意,「停止狀態」由程序包管理器跟蹤,與「應用程序未運行」不同。一旦應用程序不再處於停止狀態,即使重新啓動設備並且您的應用程序未運行,該應用程序仍會保持這種狀態。

+0

這是怎麼回事? [鏈接](http://youtube.com/watch?v=htU_Rd-DW2U) – Bharat

+0

好的。如果我使用活動第一次註冊它會一直運行嗎? – Bharat

+0

你對此有何看法? – Bharat

相關問題