标签: android-broadcast

无法接收与网络相关的事件

我已经注册到ConnectivityManager.CONNECTIVITY_ACTIONBroadcastReceiver,用于接收网络状态事件,但是onReceive当我打开或关闭我的wifi连接时,我的功能没有被调用.

正如文档中所提到的,这是一个粘滞广播接收器,当我们注册它时会被触发.

但是onReceive当我注册这个接收器时,我的功能中没有任何事件,可能是什么原因?

在我的清单文件中,我拥有访问Internet /网络/ Wifi连接及其状态的所有权限.

我正在使用以下代码注册此意图:

registerReceiver(mNetworkStateReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
Run Code Online (Sandbox Code Playgroud)

在我的Logcat中,我得到以下错误消息寄存器:

01-01 00:05:29.804: ERROR/WifiHW(1305): Unable to open connection to supplicant on "/data/system/wpa_supplicant/wlan0": Connection refused
Run Code Online (Sandbox Code Playgroud)

可能是什么原因?有没有办法找出BroadcastReceiver是否正确注册?

谢谢.

android broadcastreceiver network-connection android-broadcast

6
推荐指数
1
解决办法
3962
查看次数

如何使用包名获取应用程序的类别

我有两个或更多具有我指定类别的应用程序

 <category android:name="com.myapp.MY_CATEGORY"/>
Run Code Online (Sandbox Code Playgroud)

我可以通过以下方式获得所有具有此类别的包裹:

 final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
 mainIntent.addCategory("com.myapp.MY_CATEGORY");
 final List<ResolveInfo> pkgAppsList =getPackageManager().queryIntentActivities( mainIntent, 0);
Run Code Online (Sandbox Code Playgroud)

现在我想跟踪我的类别应用程序安装并从应用程序中删除所以我已经制作了一个广播接收器,它将给我安装或删除应用程序的包名称,但我如何使用包名称来确定应用程序的类别以确定是否是我的应用程序.我可以为指定的类别应用程序制作广播接收器,如果不能,我如何从packagename获取类别.

android android-intent android-install-apk android-broadcast

6
推荐指数
1
解决办法
2349
查看次数

无法重新安装崩溃的Sony SmartWatch Control

我希望这不是通用的,但我正在为Sony SmartWatch开发一个应用程序.什么时候我犯了一个错误,比如允许空指针异常.我无法让我的应用重启.就像它永远处于坠毁状态一样.为了使问题更严重,我也停止通过与该应用程序相关的Logcat接收消息.当我卸载并重新安装应用程序时,它未在手机上的SmartWatch应用程序中列出.喜欢它不会注册.由于此时我没有收到任何日志消息,因此很难解决问题.我唯一能做的就是卸载应用程序.重启我的手机.然后重新安装该应用程序.那时它恢复正常,我可以再次开始编写代码.这让我想到了我的问题.有没有更好的方法来重新注册控件?这会发生在最终用户身上吗?如果应用程序崩溃他们需要卸载,重新启动并安装以恢复?

一些细节(名称已被更改以保护无辜者):

我创建了一个广播接收器,并在我的主要节目中设置它来收听这些广播.

  <receiver android:name=".MyExtensionReceiver" >
        <intent-filter>
             <!-- Receiver intents -->
            <action android:name="com.sonyericsson.extras.liveware.aef.registration.EXTENSION_REGISTER_REQUEST" />
            <action android:name="com.sonyericsson.extras.liveware.aef.registration.ACCESSORY_CONNECTION" />

            <!-- Control intents -->
            <action android:name="com.sonyericsson.extras.aef.control.START" />
            <action android:name="com.sonyericsson.extras.aef.control.STOP" />
            <action android:name="com.sonyericsson.extras.aef.control.PAUSE" />
            <action android:name="com.sonyericsson.extras.aef.control.RESUME" />
            <action android:name="com.sonyericsson.extras.aef.control.ERROR" />
            <action android:name="com.sonyericsson.extras.aef.control.TOUCH_EVENT" />
            <action android:name="com.sonyericsson.extras.aef.control.SWIPE_EVENT" />

        </intent-filter>
Run Code Online (Sandbox Code Playgroud)

MyExtensionReceiver的代码:

 public class MyExtensionReceiver extends BroadcastReceiver {


public MyExtensionReceiver() {
    super();
    Log.d("mytag", "MyExtensionReceiver Loaded");
    Dbg.setLogTag("mytag");
}

@Override
public void onReceive(Context context, Intent intent) {
    Log.d("mytag", "onReceive: " + intent.getAction());
    intent.setClass(context, MyExtensionReceiver.class);
    context.startService(intent);
}
Run Code Online (Sandbox Code Playgroud)

}

即使我的应用程序崩溃,我仍应在调用onReceive时收到日志消息.就像EXTENSION_REGISTER_REQUEST广播永远不会被发送一样.我只是一直在卸载重新启动并重新安装.最终SmartConnect应用程序找到了应用程序.

java android sony sony-smartwatch android-broadcast

6
推荐指数
1
解决办法
466
查看次数

永远不会触发WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION

我正在注册接收器onResume():

registerReceiver(wifiConnectivityReceiver, new
                IntentFilter(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION));
Run Code Online (Sandbox Code Playgroud)

这是接收器本身:

class WiFiConnectivityReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED,false)){
            Log.d(TAG,"Connected to network!");
        } else {
            Log.d(TAG,"Could not connect to network!");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的应用程序中,我能够连接到选定的WiFi网络,但这SUPPLICANT_CONNECTION_CHANGE_ACTION永远不会被解雇.如果我将其更改SUPPLICANT_STATE_CHANGED_ACTION为例如它正在工作.

我正在研究ICS.
是否有其他人因此意图遇到这样的问题?

android android-intent android-broadcast

6
推荐指数
1
解决办法
2994
查看次数

如何在Nexus 7上触发MediaScan?

因为我想确保MediaStore拥有最新信息而无需重新启动我想使用我在SO上找到的流行方式触发MediaScanner

context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
                                 Uri.parse("file://" + Environment.getExternalStorageDirectory())));
