android中Bump Api中的BroadcastReceiver未响应
每当我运行我的应用程序时,我都会收到“服务已连接”消息,但此后广播接收器没有响应 有什么问题? 谁能告诉我该怎么办 公共类测试扩展了活动 { 私人IBumpAPIandroid中Bump Api中的BroadcastReceiver未响应,android,api,bump,Android,Api,Bump,每当我运行我的应用程序时,我都会收到“服务已连接”消息,但此后广播接收器没有响应 有什么问题? 谁能告诉我该怎么办 公共类测试扩展了活动 { 私人IBumpAPI private final ServiceConnection connection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName className, IBinder binder) {
private final ServiceConnection connection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder binder) {
Log.i("BumpTest", "onServiceConnected");
api = IBumpAPI.Stub.asInterface(binder);
try {
api.configure("8836a26d3545410c9905d90528b2153a",
"ram");//8836a26d3545410c9905d90528b2153a,3826a0e77b284c05960d4513e87c4a88
} catch (RemoteException e) {
Log.w("BumpTest", e);
}
Log.d("Bump Test", "Service connected");
}
@Override
public void onServiceDisconnected(ComponentName className) {
Log.d("Bump Test", "Service disconnected");
}
};
private final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
try {
Log.i("Bump Test", "In Receive " );
if (action.equals(BumpAPIIntents.DATA_RECEIVED)) {
Log.i("Bump Test", "Received data from: " + api.userIDForChannelID(intent.getLongExtra("channelID", 0)));
Log.i("Bump Test", "Data: " + new String(intent.getByteArrayExtra("data")));
} else if (action.equals(BumpAPIIntents.MATCHED)) {
long channelID = intent.getLongExtra("proposedChannelID", 0);
Log.i("Bump Test", "Matched with: " + api.userIDForChannelID(channelID));
api.confirm(channelID, true);
Log.i("Bump Test", "Confirm sent");
} else if (action.equals(BumpAPIIntents.CHANNEL_CONFIRMED)) {
long channelID = intent.getLongExtra("channelID", 0);
Log.i("Bump Test", "Channel confirmed with " + api.userIDForChannelID(channelID));
api.send(channelID, "Hello, world!".getBytes());
} else if (action.equals(BumpAPIIntents.NOT_MATCHED)) {
Log.i("Bump Test", "Not matched.");
} else if (action.equals(BumpAPIIntents.CONNECTED)) {
Log.i("Bump Test", "Connected to Bump...");
api.enableBumping();
}else{
System.out.println("inn broadcast rcvr ::: "+api.toString());
}
} catch (RemoteException e) {}
}
};
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bindService(new Intent(IBumpAPI.class.getName()),
connection, Context.BIND_AUTO_CREATE);
Log.i("BumpTest", "boot");
IntentFilter filter = new IntentFilter();
filter.addAction(BumpAPIIntents.CHANNEL_CONFIRMED);
filter.addAction(BumpAPIIntents.DATA_RECEIVED);
filter.addAction(BumpAPIIntents.NOT_MATCHED);
filter.addAction(BumpAPIIntents.MATCHED);
filter.addAction(BumpAPIIntents.CONNECTED);
registerReceiver(receiver, filter);
//txtReceived=(TextView)findViewById(R.id.txtReceived);
//bindService(new Intent(IBumpAPI.class.getName()), connection, Context.BIND_AUTO_CREATE);
new BindService().execute();
}
@SuppressLint("NewApi")
class BindService extends AsyncTask<String, Integer, String>{
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
bindService(new Intent(IBumpAPI.class.getName()), connection, Context.BIND_AUTO_CREATE);
return null;
}
@SuppressLint("NewApi")
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
System.out.println("done");
}
}
public void onStart() {
Log.i("BumpTest", "onStart");
super.onStart();
}
public void onRestart() {
Log.i("BumpTest", "onRestart");
super.onRestart();
}
public void onResume() {
Log.i("BumpTest", "onResume");
super.onResume();
}
public void onPause() {
Log.i("BumpTest", "onPause");
super.onPause();
}
public void onStop() {
Log.i("BumpTest", "onStop");
super.onStop();
}
public void onDestroy() {
Log.i("BumpTest", "onDestroy");
super.onDestroy();
try {
unbindService(connection);
unregisterReceiver(receiver);
} catch (Exception e) {
// TODO: handle exception
}
}
private final ServiceConnection connection=new ServiceConnection(){
@凌驾
服务连接上的公共void(组件名称类名称,IBinder绑定器){
Log.i(“BumpTest”、“onServiceConnected”);
api=IBumpAPI.Stub.a接口(活页夹);
试一试{
api.配置(“8836a26d3545410c9905d90528b2153a”,
“ram”);/8836a26d3545410c9905d90528b2153a、3826a0e77b284c05960d4513e87c4a88
}捕获(远程异常){
Log.w(“颠簸试验”,e);
}
Log.d(“通气测试”,“连接服务”);
}
@凌驾
ServiceDisconnected上的公共void(ComponentName类名称){
Log.d(“通气测试”、“服务断开”);
}
};
专用最终BroadcastReceiver=新的BroadcastReceiver(){
@凌驾
公共void onReceive(上下文、意图){
最后一个字符串action=intent.getAction();
试一试{
Log.i(“通气测试”、“接收中”);
if(action.equals(bumpapitintents.DATA_已接收)){
Log.i(“通气测试”,“从以下位置接收数据:”+api.userIDForChannelID(intent.getlongtra(“channelID”,0)));
Log.i(“通气测试”,“数据:+新字符串(intent.getByteArrayExtra(“数据”)));
}else if(action.equals(bumpapitintents.MATCHED)){
long channelID=intent.getLongExtra(“proposedChannelID”,0);
Log.i(“通气测试”,“匹配:”+api.userIDForChannelID(channelID));
api.确认(channelID,true);
Log.i(“通气测试”、“确认发送”);
}else if(action.equals(bumpapitintents.CHANNEL_confirm)){
long channelID=intent.getLongExtra(“channelID”,0);
Log.i(“通气测试”,“通道通过”+api.userIDForChannelID(channelID))确认);
send(channelID,“你好,世界!”.getBytes());
}else if(action.equals(bumpapitintents.NOT_MATCHED)){
Log.i(“通气测试”,“不匹配”);
}else if(action.equals(bumpapitintents.CONNECTED)){
Log.i(“通气测试”,“连接到通气…”);
api.enableBumping();
}否则{
System.out.println(“inn广播rcvr::”+api.toString());
}
}捕获(远程异常e){}
}
};
@凌驾
公共无效OnConfiguration已更改(配置newConfig){
super.onConfigurationChanged(newConfig);
}
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bindService(新的意图(IBumpAPI.class.getName()),
连接、上下文、绑定(自动创建);
Log.i(“BumpTest”、“boot”);
IntentFilter=newintentfilter();
filter.addAction(bumpapintents.CHANNEL_已确认);
filter.addAction(bumpapitintents.DATA_接收);
filter.addAction(bumpapintents.NOT_MATCHED);
filter.addAction(BumpAPIIntents.MATCHED);
filter.addAction(BumpAPIIntents.CONNECTED);
寄存器接收器(接收器、过滤器);
//txtReceived=(TextView)findViewById(R.id.txtReceived);
//bindService(新意图(IBumpAPI.class.getName()),连接,Context.BIND\u AUTO\u CREATE);
新建BindService().execute();
}
@SuppressLint(“新API”)
类BindService扩展了异步任务{
@凌驾
受保护的字符串doInBackground(字符串…参数){
//TODO自动生成的方法存根
bindService(新意图(IBumpAPI.class.getName()),连接,Context.BIND\u AUTO\u CREATE);
返回null;
}
@SuppressLint(“新API”)
@凌驾
受保护的void onPostExecute(字符串结果){
//TODO自动生成的方法存根
super.onPostExecute(结果);
系统输出打印项次(“完成”);
}
}
public void onStart(){
Log.i(“BumpTest”、“onStart”);
super.onStart();
}
公共void onRestart(){
Log.i(“BumpTest”、“onRestart”);
super.onRestart();
}
恢复时公开作废(){
Log.i(“颠簸测试”、“恢复测试”);
super.onResume();
}
公共无效暂停(){
Log.i(“颠簸测试”、“暂停”);
super.onPause();
}
公共void onStop(){
Log.i(“颠簸测试”、“顶部”);
super.onStop();
}
公共空间{
Log.i(“颠簸测试”、“onDestroy”);
super.ondestory();
试一试{
解除绑定服务(连接);
未注册接收人(接收人);
}捕获(例外e){
//TODO:处理异常
}
}
}