0
我有一個按鈕,當我點擊這個按鈕,它會打開谷歌對我來說,但是當我運行我的代碼,不幸的是說,它停止按鈕打開谷歌URL點擊
public class MyActivity extends Activity {
Context myContext=null;
ConnectivityManager connectMngr=(ConnectivityManager) myContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo=connectMngr.getActiveNetworkInfo();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button=(Button)findViewById(R.id.btnCall);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {if (netInfo==null || netInfo.isAvailable()==false||netInfo.isConnected()==false)
{
Toast.makeText(getApplicationContext(),"No Internet!!",Toast.LENGTH_LONG);
}
else
{
Toast.makeText(getApplicationContext(),"You are Connected", Toast.LENGTH_LONG);
Intent intent=new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
startActivity(intent);
}
}
});
}
可能有很多理由讓_ 「不幸的是,它停止了」厄羅河所以請[編輯](http://stackoverflow.com/posts/40070406/edit)你的問題,併發布logcat錯誤。 – Shashanth