Java Android系统如何告诉应用程序该应用程序已进入后台(不可见)?
我试图制作一个Xposed模块来钩住安卓系统的功能,它告诉应用程序A它已经进入后台。 换句话说,这里有一个例子: 我们正在使用应用程序A,然后按下home按钮,或进入另一个应用程序。系统将向我们的应用程序a发送一条消息,让它知道焦点已更改,现在它位于后台(用户无法再看到它)。系统这样做是为了让应用程序可以运行onPause()方法等等 我在XDA的Xposed部分发布了帖子,尽管我能够缩小范围,但我无法解决它 我还在github和grepcode的Android存储库中进行了大量搜索,但没有找到哪种方法可以做到这一点。我有点迷路了。 以下是我得到的链接:Java Android系统如何告诉应用程序该应用程序已进入后台(不可见)?,java,android,android-activity,system,xposed-framework,Java,Android,Android Activity,System,Xposed Framework,我试图制作一个Xposed模块来钩住安卓系统的功能,它告诉应用程序A它已经进入后台。 换句话说,这里有一个例子: 我们正在使用应用程序A,然后按下home按钮,或进入另一个应用程序。系统将向我们的应用程序a发送一条消息,让它知道焦点已更改,现在它位于后台(用户无法再看到它)。系统这样做是为了让应用程序可以运行onPause()方法等等 我在XDA的Xposed部分发布了帖子,尽管我能够缩小范围,但我无法解决它 我还在github和grepcode的Android存储库中进行了大量搜索,但没有找到
谢谢,非常感谢您的任何帮助或建议。是的,这是可能的,而且很有意义。但这需要很多的东西去做,例如 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>
}
在从mainActivity调用服务时,定义如下
public class AppService extends WakefulIntentService{
// your stuff goes here
Intent intent = new Intent(MainActivity.this, AppService.class);
startService(意向);
hideApp(getApplicationContext().getPackageName())
hideApp//在主活动之外使用它
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>
是的,这是可能的,而且很有意义。但这需要很多的东西去做,例如 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>
}
在从mainActivity调用服务时,定义如下
public class AppService extends WakefulIntentService{
// your stuff goes here
Intent intent = new Intent(MainActivity.this, AppService.class);
startService(意向);
hideApp(getApplicationContext().getPackageName())
hideApp//在主活动之外使用它
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>
嗨,梅格尔,你搞错我了;我不想创建一个应用程序,然后创建它的服务,这样它就可以在后台运行。我想做的是一个Xposed模块,它所做的只是挂接到系统方法,当应用程序进入后台时,它会告诉应用程序,并在其中注入一个代码(可能只是一个简单的XC_方法替换),因此X应用程序不会收到该消息,它们会像在前台一样继续运行。如果需要进一步解释,请查看我发布的XDA链接。谢谢很抱歉我当时忘记了这篇文章。我会抽出时间来完美地回答:在24小时的《梅格尔》中,你把我搞错了;我不想创建一个应用程序,然后创建它的服务,这样它就可以在后台运行。我想做的是一个Xposed模块,它所做的只是挂接到系统方法,当应用程序进入后台时,它会告诉应用程序,并在其中注入一个代码(可能只是一个简单的XC_方法替换),因此X应用程序不会收到该消息,它们会像在前台一样继续运行。如果需要进一步解释,请查看我发布的XDA链接。谢谢很抱歉我当时忘记了这篇文章。我会找时间尝试完美的回答:在24小时内