我試圖在接到來電/撥出電話時顯示敬酒信息。 如果應用程序關閉,則接收器無法正常工作。 我不想使用服務。請幫助我。即使關閉應用程序,我也想使用廣播接收器
'I am using the below receiver code'
public class CallReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent) {
if (isConnected(context)) {
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING)) {
Toast.makeText(context, "Call in progress", Toast.LENGTH_LONG).show();
}
}
}
'This is receiver registered in manifest'
<receiver android:name="com.example.android.testapplication.CallReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"></action>
<action android:name="android.intent.action.new_outgoing_call"></action>
</intent-filter>
</receiver>
修復您的''元素。特別是第二個,不會被認可,因爲Android是區分大小寫的。 –
CommonsWare
謝謝你。我修好了。但是如果應用程序關閉,接收器仍然無法工作。 – Niranvj
我想你需要一個[Service](http://developer.android.com/guide/components/services.html)。 – Xplouder