如果USB断开,警报不会响起

时间:2013-01-18 13:06:57

标签: android usb alarmmanager

在我的应用程序中,我使用重复警报。如果设备(Trekstor SurfTab breeze 7.0 with Android 4.0.4)连接到调试应用程序,一切正常。一旦断开设备,就不会再发出警报。 为了确保这是一个警报问题,我刚刚创建了一个简单的示例应用程序。

仅创建警报的Sample-Activity:

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
        if (am != null) {

            final Intent intent = new Intent(this, AlarmReceiver.class);

            // check if this intent already exists
            if (PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_NO_CREATE) == null) {
                am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), TimeUnit.SECONDS.toMillis(30),
                        PendingIntent.getBroadcast(this, 0, intent, 0));
            }
        }
    }
}

报警-接收器:

    public class AlarmReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(final Context context, final Intent intent) {
        Log.d("AlarmReceiver", "onReceive");
        final File mainDir = new File(Environment.getExternalStorageDirectory(), "AlarmTest");
        final File file = new File(mainDir, "alarmtest.txt");
        try {
            new FileWriter(file, true).append(new Date() + "\n").close();
        } catch (IOException e) {
            Log.d("AlarmReceiver", "Error writing alarmtest.txt", e);
        }
    }
}

清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ch.rse.alarmtest"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="14" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="ch.rse.alarmtest.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <receiver android:name=".AlarmReceiver" />
</application>

这就是logcat所说的:

