在Android的BroadcastReceiver的问题3.1+ [英] BroadcastReceiver issues in Android 3.1+

查看:102
本文介绍了在Android的BroadcastReceiver的问题3.1+的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将位置数据更新为使用Web数据库的的BroadcastReceiver 服务

I'm trying to update location data to a web database using BroadcastReceiver and Service.

不过我有做它一个的Galaxy Tab 7.0 Plus运动升级版的Andr​​oid 3.2的工作困难。

However I am having difficulties making it to work with Android 3.2 on a Galaxy Tab 7.0 Plus.

同样的应用程序工作得很好的一款Android 2.3.6 Galaxy Note的,但它并没有在平板电脑上运行。事实上,我添加了 RECEIVE_BOOT 的意图行动,我的接收器,但它永远不会被实例化,也就是,0 nReceive()从来没有得到所谓的开机完成后。我不知道是否有任何更新的系统,导致这一行动。

The same application is working very well on a Android 2.3.6 Galaxy Note, but it doesn't run on the tablet. In fact, I add the RECEIVE_BOOT intent action to my receiver, but it never gets instantiated, that is, onReceive() never gets called after boot completes. I wonder if there are any updates to the system that cause this action.

下面是我的xml和接收器类:

Here is my xml and receiver classes:

AndroidManifest.xml中

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

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

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <receiver
        android:name=".BootUpReceiver"
        android:enabled="true"
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver>

    <service android:name=".MyService" >
    </service>
</application>

BootU preceiver.java

public class BootUpReceiver extends BroadcastReceiver {

private static int INTERVAL = 1000*15;

@Override
public void onReceive(Context context, Intent intent) {     
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    PendingIntent pi = PendingIntent.getService(context, 0, new Intent(context, MyService.class), PendingIntent.FLAG_UPDATE_CURRENT);
    am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), INTERVAL, pi);
}

}

还有一个原因是在一个系统中同一块code的工作,也没有其他的工作?

Is there a reason for the same piece of code work in one system and don't work on another?

感谢您!

推荐答案

由于Android 3,在一个应用程序的所有组件运行(接收广播)pvented直到应用程序被用户显式启动$ P $。

since android 3, all components in an app are prevented from running (receiving broadcasts) until the app is explicitly started by the user.

来测试,如果这是你的问题,一个虚拟活动添加到您的应用程序并启动它。现在,您的应用程序应该能够收到意图从那时起(即使重新启动)。

to test if this is your problem, add a dummy activity to your app and start it. now your app should be able to receive intents from then on (even after a reboot).

这里的AOSP问题描述该问题,

here's the AOSP issue describing the problem,

HTTP://$c$c.google。 COM / P /安卓/问题/详细信息?ID = 18225

请注意,它的关闭,按预期工作。这在技术上是一个安全补丁。应用程序可以利用一定知名度的广播意图像 TIMER_TICK 来开始自己没有用户不断运行的应用程序或明知该应用程序正在运行。

note that it's closed as "works as intended". this is technically a security fix. apps could exploit certain well-known broadcast intents like TIMER_TICK to start themselves without the user ever running the app or knowing that the app was running.

这篇关于在Android的BroadcastReceiver的问题3.1+的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