0

我制作了一个读取 rss 提要的应用程序,并引起了轰动,然后我将放入 spash 中,我将放置一个函数来检查您的互联网连接,如果连接存在,则应用程序转到读取 rss 提要的活动,如果这样是不是应用程序显示一个弹出窗口,说明连接不存在,并显示一个关闭应用程序的按钮。

这是我的 SplashActivity 的代码

代码:

package rebus.palinsesti.tv;

import rebus.palinsesti.tv.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;

public class SplashActivity extends Activity {

    private static String TAG = SplashActivity.class.getName();
    private static long SLEEP_TIME = 5;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.splash);

        IntentLauncher launcher = new IntentLauncher();
        launcher.start();
    }

    private class IntentLauncher extends Thread {

        @Override
        public void run() {
            try {

                Thread.sleep(SLEEP_TIME*1000);
            } catch (Exception e) {
                Log.e(TAG, e.getMessage());
            }

            Intent intent = new Intent(SplashActivity.this, MainActivity.class);
            SplashActivity.this.startActivity(intent);
            SplashActivity.this.finish();
        }
    }

}
4

2 回答 2

0
    This might help you:

      ConnectivityManager conMgr = (ConnectivityManager) getSystemService (Context.CONNECTIVITY_SERVICE);
                // ARE WE CONNECTED TO THE NET
                if (conMgr.getActiveNetworkInfo() != null
                        && conMgr.getActiveNetworkInfo().isAvailable()
                        && conMgr.getActiveNetworkInfo().isConnected()) {
//place the required operation here
    Toast.makeText(this, "net available", Toast.length_duration).show();
     }

    else
    Toast.makeText(this, "net not available", Toast.length_duration).show();
于 2013-09-04T13:29:52.487 回答
0
/**
 * Return Internet connection status
 * @param ctxt
 *      The context
 * @return
 *      True if internet is reachable
 *      False otherwise
 */
public boolean isInternetReachable(Context ctxt)
{
    ConnectivityManager cm = (ConnectivityManager) ctxt.getSystemService(Context.CONNECTIVITY_SERVICE);    
    android.net.NetworkInfo netInfo = cm.getActiveNetworkInfo();    
    return netInfo != null && netInfo.isConnectedOrConnecting();
}

试试这个

希望能帮助到你

于 2013-09-04T13:27:44.037 回答