我试图从广播接收器的onReceive方法中调用SCS类中的几个方法,但是到处都给我报错:“Cannot make a static reference to the non-static method CheckConnection() from the type SCS”。
SCSReceiver.class
public class SCSReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
SCS.mehtodName(context);
// ... do what you need to do here...
}
SCS.class
public class SCS extends Activity {
private Handler handler;
private Runnable runnable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_connection_stablizer);
}
public static void mehtodName(Context context) {
// TODO Auto-generated method stub
CheckConnection();
}
private void CheckConnection() {
ConnectivityManager cn = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo nf = cn.getActiveNetworkInfo();
if (nf != null && nf.isConnected() == true) {
//CheckAccess();
Toast.makeText(this,
"Network Available! now checking Inernet access..",
Toast.LENGTH_SHORT).show();
} else {
// Toast.makeText(this, "Network Not Available", Toast.LENGTH_SHORT)
// .show();
}
}
manifest.xml
<activity
android:name="com.xyz.netspeedmaster.SCS"
android:label="@string/title_activity_connection_stablizer" >
</activity>
<receiver android:name="com.xyz.abc.SCSReceiver" >
</receiver>