-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1534 from skyzzk/master
#7 实验7代码
- Loading branch information
Showing
8 changed files
with
181 additions
and
171 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
students/com1714080901240/app/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...s/com1714080901240/app/src/main/java/android/MusicPlayer/Com1714080901240Activity_04.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("搜索完成..."); | ||
} | ||
} | ||
}; | ||
|
||
} |
170 changes: 0 additions & 170 deletions
170
students/com1714080901240/app/src/main/res/drawable/ic_launcher_background.xml
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
students/com1714080901240/app/src/main/res/layout/activity_com1714080901240_04.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |