我有一个带有布局的 Java 类。我想做一个 BroadcastReceiver 来获取来电号码。我如何在我的活动课上做到这一点:
现在我正在尝试这个:
package com.example.callchecker;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.content.BroadcastReceiver;
import android.content.Intent;;
public class Mark_number extends Activity {
Context context = this ;
Dialog D =new Dialog(context);
Button btn_dialog = (Button) findViewById(R.id.btn_dialog);
Button btn_dismiss = (Button) D.findViewById(R.id.btn_dismiss);
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mark_number);
private BroadcastReceiver myR = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
}
};
}
}
这是正确的方法还是我必须创建另一个扩展 BraodcastRceiver 的类?
public class My_Receiver extends BroadcastRceiver {
如果要创建另一个类,那么如何从我的主要活动中调用它???