- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我查看了本网站上的几篇关于BOOT_COMPLETED
未调用Broadcast Receiver
的帖子。我认为我的问题类似于这个问题 BroadcastReceiver not working after BOOT_COMPLETED
但是,我并没有尝试在一项服务中捕获多个 Intent
。我只想要 BOOT_COMPLETED
操作。
你能看一下我的代码,让我知道在哪里以及如何修复它吗?
这是 list :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.gcm.demo.app"
android:versionCode="1"
android:versionName="1.0" >
<!-- GCM requires Android SDK version 2.2 (API level 8) or above. -->
<!--
The targetSdkVersion is optional, but it's always a good practice
to target higher versions.
-->
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!--
Creates a custom permission so only this app can receive its messages.
NOTE: the permission *must* be called PACKAGE.permission.C2D_MESSAGE,
where PACKAGE is the application's package name.
-->
<permission
android:name="com.google.android.gcm.demo.app.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.google.android.gcm.demo.app.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- permission for network state -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BATTERY_STATS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- Main activity. -->
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="com.google.android.gcm.demo.app.DemoActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.android.gcm.demo.app.sqllite.SQLViews" >
</activity>
<activity android:name="com.google.android.gcm.demo.app.ScheduleView" >
</activity>
<activity android:name="com.google.android.gcm.demo.app.ConventionView" >
</activity>
<activity android:name="com.google.android.gcm.demo.app.EventList.DataView" >
</activity>
<activity android:name="com.google.android.gcm.demo.app.EventList.EventDetails" >
</activity>
<activity android:name="com.google.android.gcm.demo.app.Alerts.AlertView" >
</activity>
<activity android:name="com.google.android.gcm.demo.app.Alerts.AlertDetails" >
</activity>
<service
android:name="com.google.android.gcm.demo.app.Alerts.AlarmsService"
class="com.google.android.gcm.demo.app.Alerts.AlarmsService" >
<intent-filter>
<action
android:name="com.google.android.gcm.demo.app.Alerts.AlarmsService"
android:value="com.google.android.gcm.demo.app.Alerts.AlarmsService" />
</intent-filter>
</service>
<receiver
android:name="com.google.android.gcm.demo.app.Alerts.AlarmsBroadcastReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<!--
BroadcastReceiver that will receive intents from GCM
services and handle them to the custom IntentService.
The com.google.android.c2dm.permission.SEND permission is necessary
so only GCM services can send data messages for the app.
-->
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.google.android.gcm.demo.app" />
</intent-filter>
</receiver>
<!--
Application-specific subclass of GCMBaseIntentService that will
handle received messages.
By default, it must be named .GCMIntentService, unless the
application uses a custom BroadcastReceiver that redefines its name.
-->
<service android:name=".GCMIntentService" />
</application>
</manifest>
广播接收器:
package com.google.android.gcm.demo.app.Alerts;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class AlarmsBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "BootReceiver";
Intent startServiceIntent;
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
startServiceIntent = new Intent(context, AlarmsService.class);
context.startService(startServiceIntent);
Log.d("TAG", "alarmBroadcastReceiver");
System.out.println("alarm broadcast reciver...");
}
}
}
服务:
package com.google.android.gcm.demo.app.Alerts;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
public class AlarmsService extends Service {
String tag="alerttService";
@Override
public void onCreate() {
super.onCreate();
Toast.makeText(this, "Service created...", Toast.LENGTH_LONG).show();
Log.i(tag, "Service created...");
}
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("TAG", "Service command started.");
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
Toast.makeText(this, "Service started...", Toast.LENGTH_LONG).show();
Log.i(tag, "Service started. ..");
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service destroyed...", Toast.LENGTH_LONG).show();
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
最佳答案
我使用的是在为 Jellybean 安装 sdk 之前创建的模拟器。我为所有版本创建了新的模拟器,现在该程序可以在 Android 8 及更高版本的模拟器上运行。
关于android - BOOT_COMPLETED 未调用 BroadcastRecevier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11920712/
当您的应用权限发生变化时,您将如何创建广播接收器? 最佳答案 由于没有广播,因此您无法为应用程序权限创建BroadcastReceiver。一旦权限发生更改,应用程序就会重新启动。 编辑:您可以按照
我查看了本网站上的几篇关于BOOT_COMPLETED 未调用Broadcast Receiver 的帖子。我认为我的问题类似于这个问题 BroadcastReceiver not working a
我想接收 Broad Cast 接收器,了解“我何时会在设备中删除或卸载我的应用程序,如何实现,” 谢谢 最佳答案 没有这样的广播。当您的应用程序被删除时,您不会收到通知 关于android - 如何
我有一个 SMS 阅读器应用程序,我正在将发件人编号和消息正文显示到自定义 ListView 中。对于传入的消息,我已经注册了一个广播接收器并填充了 listView。 每当广播接收者收到一条新消息时
我有一个半透明的 AlertDialog 设置来显示用户是否收到短信。它是从广播接收器启动的。 用户只会收到这种“紧急”类型的消息,前提是发件人将其设置为此类消息并且用户启用了这种类型的中断。 我有一
我是一名优秀的程序员,十分优秀!