ブロードキャストレシーバーを介して着信を認識しようとしています。私はそうすることができません!実際、ブロードキャストを「トリガー」することはできません。
これが私のコードです:
activate.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Toast.makeText(getApplicationContext(),"Clicked",1).show();
final String BROADCAST_ACTION_NAME = ".BroadcastMM";
Intent intent = new Intent();
intent.setAction(BROADCAST_ACTION_NAME);
sendBroadcast(intent);
}
}
この「sendBroadcast」がトリガーされるかどうかはわかりません。私のブロードキャストレシーバーファイルでは:
public void onReceive(Context context, Intent intent)
{
if(intent.getAction()=="android.intent.action.PHONE_STATE"){
Toast.makeText(c,"BroadCast fired!",1).show();}
Bundle extras = intent.getExtras();
String state = extras.getString(TelephonyManager.EXTRA_STATE);
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
Toast.makeText(context, "Ringing", 1).show();
}
}
私のマニフェストファイル:
<receiver android:name=".BroadcastMM" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" >
</action>
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
私が見逃しているロジックはありますか?私はAndroidに非常に慣れていないので、助けてください。