Tag: broadcastreceiver

清单文件中是否可以将广播接收器定义为内部类?

我想在我的主要活动中创build一个广播接收器作为内部类。 但我有定义在清单xml文件广播接收机的问题,因为android找不到它。 码: public class MyActivity extends Activity{ … public class Receiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { …. } } … } performance: <receiver android:name=".org.danizmax.myapp.MyActivity$Receiver" android:enabled="true"> <intent-filter> <action android:name="org.danizmax.myapp.BROADCAST_INITIAL_DATA"></action> </intent-filter> </receiver> 我试着用: .org.danizmax.myapp.MyActivity $接收器 org.danizmax.myapp.MyActivity $接收器 .MyActivity $接收器 。接收机 我看到其他人也有类似的问题,但没有find任何答案。 那可能吗? 如果没有,使用广播接收机的更好方法是什么? 谢谢!

服务意图必须是明确的:意图

我有一个应用程序现在我通过广播接收器(MyStartupIntentReceiver)调用服务。 广播接收机中用于调用该服务的代码是: public void onReceive(Context context, Intent intent) { Intent serviceIntent = new Intent(); serviceIntent.setAction("com.duk3r.eortologio2.MyService"); context.startService(serviceIntent); } 问题是,在Android 5.0 Lollipop我得到以下错误(在以前的Android版本,一切正常): Unable to start receiver com.duk3r.eortologio2.MyStartupIntentReceiver: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.duk3r.eortologio2.MyService } 为了将服务声明为显式并正常启动,需要更改哪些内容? 在其他类似的线程尝试了一些答案,但虽然我摆脱了消息,该服务将无法启动。

如何使用registerReceiver方法?

我想要使​​用dynamic注册的BroadcastReceiver来引用一个Activity以便修改它的UI。 我正在使用Context.registerReceiver()方法,但接收方的onReceive()方法永远不会被调用。 以下是显示问题的示例代码: package com.example; import android.app.Activity; import android.app.IntentService; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; public class RegisterBroadcastReceiver extends Activity { public static class MyIntentService extends IntentService { public MyIntentService() { super(MyIntentService.class.getSimpleName()); } @Override protected void onHandleIntent(Intent intent) { Intent i = new Intent(this, MyBroadcastReceiver.class); sendBroadcast(i); } […]

在broadcastreceiver里共享喜好

在我的应用程序,我想在广播接收器内使用共享首选项…但我不能访问里面的getPreferences()方法… SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE); 我不能与上下文对象调用…任何其他方法?

BroadcastReceiver:不能实例化类; 没有空的构造函数

我有内部类作为广播接收器: public class ManualBacklightReceiver extends BroadcastReceiver { public static final String ACTION_MANUAL_BACKLIGHT = "com.android.systemui.statusbar.powerwidget.MANUAL_BACKLIGHT"; public ManualBacklightReceiver() { } @Override public void onReceive(Context context, Intent intent) { Log.d("ManualBacklightReceiver", intent.getAction()); } }; AndroidManifest: <receiver android:name=".statusbar.powerwidget.PowerWidgetGrid$ManualBacklightReceiver"> <intent-filter> <action android:name="com.android.systemui.statusbar.powerwidget.MANUAL_BACKLIGHT"/> </intent-filter> </receiver> 当我用这个代码发送意图时:Intent intent = new Intent(); intent.setAction("com.android.systemui.statusbar.powerwidget.MANUAL_BACKLIGHT"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.sendBroadcast(intent); 我得到这些例外: java.lang.RuntimeException: Unable to instantiate receiver com.android.systemui.statusbar.powerwidget.PowerWidgetGrid$ManualBacklightReceiver: java.lang.InstantiationException: can't […]

活动泄露了IntentReceiver

我正试图发送短信和邮件在一起。 发送邮件没有问题,但是当我发送短信时,我收到这个例外: End has leaked IntentReceiver Are you missing a call to unregisterReceiver()? 这是我的短信方法的代码: public class End extends Activity { Button btnSendSMS; EditText txtPhoneNo; EditText txtMessage; public EditText Details; public String user; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.end); Details = (EditText)findViewById(R.id.details); btnSendSMS = (Button) […]

在BroadcastReceiver中使用getWindowManager()

我想在BroadcastReceiver使用getWindowManager() ,我得到这个错误: “方法getWindowManager()是未定义的typesMyReceiver ” 我只需要得到display.getWidth()和display.getHeight() 任何提示? 非常感谢。

使用广播意图/广播接收机将消息从服​​务发送到活动

所以我理解(我认为)广播意图和接收消息给他们。 所以现在,我的问题/我无法解决的是如何从接收器的onReceive方法发送消息到活动。 比方说,我有一个接收器: public class ReceiveMessages extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if(action.equalsIgnoreCase(TheService.DOWNLOADED)){ // send message to activity } } } 我将如何发送消息给一个活动? 我是否必须在接收者中实例化我想要发送消息并以某种方式进行监视的活动? 或者是什么? 我理解这个概念,但不是真正的应用。 任何帮助将是绝对惊人的,谢谢。 汤姆

如何从上下文获取视图?

我想从上下文获取视图或findViewById()? 还是从意图? 我试图达到在我的广播接收器的具体视图和onReceive的参数是上下文和意图。 那么,我有一个class,其中是我的广播接收器。 现在,我正试图将广播接收器与它分开,但是我需要一种方法,以便从分离的广播接收器类中继续与我的课堂上的视图进行通信。 谢谢。

android – “导出的接收器不需要许可”的接收器意图从系统服务接收

我在AndroidManifest中声明了一些接收器: <!– no warning –> <receiver android:name=".receivers.TriggerMonitoringBootReceiver" android:enabled="false"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> <!– no warning –> <receiver android:name=".receivers.ScanResultsReceiver" android:enabled="false"> <intent-filter> <action android:name="android.net.wifi.SCAN_RESULTS" /> </intent-filter> </receiver> <!– warning : Exported receiver does not require permission–> <receiver android:name=".receivers.BatteryMonitoringReceiver" android:enabled="false"> <intent-filter> <action android:name="@string/intent_action_setup_alarm" /> <action android:name="@string/intent_action_cancel_alarm" /> <action android:name="@string/intent_action_monitor" /> </intent-filter> </receiver> 第一个是为了接收一个BOOT_COMPLETED动作。 第二个意思是接收android.net.wifi.SCAN_RESULTS 。 第三个是为了接收我广播的一些动作(intent_action_monitor)和一些由AlarmManager […]