模拟在Android的广播 [英] Emulate a broadcast in Android

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

问题描述

我需要知道如何来模拟的BroadcastReceiver

我有以下的code,但我不知道如何真正看到当它接收广播。

 公共类LocationBroadcastReceiver扩展的BroadcastReceiver
{
@覆盖

公共无效的onReceive(上下文的背景下,意图意图){


    叠B = intent.getExtras();
    位置LOC =(地点)b.get(android.location.LocationManager.KEY_LOCATION_CHANGED);

    Toast.makeText(上下文,loc.toString(),Toast.LENGTH_SHORT).show();
    Log.d(com.dennis.test,位置:+ loc.toString());


}
}
 

在我的清单我有以下几点:

 <接收器的Andr​​oid版本:NAME =com.dennis.test.LocationBroadcastReceiver>
    <意向滤光器>
        <作用机器人:名称=android.location.LocationManager.KEY_LOCATION_CHANGED/>
    &所述; /意图滤光器>
< /接收器>
 

解决方案

进入到你的Andr​​oid SDK安装,然后以平台工具的文件夹。 会有一些可执行文件。其中之一是亚行。

在该文件夹中,执行

  

./亚行壳AM广播-a android.intent.action.KEY_LOCATION_CHANGED   -c android.intent.category.HOME -n com.dennis.test / .LocationBroadcastReceiver

或Windows

  

亚行壳AM广播-a android.intent.action.KEY_LOCATION_CHANGED   -c android.intent.category.HOME -n com.dennis.test / .LocationBroadcastReceiver

I need to know how to emulate a broadcastreceiver.

I have the following code, but I have no clue how to actually see when it is receiving a broadcast.

public class LocationBroadcastReceiver extends BroadcastReceiver 
{
@Override

public void onReceive(Context context, Intent intent) {


    Bundle b = intent.getExtras();
    Location loc = (Location)b.get(android.location.LocationManager.KEY_LOCATION_CHANGED);

    Toast.makeText(context, loc.toString(), Toast.LENGTH_SHORT).show(); 
    Log.d("com.dennis.test","LOCATION:  " + loc.toString());


}
}

In my manifest I have the following:

<receiver android:name="com.dennis.test.LocationBroadcastReceiver">
    <intent-filter>
        <action android:name="android.location.LocationManager.KEY_LOCATION_CHANGED" />
    </intent-filter>
</receiver>

解决方案

Go to the folder where your android-sdk is installed and then to platform-tools. There will be some executables. One of them is 'adb'.

When in the folder, execute

./adb shell am broadcast -a android.intent.action.KEY_LOCATION_CHANGED -c android.intent.category.HOME -n com.dennis.test/.LocationBroadcastReceiver

or on windows

adb shell am broadcast -a android.intent.action.KEY_LOCATION_CHANGED -c android.intent.category.HOME -n com.dennis.test/.LocationBroadcastReceiver

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

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