为了找到一种从我的后台服务(相同的包)启动活动的方法,我被困在 10 级或更低的 API(在 2.3.3 中尝试),它一直在抱怨权限 STATUS_BAR 这是一个系统权限。
我尝试了各种方法都没有成功。
清单中的活动定义:
<activity
android:name="com.company.app.ui.ViewActivity"
android:label="@string/title_activity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:screenOrientation="portrait"
android:launchMode="singleInstance"
android:stateNotNeeded="true"
android:exported="true">
<intent-filter>
<action android:name="com.company.app.action.START_VIEW" />
<data android:scheme="package" android:pathPattern="com.company.app"/>
</intent-filter>
</activity>
代码:
Intent it = new Intent("com.company.app.action.START_VIEW");
it.setComponent(new ComponentName(getPackageName(), ViewActivity.class.getName()));
it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(it);
选择:
Intent intent = new Intent(this, ViewActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
两者都失败,但有以下例外:
03-16 14:10:07.583: E/MyApp(367): java.lang.SecurityException: Permission Denial: starting Intent { act=com.company.app.action.START_DDM flg=0x10000000 cmp=com.company.app/.ViewActivity } from ProcessRecord{43db3d88 367:com.company.app/10029} (pid=367, uid=10029) requires android.permission.STATUS_BAR
03-16 14:10:07.703: E/MyApp(367): android.os.Parcel.readException(Parcel.java:1218)
03-16 14:10:07.793: E/MyApp(367): android.os.Parcel.readException(Parcel.java:1206)
03-16 14:10:07.864: E/MyApp(367): android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1214)
03-16 14:10:07.944: E/MyApp(367): android.app.Instrumentation.execStartActivity(Instrumentation.java:1373)
03-16 14:10:08.044: E/MyApp(367): android.app.ApplicationContext.startActivity(ApplicationContext.java:555)
03-16 14:10:08.174: E/MyApp(367): android.content.ContextWrapper.startActivity(ContextWrapper.java:248)
03-16 14:10:08.244: E/MyApp(367): com.company.app.service.MyService.showHideView(MyService.java:616)
03-16 14:10:08.324: E/MyApp(367): com.company.app.service.MyServiceThread$1.handleMessage(MyServiceThread.java:99)
03-16 14:10:08.394: E/MyApp(367): android.os.Handler.dispatchMessage(Handler.java:99)
03-16 14:10:08.473: E/MyApp(367): com.company.app.service.MyServiceThread.callShowHideView(MyServiceThread.java:231)
03-16 14:10:08.563: E/MyApp(367): com.company.app.service.MyServiceThread.run(MyServiceThread.java:205)
更新:下面发布的解决方案......感谢Android的愚蠢错误消息!