- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在按下电源按钮两次时发送电子邮件?我已经尝试了很多代码,但到目前为止没有一个有效。有人可以帮忙吗?
这是我的服务等级
public class UpdateService extends Service {
BroadcastReceiver mReceiver;
int counter=0;
@Override
public void onCreate() {
super.onCreate();
// register receiver that handles screen on and screen off logic
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
mReceiver = new Receiver();
registerReceiver(mReceiver, filter);
}
@Override
public void onDestroy() {
unregisterReceiver(mReceiver);
Log.i("onDestroy Reciever", "Called");
super.onDestroy();
}
@Override
public void onStart(Intent intent, int startId) {
boolean screenOn = intent.getBooleanExtra("screen_state", false);
if (!screenOn) {
counter += 1;
Log.i("screenON *****************", "Called");
Toast.makeText(getApplicationContext(), "Awake" + counter, Toast.LENGTH_LONG)
.show();
} else {
counter += 1;
Log.i("screenOFF ******************", "Called");
Toast.makeText(this, "slept" + counter, Toast.LENGTH_SHORT).show();
}
if (counter >= 4) {
Log.e("counter is -->", "" + counter);
counter = 0;
Log.e("counter is after clearance -->", "" + counter);
Log.e("************-***********", "Boooyah");
Toast.makeText(this, "Booyaaaha !!!!!!!!!!!!!!!!", Toast.LENGTH_SHORT).show();
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"dracmore@outlook.com"});
email.putExtra(Intent.EXTRA_SUBJECT, "TFS");
email.putExtra(Intent.EXTRA_TEXT, "This is the sample Message of my email");
email.setType("email/rfc822");
startActivity(Intent.createChooser(email, "Send Mail Via"));
email.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
email.addFlags(Intent.FLAG_FROM_BACKGROUND);
startActivity(email);
}
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}
这个小家伙是接收器
public class Receiver extends BroadcastReceiver {
private boolean screenOff;
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
screenOff = true;
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
screenOff = false;
}
Intent i = new Intent(context, UpdateService.class);
i.putExtra("screen_state", screenOff);
context.startService(i);
}
}
list
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.apkglobal.transarent">
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS"></uses-permission>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".Receiver"/>
<service android:name=".UpdateService"/>
</application>
</manifest>
问题是代码在屏幕关闭和打开时工作正常但我希望此代码在连续按下电源按钮 2 次或 3 次时工作
最佳答案
通过使用广播接收器,您可以获得屏幕关闭的 Action ,借助它您可以跟踪 Action 。
关于android - 按下电源按钮时如何执行我的应用程序的某些功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45603754/
是否可以通过编程方式关闭 iPhone,或者 Apple 不允许这样做? 如果 Apple 不允许这样做,是否可以通过编程方式将 iPhone 静音? 最佳答案 您使用官方 SDK 创建的 iPhon
我目前正在使用 Phonegap Build (3.7) 构建一个简单(但有用)的移动应用程序。 我正在制作的应用程序需要模拟信息亭模式类型的应用程序,因此该设备将仅与该应用程序一起使用,而不会用于其
当使用 numpy.power(2,N) 时,N 是一个整数,我遇到了以下问题: In[1] np.power(2,63) Out[1] -9223372036854775808 RuntimeWar
我的老板想从 Reporting Services 切换到 Power View,但他想知道您可以在 SSRS 中执行的所有操作是否首先在 Power View 中可用。 我立即注意到的一件事是我无法
我希望当我的应用程序运行时,电源按钮(按下时锁定屏幕并且屏幕变黑)应该被禁用。使用户无法锁定屏幕。 我在三星 Galaxy S 手机的默认相机应用程序中注意到了这个东西。这就是我尝试做同样的事情的原因
我有包含字段 Amount, Condition1, Condition2 的表格。 例子: Amount Condition1 Condition2 ---------------------
我正在计算给定时间范围内每月唯一 ID 的数量,但我遇到了两件奇怪的事情: 1. 寻找相同的东西,但使用两种不同的方法(每个月的值和逐月的累积值)给出不同的值。请参阅下面的屏幕截图。 2.当您在第一列
是否可以使用 Linux 手动打开/关闭 USB 电源? 有一个外部 USB 冷却风扇(你用来冷却自己的那种,而不是 PC),如果能够从终端控制它会很好,因为我想把风扇放在很远的地方。 我想这对其他各
我刚刚开始使用 Power Bi,现在我需要一些帮助。 我需要一个公式来创建一个使用以下逻辑的新列(在下面的示例图片中称为“组合”): 在每个 ParentID 上构建 Current 列的总和 如果
我在 Power BI 的 Power Query 编辑器中运行 Python 脚本来转换和处理我的数据。在这些计算之后,我想将数据集和另一个表返回到 Power Query 编辑器。我是否正确认为第
我想为 Linux 上的 GPU 设备关闭“真正的”PCIe 电源。我找到了一些主页,但它们无法切断“真实”的力量。 我监测了交流电的使用情况,但所有这些都无法减少实际用电情况。你能告诉我如何关闭设备
我在使用 PowerShell 脚本通过 Power BI rest api 更新数据集参数时遇到了一些困难。 我的脚本基于这些资源: https://learn.microsoft.com/en-u
如何使用使用两个现有表作为输入的 Python 脚本创建新表?例如通过执行 left join使用 pandas merge ? 部分详情: 使用 Home > Edit queries您可以在 Tr
由于数据的 secret 性,我将尝试使用一些随机示例来描述我正在努力解决的问题。假设我在 Power BI 中有一个包含发票数据的事实表。我需要计算过去 12 个月销售额超过 50,000 欧元的不
我专门尝试使用 Power Query 编辑器将 Column A 中的字符串:yyyymmdd 转换为 dd/mm/yyyy 日期格式电源 BI。我已经可以使用以下公式在 Excel 中执行此操作:
我有一个方法: public class MarginConverter { int top = 0; int bottom = 0; int right = 0; i
这个问题衍生出了我之前发布的一个问题; Custom x-axis values in Power BI 假设以下数据集: 专注于第二排和第三排。我怎样才能使下面相应图表中的线是连续的而不是停在中间?
我是一名优秀的程序员,十分优秀!