Back to project page BHRelay.
The source code is released under:
GNU General Public License
If you think the Android project BHRelay listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.sjtu.bhrelay; /* ww w .j a v a2s. c o m*/ import com.sjtu.bhrelay.service.BGService; import android.app.Activity; 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.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends Activity { private static final String TAG = "MainActivity"; public static final String ACTION_BH_NONE = "mainactivity.bluetooth.none"; private Context context; private Button btn_connect; private Button btn_record; private Button btn_start; private EditText et_filename; private Intent intent_bgservice; private MainActivityBroadcastReceiver mBroadcastReceiver; private IntentFilter intentFilter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.e(TAG,"onCreate"); context = this; btn_connect = (Button)findViewById(R.id.btn_connect); btn_connect.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { Intent intent = new Intent(context,BHSearchActivity.class); startActivityForResult(intent,0); } }); btn_record = (Button)findViewById(R.id.btn_record); btn_record.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { } }); btn_start = (Button)findViewById(R.id.btn_start); btn_start.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { } }); et_filename = (EditText)findViewById(R.id.et_filename); intentFilter = new IntentFilter(); intentFilter.addAction(MainActivity.ACTION_BH_NONE); mBroadcastReceiver = new MainActivityBroadcastReceiver(); Log.e(TAG,"start service"); intent_bgservice = new Intent(BGService.ACTION); startService(intent_bgservice); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); } @Override protected void onResume() { super.onResume(); Log.e(TAG,"onResume"); registerReceiver(mBroadcastReceiver,intentFilter); } @Override protected void onStop() { super.onStop(); Log.e(TAG,"onStop"); unregisterReceiver(mBroadcastReceiver); } @Override protected void onDestroy() { super.onDestroy(); Log.e(TAG,"onDestroy"); stopService(intent_bgservice); } private class MainActivityBroadcastReceiver extends BroadcastReceiver{ public MainActivityBroadcastReceiver(){ super(); } @Override public void onReceive(Context context, Intent intent){ Log.e(TAG,"on broadcast received"); String action = intent.getAction(); if(action.equals(MainActivity.ACTION_BH_NONE)){ Toast.makeText(MainActivity.this, "??????????", Toast.LENGTH_SHORT).show(); } } } }