我有一个应用程序,我使用广播接收器
远程启动它。
我使用这种方法将其从应用程序抽屉中隐藏:
public static void hideFromAppDrawer(Context c) {
ComponentName componentToDisable = new ComponentName(
"mypackage", "mypackage.MyMainActivity");
c.getPackageManager().setComponentEnabledSetting(componentToDisable,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
}
但是在隐藏之后,(我隐藏了 laucher Activity ,之后我想远程启动相同的 Activity )应用程序没有启动。日志说:
03-27 15:00:53.494: E/AndroidRuntime(23392): FATAL EXCEPTION: main
03-27 15:00:53.494: E/AndroidRuntime(23392): java.lang.RuntimeException: Unable to start receiver mypackage.receivers.myReceiver: android.content.ActivityNotFoundException: Unable to find explicit activity class {mypackage/mypackage.MyMainActivity}; have you declared this activity in your AndroidManifest.xml?
03-27 15:00:53.494: E/AndroidRuntime(23392): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2383)
当我尝试启动 Activity 时,错误出现在广播接收器的
onReceive()
方法中:
context.startActivity(i);
03-27 15:00:53.494: E/AndroidRuntime(23392): at ... .onReceive(MyReceiver.java:36)
可能是什么问题?当我的应用程序隐藏在应用程序抽屉中时,我该如何启动它?
最佳答案
What could be the problem
您禁用了该组件,这意味着它无法启动。
how can I launch my application while it is hidden from the app drawer?
你可以试试这个:
设置
<activity-alias>
list 条目,指向您的 Activity ,其中包含您的MAIN
/LAUNCHER
<intent-filter>
(从原来的<activity>
中删除那个过滤器)禁用
<activity-alias>
使用上面的 Java 代码,保持原始 Activity 不变确保您的
BroadcastReceiver
引用 Activity ,因为它应该已经存在了
原则上,这应该可行,但我还没有尝试过这个特定的配方。
关于android - 应用程序在从 Android 上的应用程序抽屉中隐藏后无法启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15661329/