在 Samsung Galaxy Tab 3 上调用闹钟,但在 LeEco Le2 上不调用
Alarm is called on Samsung Galaxy Tab 3, But not called on LeEco Le2
我正在开发一个应用程序,它会在未来的适当时间发送通知。如果我在 main activity 中调用 AlarmManager.init () - 它会在 Samsung Galaxy Tab 3 和 LeEco Le 2 上 5 秒后给我 Toast,这是应该的。但是,如果我调用 AlarmManager.init () 并终止我的应用程序(将其关闭)- 我仍然会在 Samsung Galaxy Tab 3 上看到 Toast,但在 LeEco Le 2 上却看不到它。我的问题是什么?
报警管理器:
public class AlarmManager {
static android.app.AlarmManager alarmManager;
static Context context;
public static void init (Context c) {
context = c;
alarmManager = (android.app.AlarmManager) context.getSystemService(ALARM_SERVICE);
Intent intent = new Intent("com.fome.planner");
PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.set(android.app.AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() +
5 * 1000, alarmIntent);
}
}
接收者:
public class MyReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
// an Intent broadcast.
Log.e("type", intent.getAction());
StringBuilder msgStr = new StringBuilder("current time: ");
Format formatter = new SimpleDateFormat("hh:mm:ss a");
msgStr.append(formatter.format(new Date()));
Toast.makeText(context, msgStr, Toast.LENGTH_SHORT).show();
}
}
清单:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:name="android.support.multidex.MultiDexApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.NoActionBar">
<activity android:name=".DayActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_places_key" />
<activity android:name=".TaskCreationActivity" />
<activity android:name=".CalendarActivity" />
<activity android:name=".ListActivity" />
<receiver
android:name=".MyReceiver"
android:process=":remote"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.fome.planner"/>
</intent-filter>
</receiver>
<receiver
android:name=".MyReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
当三星将您的应用程序置于后台时,您在 LeEco Le2 上将其关闭时,该应用程序可能已被终止。查看应用页面,滑动后是运行还是强制停止状态
我正在开发一个应用程序,它会在未来的适当时间发送通知。如果我在 main activity 中调用 AlarmManager.init () - 它会在 Samsung Galaxy Tab 3 和 LeEco Le 2 上 5 秒后给我 Toast,这是应该的。但是,如果我调用 AlarmManager.init () 并终止我的应用程序(将其关闭)- 我仍然会在 Samsung Galaxy Tab 3 上看到 Toast,但在 LeEco Le 2 上却看不到它。我的问题是什么?
报警管理器:
public class AlarmManager {
static android.app.AlarmManager alarmManager;
static Context context;
public static void init (Context c) {
context = c;
alarmManager = (android.app.AlarmManager) context.getSystemService(ALARM_SERVICE);
Intent intent = new Intent("com.fome.planner");
PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.set(android.app.AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() +
5 * 1000, alarmIntent);
}
}
接收者:
public class MyReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
// an Intent broadcast.
Log.e("type", intent.getAction());
StringBuilder msgStr = new StringBuilder("current time: ");
Format formatter = new SimpleDateFormat("hh:mm:ss a");
msgStr.append(formatter.format(new Date()));
Toast.makeText(context, msgStr, Toast.LENGTH_SHORT).show();
}
}
清单:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:name="android.support.multidex.MultiDexApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.NoActionBar">
<activity android:name=".DayActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_places_key" />
<activity android:name=".TaskCreationActivity" />
<activity android:name=".CalendarActivity" />
<activity android:name=".ListActivity" />
<receiver
android:name=".MyReceiver"
android:process=":remote"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.fome.planner"/>
</intent-filter>
</receiver>
<receiver
android:name=".MyReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
当三星将您的应用程序置于后台时,您在 LeEco Le2 上将其关闭时,该应用程序可能已被终止。查看应用页面,滑动后是运行还是强制停止状态