Skip to content

Commit

Permalink
Merge pull request #1534 from skyzzk/master
Browse files Browse the repository at this point in the history
#7 实验7代码
  • Loading branch information
zengsn authored Apr 21, 2019
2 parents da7b387 + a9631de commit 1c876b9
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 171 deletions.
34 changes: 34 additions & 0 deletions students/com1714080901240/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.MusicPlayer">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="音乐播放器"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Com1714080901240Activity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Com1714080901240Activity_01" />
<activity android:name=".Com1714080901240Activity_02" />
<activity android:name=".Com1714080901240Activity_03" />
<activity android:name=".Com1714080901240Activity_04"></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ public void click03(View view){
Intent intent3 = new Intent(this,Com1714080901240Activity_03.class);
startActivity(intent3);
}
public void click04(View view){
//创建一个Intent对象,开启下一个activity
Intent intent4 = new Intent(this,Com1714080901240Activity_04.class);
startActivity(intent4);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package android.MusicPlayer;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Com1714080901240Activity_04 extends AppCompatActivity {

private BluetoothAdapter mBluetoothAdapter;
private TextView text1,text2,text3;
private Button btn,btn_1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_com1714080901240_04);

text1=(TextView) this.findViewById(R.id.tv2); //已配对
text2= (TextView) this.findViewById(R.id.tv1); //状态信息
text3= (TextView) this.findViewById(R.id.tv3); //未配对
btn=(Button) this.findViewById(R.id.btn);

mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(mReceiver,filter);
IntentFilter filter2=new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
registerReceiver(mReceiver,filter2);

btn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View arg0){
if(!mBluetoothAdapter.isEnabled()){
mBluetoothAdapter.enable();
}
mBluetoothAdapter.startDiscovery();
text2.setText("正在搜索...");
}

});
}
public void onDestroy(){
super.onDestroy();
//解除注册
unregisterReceiver(mReceiver);
Log.e("destroy","解除注册");
}
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.e("sky",action);
if(action.equals(BluetoothDevice.ACTION_FOUND)){
//BluetoothDevice device = intent.getParcelableArrayExtra(BluetoothDevice.EXTRA_DEVICE);
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if(device.getBondState()==BluetoothDevice.BOND_BONDED){
//显示已配对设备
text1.append("\n"+device.getName()+"==>"+device.getAddress()+"\n");
}else if(device.getBondState()!=BluetoothDevice.BOND_BONDED){
text3.append("\n"+device.getName()+"==>"+device.getAddress()+"\n");
}
}else if(action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)){
text2.setText("搜索完成...");
}
}
};

}

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
android:layout_width="139dp"
android:layout_height="wrap_content"
android:layout_column="0"
android:text="加载本地歌曲" />
android:text="蓝牙启动"
android:onClick="click04"/>

<Button
android:id="@+id/button8"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Com1714080901240Activity_04">


<Button
android:text="搜索蓝牙"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="19dp"
android:id="@+id/btn"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<TextView
android:text="初始状态"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/btn"
android:layout_toRightOf="@+id/btn"
android:layout_toEndOf="@+id/btn"
android:layout_marginLeft="45dp"
android:layout_marginStart="45dp"
android:layout_marginBottom="14dp"
android:id="@+id/tv1" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv2"
android:text="已配对蓝牙设备如下:"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_marginTop="53dp"
android:layout_below="@+id/btn"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<TextView
android:text="未配对蓝牙设备如下:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="107dp"
android:id="@+id/tv3"
android:layout_below="@+id/tv2"
android:layout_alignLeft="@+id/tv2"
android:layout_alignStart="@+id/tv2" />

</RelativeLayout>

6 changes: 6 additions & 0 deletions students/com1714080901240/app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
</resources>

0 comments on commit 1c876b9

Please sign in to comment.