01-18 13:26:20.170: D/AlarmReceiver(4890): onReceive
01-18 13:26:50.170: D/AlarmReceiver(4890): onReceive
01-18 13:27:01.660: D/lights(183): ro.product.lights =65
01-18 13:27:01.660: D/lights(183): bright =97
01-18 13:27:01.670: D/lights(183): ro.product.lights =65
01-18 13:27:01.670: D/lights(183): bright =92
01-18 13:27:01.690: D/lights(183): ro.product.lights =65
01-18 13:27:01.690: D/lights(183): bright =88
01-18 13:27:01.700: D/lights(183): ro.product.lights =65
01-18 13:27:01.700: D/lights(183): bright =83
01-18 13:27:01.720: D/lights(183): ro.product.lights =65
01-18 13:27:01.720: D/lights(183): bright =79
01-18 13:27:01.740: D/lights(183): ro.product.lights =65
01-18 13:27:01.740: D/lights(183): bright =74
01-18 13:27:01.750: D/lights(183): ro.product.lights =65
01-18 13:27:01.750: D/lights(183): bright =70
01-18 13:27:01.770: D/lights(183): ro.product.lights =65
01-18 13:27:01.770: D/lights(183): bright =65
01-18 13:27:01.780: D/lights(183): ro.product.lights =65
01-18 13:27:01.780: D/lights(183): bright =65
01-18 13:27:01.800: D/lights(183): ro.product.lights =65
01-18 13:27:01.800: D/lights(183): bright =65
01-18 13:27:01.820: D/lights(183): ro.product.lights =65
01-18 13:27:01.820: D/lights(183): bright =65
01-18 13:27:01.830: D/lights(183): ro.product.lights =65
01-18 13:27:01.830: D/lights(183): bright =65
01-18 13:27:01.850: D/lights(183): ro.product.lights =65
01-18 13:27:01.850: D/lights(183): bright =65
01-18 13:27:01.870: D/lights(183): ro.product.lights =65
01-18 13:27:01.870: D/lights(183): bright =65
01-18 13:27:01.880: D/lights(183): ro.product.lights =65
01-18 13:27:01.880: D/lights(183): bright =65
01-18 13:27:01.900: D/lights(183): ro.product.lights =65
01-18 13:27:01.900: D/lights(183): bright =65
01-18 13:27:01.910: D/lights(183): ro.product.lights =65
01-18 13:27:01.910: D/lights(183): bright =65
01-18 13:27:01.930: D/lights(183): ro.product.lights =65
01-18 13:27:01.930: D/lights(183): bright =65
01-18 13:27:08.660: D/lights(183): ro.product.lights =65
01-18 13:27:08.660: D/lights(183): bright =65
01-18 13:27:08.680: D/lights(183): ro.product.lights =65
01-18 13:27:08.680: D/lights(183): bright =65
01-18 13:27:08.690: D/lights(183): ro.product.lights =65
01-18 13:27:08.690: D/lights(183): bright =65
01-18 13:27:08.710: D/lights(183): ro.product.lights =65
01-18 13:27:08.710: D/lights(183): bright =65
01-18 13:27:08.710: D/SensorHAL(183): +__control_activate: handle=0 enabled=0
01-18 13:27:08.710: D/SensorHAL(183): Active sensors=00000000, real=00000000
01-18 13:27:08.710: D/SensorHAL(183): +__control_set_delay: ns=66667000
01-18 13:27:08.730: D/SurfaceFlinger(168): About to give-up screen, flinger = 0xaff918
01-18 13:27:08.730: E/libEGL(168): validate_display:188 error 3008 (EGL_BAD_DISPLAY)
01-18 13:27:13.730: V/TransportControlView(183): Create TCV com.android.internal.widget.TransportControlView@41339418
01-18 13:27:13.830: D/dalvikvm(183): GC_FOR_ALLOC freed 1219K, 19% free 10550K/12935K, paused 58ms
01-18 13:27:13.850: V/LockScreen(183): updateResources(Context context)
01-18 13:27:13.860: V/LockScreen(183): Catch Exception
01-18 13:27:13.940: I/WindowManager(183): MediaPlayer.is not PlayingVideo
01-18 13:27:14.000: I/TabletStatusBar(249): DISABLE_CLOCK: yes
01-18 13:27:14.040: D/dalvikvm(249): GC_CONCURRENT freed 398K, 36% free 7845K/12103K, paused 2ms+3ms
01-18 13:27:20.170: D/AlarmReceiver(4890): onReceive
01-18 13:27:50.170: D/AlarmReceiver(4890): onReceive
01-18 13:28:04.580: D/dalvikvm(2717): Debugger has detached; object registry had 1 entries
01-18 13:28:04.580: D/dalvikvm(518): Debugger has detached; object registry had 1 entries
01-18 13:28:04.580: D/dalvikvm(2446): Debugger has detached; object registry had 1 entries
01-18 13:28:04.580: D/dalvikvm(317): Debugger has detached; object registry had 1 entries
01-18 13:28:04.580: D/dalvikvm(407): Debugger has detached; object registry had 1 entries
01-18 13:28:04.580: D/dalvikvm(437): Debugger has detached; object registry had 1 entries
01-18 13:28:04.580: D/dalvikvm(346): Debugger has detached; object registry had 1 entries
01-18 13:28:04.580: D/dalvikvm(865): Debugger has detached; object registry had 1 entries
01-18 13:28:04.580: D/dalvikvm(2703): Debugger has detached; object registry had 1 entries
01-18 13:28:04.580: D/dalvikvm(2762): Debugger has detached; object registry had 1 entries
01-18 13:28:04.580: D/dalvikvm(2730): Debugger has detached; object registry had 1 entries
01-18 13:28:04.580: D/dalvikvm(2797): Debugger has detached; object registry had 1 entries
01-18 13:28:04.580: D/dalvikvm(249): Debugger has detached; object registry had 1 entries
01-18 13:28:04.580: D/dalvikvm(3997): Debugger has detached; object registry had 1 entries
01-18 13:28:04.580: D/dalvikvm(330): Debugger has detached; object registry had 1 entries
01-18 13:28:04.580: D/dalvikvm(2688): Debugger has detached; object registry had 1 entries
01-18 13:28:04.580: D/dalvikvm(183): Debugger has detached; object registry had 1 entries
01-18 13:28:04.580: D/dalvikvm(362): Debugger has detached; object registry had 1 entries
01-18 13:28:04.580: D/dalvikvm(422): Debugger has detached; object registry had 1 entries
01-18 13:28:04.580: D/dalvikvm(4752): Debugger has detached; object registry had 1 entries
01-18 13:28:04.580: V/UsbDeviceManager(183): now time is Jan. 18 01:28:04:1358512084 nachm.
01-18 13:28:04.580: V/UsbDeviceManager(183): Delay time at Jan. 18 01:28:09:1358512089 nachm.  to send DISCONNECTED massage
01-18 13:28:04.590: D/dalvikvm(4772): Debugger has detached; object registry had 1 entries
01-18 13:28:04.590: D/dalvikvm(4890): Debugger has detached; object registry had 2519 entries
01-18 13:28:09.600: I/DynamicPManagerService(183): setCpuFrequnecyPolicy flag :2
01-18 13:28:09.600: V/UsbDeviceManager(183): now time is Jan. 18 01:28:09:1358512089 nachm.
01-18 13:28:09.600: D/UsbDeviceManager(183): disable UsbDeviceManager wakelock wlref = 1
01-18 13:33:16.985: D/AlarmReceiver(4890): onReceive
01-18 13:33:16.995: W/NetworkStats(183): found non-monotonic values; saving to dropbox
01-18 13:33:17.015: D/SensorHAL(183): +__control_activate: handle=0 enabled=1
01-18 13:33:17.015: D/SensorHAL(183): Active sensors=00000001, real=00000001
01-18 13:33:17.015: D/SensorHAL(183): +__control_set_delay: ns=200000000
01-18 13:33:17.015: D/SensorHAL(183): +__control_set_delay: ns=66667000
01-18 13:33:17.035: I//system/bin/memsicd(165): Algorithm Library Info:
01-18 13:33:17.035: I//system/bin/memsicd(165): Build date: 0d-01-12, 0d:21:11
01-18 13:33:17.035: I//system/bin/memsicd(165): NVM block size: 26
01-18 13:33:17.035: I//system/bin/memsicd(165): Version: 0100
01-18 13:33:17.035: I//system/bin/memsicd(165): Auto-Calibration: 1
01-18 13:33:17.035: I//system/bin/memsicd(165): CompassLib init result: 0
01-18 13:33:17.045: W/NetworkStats(183): found non-monotonic values; saving to dropbox
01-18 13:33:17.065: W/PowerUI(249): unknown intent: Intent { act=android.intent.action.ACTION_POWER_CONNECTED flg=0x10000010 }
01-18 13:33:17.065: I/StorageNotification(249): UMS connection changed to false (media state mounted)
01-18 13:33:17.165: D/dalvikvm(183): GC_CONCURRENT freed 628K, 16% free 10933K/12935K, paused 3ms+8ms
01-18 13:33:17.175: D/lights(183): ro.product.lights =65
01-18 13:33:17.175: D/lights(183): bright =65
01-18 13:33:17.175: I/WindowManager(183): Lock screen displayed!
01-18 13:33:17.185: D/lights(183): ro.product.lights =65
01-18 13:33:17.185: D/lights(183): bright =65
01-18 13:33:17.205: D/lights(183): ro.product.lights =65
01-18 13:33:17.205: D/lights(183): bright =65
01-18 13:33:17.225: D/lights(183): ro.product.lights =65
01-18 13:33:17.225: D/lights(183): bright =65
01-18 13:33:17.235: D/SurfaceFlinger(168): Screen about to return, flinger = 0xaff918
01-18 13:33:17.235: D/lights(183): ro.product.lights =65
01-18 13:33:17.235: D/lights(183): bright =65
01-18 13:33:17.265: D/lights(183): ro.product.lights =65
01-18 13:33:17.265: D/lights(183): bright =65
01-18 13:33:17.265: W/ThrottleService(183): unable to find stats for iface rmnet0
01-18 13:33:17.275: D/lights(183): ro.product.lights =65
01-18 13:33:17.275: D/lights(183): bright =65
01-18 13:33:17.295: D/lights(183): ro.product.lights =65
01-18 13:33:17.295: D/lights(183): bright =65
01-18 13:33:17.305: D/lights(183): ro.product.lights =65
01-18 13:33:17.305: D/lights(183): bright =65
01-18 13:33:17.325: D/lights(183): ro.product.lights =65
01-18 13:33:17.325: D/lights(183): bright =68
01-18 13:33:17.345: D/lights(183): ro.product.lights =65
01-18 13:33:17.345: D/lights(183): bright =74
01-18 13:33:17.355: D/lights(183): ro.product.lights =65
01-18 13:33:17.355: D/lights(183): bright =81
01-18 13:33:17.375: D/lights(183): ro.product.lights =65
01-18 13:33:17.375: D/lights(183): bright =88
01-18 13:33:17.395: D/lights(183): ro.product.lights =65
01-18 13:33:17.395: D/lights(183): bright =95
01-18 13:33:17.405: D/lights(183): ro.product.lights =65
01-18 13:33:17.405: D/lights(183): bright =102
01-18 13:33:18.985: V/UsbDeviceManager(183): now time is Jan. 18 01:33:19:1358512399 nachm.
01-18 13:33:18.995: I/DynamicPManagerService(183): setCpuFrequnecyPolicy flag :1
01-18 13:33:18.995: V/UsbDeviceManager(183): now time is Jan. 18 01:33:19:1358512399 nachm.
01-18 13:33:18.995: D/UsbDeviceManager(183): enable UsbDeviceManager wakelock wlref = 0
01-18 13:33:19.085: V/UsbDeviceManager(183): now time is Jan. 18 01:33:19:1358512399 nachm.
01-18 13:33:19.095: D/ViewRootImpl(249): pckname = com.android.systemui
01-18 13:33:19.095: V/UsbDeviceManager(183): now time is Jan. 18 01:33:19:1358512399 nachm.
01-18 13:33:19.095: D/UsbDeviceManager(183): enable UsbDeviceManager wakelock wlref = 1
01-18 13:33:19.095: I/StorageNotification(249): UMS connection changed to false (media state mounted)
01-18 13:33:19.135: D/MtpService(437): addStorageLocked 65537 /mnt/sdcard
01-18 13:33:19.135: D/MtpService(437): addStorageLocked 196609 /mnt/inet
01-18 13:33:19.135: D/MtpService(437): starting MTP server in MTP mode
01-18 13:33:19.135: D/MtpService(437): addStorageLocked 196609 /mnt/inet
01-18 13:33:19.135: D/MtpService(437): addStorageLocked 65537 /mnt/sdcard
01-18 13:33:19.175: I/StorageNotification(249): UMS connection changed to false (media state mounted)
01-18 13:33:20.165: D/AlarmReceiver(4890): onReceive
01-18 13:33:38.425: V/LockScreen(183): onTrigger = 0
01-18 13:33:38.455: I/WindowManager(183): MediaPlayer.is not PlayingVideo
01-18 13:33:38.465: W/InputManagerService(183): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4126f1a0
01-18 13:33:38.495: I/TabletStatusBar(249): DISABLE_CLOCK: no
01-18 13:33:38.495: V/TabletStatusBar(249): setLightsOn(true)
01-18 13:33:44.375: D/dalvikvm(362): GC_CONCURRENT freed 421K, 35% free 8611K/13063K, paused 2ms+5ms
01-18 13:33:44.595: D/dalvikvm(362): GC_CONCURRENT freed 479K, 33% free 8819K/13063K, paused 2ms+5ms
01-18 13:33:44.685: D/dalvikvm(362): GC_FOR_ALLOC freed 322K, 34% free 8694K/13063K, paused 29ms
01-18 13:33:44.695: I/dalvikvm-heap(362): Grow heap (frag case) to 9.799MB for 1286224-byte allocation
01-18 13:33:44.745: D/dalvikvm(362): GC_FOR_ALLOC freed 1K, 24% free 9948K/13063K, paused 26ms
01-18 13:33:44.855: D/dalvikvm(362): GC_CONCURRENT freed 189K, 26% free 9780K/13063K, paused 2ms+10ms
01-18 13:33:45.085: D/dalvikvm(362): GC_FOR_ALLOC freed 1908K, 35% free 8596K/13063K, paused 38ms
01-18 13:33:45.085: I/dalvikvm-heap(362): Grow heap (frag case) to 9.705MB for 1286224-byte allocation
01-18 13:33:45.135: D/dalvikvm(362): GC_FOR_ALLOC freed 3K, 25% free 9849K/13063K, paused 28ms
01-18 13:33:45.225: D/dalvikvm(362): GC_CONCURRENT freed 4K, 25% free 9879K/13063K, paused 2ms+13ms
01-18 13:33:45.635: D/dalvikvm(362): GC_FOR_ALLOC freed 1369K, 30% free 9190K/13063K, paused 27ms
01-18 13:33:45.645: I/dalvikvm-heap(362): Grow heap (frag case) to 10.285MB for 1286224-byte allocation
01-18 13:33:45.695: D/dalvikvm(362): GC_FOR_ALLOC freed 5K, 21% free 10441K/13063K, paused 27ms
01-18 13:33:45.795: D/dalvikvm(362): GC_CONCURRENT freed 46K, 17% free 10921K/13063K, paused 2ms+4ms
01-18 13:33:45.895: D/dalvikvm(362): GC_FOR_ALLOC freed 2126K, 28% free 9442K/13063K, paused 27ms
01-18 13:33:45.895: I/dalvikvm-heap(362): Grow heap (frag case) to 10.531MB for 1286224-byte allocation
01-18 13:33:45.965: D/dalvikvm(362): GC_CONCURRENT freed 5K, 19% free 10693K/13063K, paused 2ms+3ms
01-18 13:33:46.505: I/ActivityManager(183): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.android.settings/.Settings} from pid 362
01-18 13:33:46.645: D/OpenGLRenderer(362): Flushing caches (mode 0)
01-18 13:33:46.705: W/InputManagerService(183): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@4139b200 (uid=10023 pid=362)
01-18 13:33:46.725: D/OpenGLRenderer(362): Flushing caches (mode 1)
01-18 13:33:49.205: I/ManageApplications(4752): onCreateOptionsMenu in ManageApplications{4109d208 #2 id=0x10202d4}: com.android.internal.view.menu.MenuBuilder@41076b88
01-18 13:33:49.365: I/ManageApplications(4752): onCreateOptionsMenu in ManageApplications{4109d208 #2 id=0x10202d4}: com.android.internal.view.menu.MenuBuilder@41076b88
01-18 13:33:50.005: D/dalvikvm(865): GC_CONCURRENT freed 415K, 8% free 6548K/7111K, paused 1ms+2ms
01-18 13:33:50.165: D/AlarmReceiver(4890): onReceive

正如您所看到的,13:28:09(拔掉插头)和13:33:16(重新插头)之间存在很大差距。好像两者之间什么也没发生过。为了确保这不是日志记录问题,每次警报发生时,我都会向文件写一个简单的时间戳。这个文件看起来像这样:

Fri Jan 18 13:25:50 MEZ 2013
Fri Jan 18 13:26:20 MEZ 2013
Fri Jan 18 13:26:50 MEZ 2013
Fri Jan 18 13:27:20 MEZ 2013
Fri Jan 18 13:27:50 MEZ 2013
Fri Jan 18 13:33:16 MEZ 2013
Fri Jan 18 13:33:20 MEZ 2013
Fri Jan 18 13:33:50 MEZ 2013

这里差距相同......

任何想法我做错了什么?

0 个答案:

没有答案