2013-11-22 81 views
0

這裏是我的應用程序應該如何工作http://postimg.org/image/57byitwpz/ 這裏是錯誤的即時得到http://postimg.org/image/ynyqerln9/ 請DONOT給任何東西在我的代碼,而不是添加糾正我的代碼。 香港專業教育學院誤寫的.xml代替的.class在第一幅圖像,請忽略如何檢測網絡,並打開無線設置

here is my code 

**SplashScreen.java** 






    public class SplashScreen extends Activity { 
if (!NetworkCheckClass.haveNetworkConnection(SplashActivity.this)) { 
    Toast.makeText(SplashScreen.this, "No internet connection!",Toast.LENGTH_LONG).show(); 

    Intent intent=new Intent(Settings.ACTION_WIRELESS_SETTINGS); 
    startActivity(intent); 
} 
else { 
    // your code if connection is available 
    // this is my code of splash screen 
    private static int SPLASH_TIME_OUT = 3000; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_splash); 

     new Handler().postDelayed(new Runnable() { 

      /* 
      * Showing splash screen with a timer. This will be useful when you 
      * want to show case your app logo/company 
      */ 

      @Override 
      public void run() { 
       // This method will be executed once the timer is over 
       // Start your app main activity 
       Intent i = new Intent(SplashScreen.this, MainActivity.class); 
       startActivity(i); 

       // close this activity 
       finish(); 
      } 
     }, SPLASH_TIME_OUT); 
    } 





} 

回答

2

試試這個,它可以幫助你

import android.app.Activity; 
    import android.app.AlertDialog; 
    import android.app.AlertDialog.Builder; 
    import android.content.Context; 
    import android.content.DialogInterface; 
    import android.content.DialogInterface.OnClickListener; 
    import android.content.Intent; 
    import android.net.ConnectivityManager; 
    import android.os.Bundle; 
    import android.provider.Settings; 
    import android.util.Log; 
    import android.widget.Toast; 

public class Splash extends Activity { 
static ConnectivityManager cm; 
AlertDialog dailog; 
AlertDialog.Builder build; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);// checking 
    // internet 
    build = new Builder(Splash.this); // connectivity 
    setContentView(R.layout.activity_splash); 
    if (cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI)// if connection is 
      // there screen goes 
      // to next screen 
      // else shows 
      // message 
      .isConnectedOrConnecting() 
      || cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) 
        .isConnectedOrConnecting()) { 
     Log.e("cm value", 
       "" 
         + cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI) 
           .isConnectedOrConnecting()); 
     Toast.makeText(Splash.this, "Internet is active", 2000).show(); 
     Thread mythread = new Thread() { 
      public void run() { 
       try { 

        sleep(5000); 

       } catch (Exception e) { 
       } finally { 
        Intent intent = new Intent(Splash.this, 
          yournextactivity.class); 
        startActivity(intent); 
        finish(); 
       } 
      } 
     }; 
     mythread.start(); 
    } else { 

     build.setMessage("This application requires Internet connection.Would you connect to internet ?"); 
     build.setPositiveButton("Yes", new OnClickListener() { 

      @Override 
      public void onClick(DialogInterface dialog, int which) { 
       // TODO Auto-generated method stub 

       startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS)); 

      } 
     }); 
     build.setNegativeButton("No", new OnClickListener() { 

      @Override 
      public void onClick(DialogInterface dialog, int which) { 
       // TODO Auto-generated method stub 
       build.setMessage("Are sure you want to exit?"); 
       build.setPositiveButton("Yes", new OnClickListener() { 

        @Override 
        public void onClick(DialogInterface dialog, int which) { 
         // TODO Auto-generated method stub 
         finish(); 
        } 
       }); 

      } 
     }); 
     dailog = build.create(); 
     dailog.show(); 

    } 

} 

}

+0

NIKHIL youractivity konsi活動hogi? – 01wifi01

+0

我不想要額外的對話,可以修復我的代碼嗎? – 01wifi01

+0

確定沒有錯誤終於 – 01wifi01