在三星Galaxy Tab 3上调用了警报,但没有调用LeEco Le2

时间:2017-04-13 11:27:10

标签: android android-studio alarmmanager alarm android-api-levels

我正在开发一款应用,可以在将来的适当时间发送通知。如果我在主要活动中调用AlarmManager.init() - 它会在三星Galaxy Tab 3和LeEco Le 2上为我提供Toast,就像它应该的那样。但是,如果我调用AlarmManager.init()并杀死我的应用程序(将其刷掉) - 我仍然可以在三星Galaxy Tab 3上获得Toast,但我不会在LeEco Le 2上获得它。我的问题是什么?

AlarmManager:

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>

1 个答案:

答案 0 :(得分:0)

当你在LeEco Le2上滑动它时,应用程序可能会被杀死,而三星将你的应用程序置于后台。检查应用程序页面以查看它在刷卡后是否仍在运行或是否处于强制停止状态。