Android 应用程序未运行时广播无法运行 运行

Android broadcast is not working when the app is not running

如果这是一个愚蠢的问题,请不要投反对票,请在此处分享一些信息

我想创建一个保存通话记录的应用程序

为此我关注了 http://karanbalkar.com/2014/02/detect-incoming-call-and-call-hangup-event-in-android/

这个网站 但是当应用程序没有 running.Please 帮助

时我没有收到事件

我想在应用程序关闭时收到来电时获取事件

清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sars.broadcasttest">

    <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity android:name=".Main">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver android:name=".IncommingCall">
            <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE" />

            </intent-filter>
        </receiver>
    </application>

</manifest>

class 文件

package com.sars.broadcasttest;

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

/**
 * Created by athulbabu on 18/08/15.
 */
public class IncommingCall extends BroadcastReceiver {
    int i=0;
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("IncomingCall", "Call catched test"+i++);
        Toast.makeText(context, "Calll Intent Detected. test", Toast.LENGTH_LONG).show();
    }
}

出于安全原因,您必须在安装后至少 运行 应用程序一次才能使 BroadcastReceiver 正常工作。

阅读此部分:在已停止的应用程序上启动控件 http://developer.android.com/about/versions/android-3.1.html