android sdk1.6,Android使用sdk 1.6及以上版本

我找到了一个工作演示并成功使用它.但问题是我用最小版本10实现它,其中StrictPolicy是可导入的.现在我想使用min sdk 1.6或更高版本来使用Bump.

我也看到AsysncTask for BindService可以用,但不适用于我.我正在做什么错

int sdkVersion = android.os.Build.VERSION.SDK_INT;

if(sdkVersion>9)

{

try{

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

StrictMode.setThreadPolicy(policy);

}catch (Exception e) {

// TODO: handle exception

}

}

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);

filter.addAction(BumpAPIIntents.DISCONNECTED);

filter.addAction(BumpAPIIntents.BUMPED);

this.registerReceiver(receiver, filter);

//txtReceived=(TextView)findViewById(R.id.txtReceived);

//bindService(new Intent(IBumpAPI.class.getName()), connection, Context.BIND_AUTO_CREATE);

new BindService().execute();

}

class BindService extends AsyncTask{

@Override

protected String doInBackground(String... params) {

// TODO Auto-generated method stub

bindService(new Intent(IBumpAPI.class.getName()), connection, Context.BIND_AUTO_CREATE);

return null;

}

@Override

protected void onPostExecute(String result) {

// TODO Auto-generated method stub

super.onPostExecute(result);

System.out.println("done");

}

}

/*@Override

public boolean onCreateOptionsMenu(Menu menu) {

getMenuInflater().inflate(R.menu.activity_main, menu);

return true;

} */

@Override

public void onDestroy()

{

super.onDestroy();

try {

unbindService(connection);

unregisterReceiver(receiver);

} catch (Exception e) {

// TODO: handle exception

}

}

private final ServiceConnection connection = new ServiceConnection() {

@Override

public void onServiceConnected(ComponentName className, IBinder binder)

{

Log.i("Bump", "onServiceConnected");

api = IBumpAPI.Stub.asInterface(binder);

try

{

api.configure("KEY_HERE", "Some text..");

}

catch (RemoteException e)

{

Log.i("Bump", "api.configured failed");

}

}

@Override

public void onServiceDisconnected(ComponentName className)

{

Log.i("Bump", "onServiceDisconnected");

}

};

private final BroadcastReceiver receiver = new BroadcastReceiver() {

@Override

public void onReceive(Context context, Intent intent) {

final String action = intent.getAction();

try {

if (action.equals(BumpAPIIntents.DATA_RECEIVED)) {

Log.i("Bump", "DATA_RECEIVED");

Log.i("Bump", "Received data from: " + api.userIDForChannelID(intent.getLongExtra("channelID", 0)));

Log.i("Bump", "Data: " + new String(intent.getByteArrayExtra("data")));

//AlertDialog.Builder diaBuilder=

} else if (action.equals(BumpAPIIntents.MATCHED)) {

Log.i("Bump", "MATCHED");

api.confirm(intent.getLongExtra("proposedChannelID", 0), true);

} else if (action.equals(BumpAPIIntents.CHANNEL_CONFIRMED)) {

Log.i("Bump", "CHANNEL_CONFIRMED");

api.send(intent.getLongExtra("channelID", 0), (StaticData.strUserId + ","+ StaticData.strHomeName + ","+ StaticData.strUserImgUrl).getBytes());

} else if (action.equals(BumpAPIIntents.CONNECTED)) {

Log.i("Bump", "CONNECTED");

api.enableBumping();

}

else if (action.equals(BumpAPIIntents.DISCONNECTED)) {

Log.i("Bump", "DISCONNECTED");

} else if (action.equals(BumpAPIIntents.BUMPED)) {

Log.i("Bump", "BUMPED");

}

else if (action.equals(BumpAPIIntents.NOT_MATCHED)) {

Log.i("Bump", "NOT_MATCHED");

}

else if (action.equals(BumpAPIIntents.CHANNEL_CONFIRMED_EXTRA_CHANNEL_ID)) {

Log.i("Bump", "CHANNEL_CONFIRMED_EXTRA_CHANNEL_ID");

}

else if (action.equals(BumpAPIIntents.CHANNEL_CONFIRMED_EXTRA_CHANNEL_ID)) {

Log.i("Bump", "CHANNEL_CONFIRMED_EXTRA_CHANNEL_ID");

}

} catch (RemoteException e) {}

}

};

我上面使用的工作演示是docs.google.com/open?id=0B8f-N2PC8e0vU0gxRm1jaG51RGM

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值