扫码关注官方订阅号
就是你手机如果没有开网,软件禁止被打开,怎么实现啊?
欢迎选择我的课程,让我们一起见证您的进步~~
你的Launcher Activity设置背景为透明,在Launcher Activity的onCreate函数里,判断当前是否有网络链接,无网络链接就提示一个Toast,然后自动finish好了。
知道你肯定需要关键性代码,代码如下,别忘了点赞和采纳。
在AndroidManifest.xml中注册Launcher Activity,并设置theme为透明主题。
<activity android:name=".activity.SplashActivity" android:configChanges="orientation|screenSize|keyboardHidden" android:screenOrientation="portrait" android:theme="@android:style/Theme.Translucent"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
SplashActivity中,onCreate函数直接判断当前是否有网络链接。如果有,则跳转到应用主Activity,没有,则finish当前SplashActivity。
/** * 判断网络是否连接 */ public static boolean isNetworkAvailable(Context context) { context = context.getApplicationContext(); ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); return activeNetworkInfo != null && activeNetworkInfo.isConnected(); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (isNetworkAvailable(this)) { // TODO:启动应用 } else { Toast.makeText(this, "当前无网络", Toast.SHORT_TOAST).show(); finish(); } }
看到这里,可以点赞和接纳了。消灭0回答。
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
你的Launcher Activity设置背景为透明,在Launcher Activity的onCreate函数里,判断当前是否有网络链接,无网络链接就提示一个Toast,然后自动finish好了。
知道你肯定需要关键性代码,代码如下,别忘了点赞和采纳。
在AndroidManifest.xml中注册Launcher Activity,并设置theme为透明主题。
SplashActivity中,onCreate函数直接判断当前是否有网络链接。如果有,则跳转到应用主Activity,没有,则finish当前SplashActivity。
看到这里,可以点赞和接纳了。消灭0回答。