1

我正在尝试制作一个Xposed 模块来挂钩 Android 系统的功能,它告诉应用程序 A,它已进入后台。换句话说,这里是一个例子:我们正在使用应用程序A,然后我们按下主页按钮,或者进入另一个应用程序。系统会向我们的应用程序A发送一条消息,让它知道焦点已经改变,现在它在后台(用户再也看不到它了)。系统这样做是为了让应用程序可以运行onPause()方法等等。

我在 XDA 上的 Xposed 部分发布了帖子,即使我能够缩小范围,我也无法解决它。关联

我也在 github 和 grepcode 的 Android 存储库中进行了很多搜索,但一直无法找到执行此操作的方法。我有点失落。这些是我得到的链接:

  1. http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.4.4_r1/android/app/Instrumentation.java#1234
  2. http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.4.4_r1/android/app/Activity.java#5346
  3. https://github.com/CyanogenMod/android_frameworks_base/blob/19a2266fed147ae051ba2df74f755cd7427c6eaa/docs/html/guide/topics/ui/ui-events.jd

谢谢,非常感谢任何帮助或建议。

4

1 回答 1

0

是的,这是可能的,而且很有意义。但是,例如,它需要做很多事情。

1)。您需要将您的应用程序设置为启动启动,这意味着每当用户重新启动移动设备或设备时,您的应用程序应自动启动。

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <receiver android:name=".OnBootReceiver" >
        <intent-filter
            android:enabled="true"
            android:exported="false" >
            <action android:name="android.intent.action.USER_PRESENT" />
        </intent-filter>
    </receiver>
    <receiver android:name=".OnGPSReceiver" >
    </receiver>

2)。显然,您必须制作没有启动器模式的应用程序,因为它是第一个活动,然后将第二个活动称为服务而不是活动。

所以基本上你必须创造这样的东西。

public class AppService extends WakefulIntentService{
   // your stuff goes here

}

从你的 mainActivity 调用服务时,像这样定义它。

Intent intent = new Intent(MainActivity.this, AppService.class);

启动服务(意图);hideApp(getApplicationContext().getPackageName());

hideApp // 在 mainActivity 之外使用它。

private void hideApp(String appPackage) {
    ComponentName componentName = new ComponentName(appPackage, appPackage
            + ".MainActivity");
    getPackageManager().setComponentEnabledSetting(componentName,
            PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
}

3)。然后在清单中定义此服务,如下所示。

<service android:name=".AppService" >
    </service>
于 2015-07-03T20:38:52.587 回答