BroadcastReceiver无法正常工作

时间:2012-08-18 08:26:31

标签: android broadcastreceiver

我有BroadcastReceiver

AndroidManifest.xml

<!-- When starting calculator-->    
<receiver android:name=".APP_CALCULATOR_class" >
    <intent-filter>
        <action android:name="android.intent.category.APP_CALCULATOR" >
        </action>
    </intent-filter>
</receiver>

APP_CALCULATOR_class.class

    package com.startcalcevent.startcalcevent;
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.widget.Toast;

    public class APP_CALCULATOR_class  extends BroadcastReceiver {
        public void onReceive(Context context, Intent intent) {
            Toast.makeText(context, "Calculator is on" , Toast.LENGTH_LONG).show();
        }
    }

打开计算器应用程序时,为什么此代码无效?

1 个答案:

答案 0 :(得分:0)

我只会在您发送广播的意图时开始。 App_CALCULATOR类别操作意图(ACTION_MAIN)未广播(使用sendBroadcast(Intent)),但使用startActivity(Intent);

作为活动开始