创建“电池使用情况”安卓意图

发布于 2024-09-18 07:54:59 字数 423 浏览 5 评论 0原文

在我的 Nexus 上,有一个方便的应用程序,可以通过“设置”>“访问”访问。关于电话>电池使用。

我想从我的一项活动中 StartActivity() 该应用程序。

我可以在日志中看到,当“设置”运行它时,会记录此意图:

Starting activity:
  Intent { act=android.intent.action.MAIN
           cmp=com.android.settings/.fuelgauge.PowerUsageSummary }

我无法将其与 Android Java 源代码中的某些内容相关联。我什至无法在 GIT 源中找到“fuelgauge”。任何人都可以指出我正确的文件,或其他有用的东西,例如如何创建正确类型的意图?

谢谢

彼得

On my nexus one, there is a handy app reachable from Settings > About Phone > Battery use.

I'd like to StartActivity() that app from one of my Activities.

I can see in the log that when Settings runs it, this intent is logged:

Starting activity:
  Intent { act=android.intent.action.MAIN
           cmp=com.android.settings/.fuelgauge.PowerUsageSummary }

I'm having trouble relating that to something in Android Java source. I can't even find "fuelgauge" in the GIT source. Can anyone point me to the right file, or anything else helpful, like how to create the right kind of Intent?

Thanks

Peter

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

假扮的天使 2024-09-25 07:55:00

基于 @Chris Lacy 的少量代码,我将代码包装到您调用以打开此屏幕的静态方法:

public static void openBatteryUsagePage(Context ctx){
    Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
    ResolveInfo resolveInfo = ctx.getPackageManager().resolveActivity(powerUsageIntent, 0);
    // check that the Battery app exists on this device
    if(resolveInfo != null){
        ctx.startActivity(powerUsageIntent);
    } else
        Toast.makeText(ctx, R.string.not_found, Toast.LENGTH_LONG).show();
} 

Base on the handful code of @Chris Lacy , I wrapped the code to static method that you call to open this screen:

public static void openBatteryUsagePage(Context ctx){
    Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
    ResolveInfo resolveInfo = ctx.getPackageManager().resolveActivity(powerUsageIntent, 0);
    // check that the Battery app exists on this device
    if(resolveInfo != null){
        ctx.startActivity(powerUsageIntent);
    } else
        Toast.makeText(ctx, R.string.not_found, Toast.LENGTH_LONG).show();
} 
南七夏 2024-09-25 07:54:59

代码如下:

Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
ResolveInfo resolveInfo = getPackageManager().resolveActivity(powerUsageIntent, 0);
// check that the Battery app exists on this device
if(resolveInfo != null){
    startActivity(powerUsageIntent);
}

Code is as follows:

Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
ResolveInfo resolveInfo = getPackageManager().resolveActivity(powerUsageIntent, 0);
// check that the Battery app exists on this device
if(resolveInfo != null){
    startActivity(powerUsageIntent);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文