Run Code Online (Sandbox Code Playgroud)

这适用于我的三星S2 w/ICS,但不适用于我的Nexus 7 w/JellyBean.Logcat在我的Nexus 7上显示:

WARN/ActivityManager(480): Permission denied: checkComponentPermission() owningUid=10014
WARN/BroadcastQueue(480): Permission Denial: broadcasting Intent { act=android.intent.action.MEDIA_MOUNTED dat=file:///storage/emulated/0 flg=0x10 } from com.example.foo.bar (pid=17488, uid=10046) is not exported from uid 10014 due to receiver com.android.providers.downloads/.DownloadReceiver
INFO/ActivityManager(480): Start proc com.google.android.music:main for broadcast com.google.android.music/.store.MediaStoreImportService$Receiver: pid=17858 uid=10038 gids={50038, 3003, 1015, 1028}
INFO/MusicStore(17858): Database version: 50
INFO/MediaStoreImporter(17858): Update: incremental Added music: 0 Updated music: 0 Deleted music: 0 Created playlists: 0 Updated playlists: 0 Deleted playlists: 0 Inserted playlist …
Run Code Online (Sandbox Code Playgroud)

android android-intent android-mediascanner android-broadcast

6
推荐指数
3
解决办法
1万
查看次数

从广播事件切换到Otto是否有任何好处

我偶然发现了Otto,看起来它被用作广播事件的替代品.我阅读了文档但是,我不明白使用Otto是否有很多好处.

android otto android-broadcast

6
推荐指数
2
解决办法
1545
查看次数

在android中卸载应用程序时调用广播接收器

我想在应用程序上清理我的应用程序创建的垃圾UnInstalling.

使用ManiFest文件: -

在清单文件中添加:

 <receiver android:name="com.netdoers.com.ui.CleanReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_REMOVED" >
            </action>
            <data android:scheme="package"/>
        </intent-filter>
    </receiver>
Run Code Online (Sandbox Code Playgroud)

创建接收器以捕获 BroadCast Event

public class CleanReceiver extends BroadcastReceiver
{
  public void onReceive(Context context, Intent intent) {
    CustomToast.showToastMessage(context, "Uninstalling Application");
    Log.e("Uninstall", "CleanReceiver Called");
  }
} 
Run Code Online (Sandbox Code Playgroud)

在Java代码: -

 BroadCastReceiver br = new CleanReceiver();
 IntentFilter intentFilter = new IntentFilter();
 intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
 intentFilter.addDataScheme("package");
 registerReceiver(br, intentFilter);
Run Code Online (Sandbox Code Playgroud)

但是在卸载应用程序时,接收器从未被调用过.

Java和Manifest都不会在卸载应用程序时调用Receiver.如何在卸载应用程序时捕获广播事件?

android android-package-managers android-broadcast

6
推荐指数
1
解决办法
7015
查看次数

Android日历BroadcastReceiver主机:com.android.calendar与com.google.android.calendar

环顾四周后,我注意到Android日历有2个可能的主机.
第一个是com.android.calendar,另一个是com.google.android.calendar.
我很确定它反映了谷歌去年发布的新独立日历,但除此之外,我一无所知.
有什么不同?我何时应该使用第一个而另一个?

android calendar android-contentprovider android-broadcast

6
推荐指数
1
解决办法
553
查看次数

从BroadcastReceiver调用时,startActivity不起作用

我有一个通知,当我选择时,它会发送Broadcast一个BroadcastReceiver使用a PendingIntent.在onReceive我开始新的Activity.

但是,如果我从最近打开的应用程序中移除我的应用程序(或通知在绘图中长时间停留),则会出现以下情况:

当我在抽屉里有多个通知时,第一个通知很好.在点击第二个之后,我onCreate()和我onResume()的被叫,它就好像startActivity()根本不工作一样.如果我添加标志Intent.FLAG_ACTIVITY_SINGLE_TOP然后onNewIntent被调用.

notificationIntent = new Intent();
notificationIntent.setAction(AppConstants.ACTION_ACTIVITY);
notificationIntent.putExtra("key", value);
int requestID = (int) System.currentTimeMillis();

mBuilder.setContentIntent(PendingIntent
                    .getBroadcast(context, requestID, notificationIntent, 
                                  PendingIntent.FLAG_UPDATE_CURRENT));
Run Code Online (Sandbox Code Playgroud)

的onReceive

  Intent intent = new Intent(context, Activity.class);
  intent.putExtra("key", value);
  //IF I ADD FLAG_ACTIVITY_SINGLE_TOP IT WORKS
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  context.startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

android android-notifications android-activity android-broadcast

6
推荐指数
2
解决办法
5765
查看次数

后台服务从最近删除应用程序时停止

当从最近的oppo和vivo手机中移除我的应用程序时,后台服务停止,并且广播接收器在这种情况下也不起作用.

android background-service broadcastreceiver android-broadcast oppo

6
推荐指数
1
解决办法
2362
查看次数