Android 11 如何在源码中屏蔽launcher启动之后继续拉起的情况
时间: 2024-03-18 14:39:04 浏览: 25
要在 Android 11 源代码中屏蔽 launcher 启动之后继续拉起的情况,可以通过以下步骤实现:
1. 在 AndroidManifest.xml 文件中找到 launcher Activity 的 intent-filter,将其添加一个 CATEGORY_DEFAULT 的 category,示例代码如下:
```xml
<activity android:name=".LauncherActivity"
android:label="@string/launcher_name"
android:theme="@style/LauncherTheme"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
```
2. 在 LauncherActivity 的 onCreate() 方法中,获取 Intent 中的 action,如果是 MAIN,则正常启动,否则直接 finish(),示例代码如下:
```java
public class LauncherActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
if (Intent.ACTION_MAIN.equals(intent.getAction())) {
setContentView(R.layout.activity_launcher);
// 正常启动
} else {
finish();
}
}
}
```
通过上述步骤,就可以在 Android 11 源代码中屏蔽 launcher 启动之后继续拉起的情况了。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)