add mpdroid & broadcast_mpd

This commit is contained in:
JamesonHuang 2015-07-29 20:33:57 +08:00
parent 9922c12910
commit 256defe458
59 changed files with 589 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SocketAutoConnectClient</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.socketautoconnect.client"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".SocketAutoConnectClient"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" ></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" ></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" ></uses-permission>
<uses-permission android:name="android.permission.INTERNET" ></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK" ></uses-permission>
</manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -0,0 +1,26 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.socketautoconnect.client;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
}
public static final class id {
public static final int ip_info=0x7f050000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}

View File

@ -0,0 +1,40 @@
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}

View File

@ -0,0 +1,11 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "ant.properties", and override values to adapt the script to your
# project structure.
# Project target.
target=android-7

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<TextView
android:id="@+id/ip_info"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20dip"
android:text="检测到服务端IP: " />
</LinearLayout>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, SocketAutoConnectClient!</string>
<string name="app_name">UDP Client</string>
</resources>

View File

@ -0,0 +1,98 @@
package com.socketautoconnect.client;
import android.app.Activity;
import android.os.Bundle;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;
import android.widget.Toast;
public class SocketAutoConnectClient extends Activity implements Runnable
{
private MulticastSocket multicastSocket=null;
private static int BROADCAST_PORT=9898;
private static String BROADCAST_IP="224.0.0.1";
InetAddress inetAddress=null;
Thread thread=null;
TextView ipInfo;
private static String ip;
Handler myHandler=new Handler()
{
@Override
public void handleMessage(Message msg)
{
super.handleMessage(msg);
if(msg.what==1)
{
ipInfo.append(msg.obj.toString());
}
}
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ipInfo=(TextView) findViewById(R.id.ip_info);
thread=new Thread(this);
try
{
multicastSocket = new MulticastSocket(BROADCAST_PORT);
inetAddress=InetAddress.getByName(BROADCAST_IP);
multicastSocket.joinGroup(inetAddress);
thread.start();
} catch (Exception e1)
{
e1.printStackTrace();
}
}
@Override
public void run( )
{
// TODO Auto-generated method stub
Message msg=new Message();
msg.what=1;
byte buf[] = new byte[1024];
DatagramPacket dp =null;
dp=new DatagramPacket(buf,buf.length,inetAddress,BROADCAST_PORT);
while (true)
{
try
{
multicastSocket.receive(dp);
Thread.sleep(3000);
ip=new String(buf, 0, dp.getLength());
msg.obj=ip;
myHandler.sendMessage(msg);
System.out.println("检测到服务端IP : "+ip);
// Toast.makeText(this, new String(buf, 0, dp.getLength()), Toast.LENGTH_SHORT);
} catch (Exception e)
{
e.printStackTrace();
}
}
}
@Override
protected void onDestroy()
{
super.onDestroy();
multicastSocket.close();
System.out.println("UDP Client程序退出,关掉socket,停止广播");
finish();
}
}

Binary file not shown.

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SocketAutoConnectServer</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.socketautoconnect.server"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".SocketAutoConnectServer"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" ></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" ></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" ></uses-permission>
<uses-permission android:name="android.permission.INTERNET" ></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK" ></uses-permission>
</manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -0,0 +1,27 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.socketautoconnect.server;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
}
public static final class id {
public static final int ip_info=0x7f050001;
public static final int sendUDPBrocast=0x7f050000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}

View File

@ -0,0 +1,40 @@
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}

View File

@ -0,0 +1,11 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "ant.properties", and override values to adapt the script to your
# project structure.
# Project target.
target=android-7

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/sendUDPBrocast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="停止广播"/>
<TextView
android:id="@+id/ip_info"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20dip"
android:text="服务端自身IP: " />
"
</LinearLayout>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, SocketAutoConnectClient!</string>
<string name="app_name">UDP Server</string>
</resources>

View File

@ -0,0 +1,134 @@
package com.socketautoconnect.server;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import java.lang.*;
public class SocketAutoConnectServer extends Activity implements Runnable
{
private static String ip; //服务端ip
private static int BROADCAST_PORT=9898;
private static String BROADCAST_IP="224.0.0.1";
InetAddress inetAddress=null;
Thread t=null;
/*发送广播端的socket*/
MulticastSocket multicastSocket=null;
/*发送广播的按钮*/
private Button sendUDPBrocast;
private volatile boolean isRuning= true;
TextView ipInfo;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ipInfo=(TextView) findViewById(R.id.ip_info);
sendUDPBrocast=(Button) findViewById(R.id.sendUDPBrocast);
sendUDPBrocast.setOnClickListener(new SendUDPBrocastListener());
//Wifi状态判断
WifiManager wifiManager=(WifiManager) getSystemService (Context.WIFI_SERVICE);
if(wifiManager.isWifiEnabled())
{
WifiInfo wifiInfo=wifiManager.getConnectionInfo();
ip=getIpString(wifiInfo.getIpAddress());
ipInfo.append(ip);
System.out.println("服务端的wifi IP:"+ip);
}
try
{
inetAddress=InetAddress.getByName(BROADCAST_IP);
multicastSocket=new MulticastSocket(BROADCAST_PORT);
multicastSocket.setTimeToLive(1);
multicastSocket.joinGroup(inetAddress);
}catch(Exception e)
{
e.printStackTrace();
}
t=new Thread(this);
t.start();
}
//将获取到的int型ip转成string类型
private String getIpString(int i)
{
return (i & 0xFF) + "." +((i >> 8) & 0xFF) + "."
+((i >> 16) & 0xFF) + "." +(i >> 24 & 0xFF);
}
class SendUDPBrocastListener implements OnClickListener
{
@Override
public void onClick(View v)
{
if(isRuning)
{
isRuning=false;
sendUDPBrocast.setText("发送广播");
System.out.println("现在停止广播..");
}else
{
isRuning=true;
sendUDPBrocast.setText("停止广播");
System.out.println("现在发送广播..");
}
}
}
@Override
public void run()
{
//发送的数据包局网内的所有地址都可以收到该数据包
DatagramPacket dataPacket = null;
//将本机的IP这里可以写动态获取的IP地址放到数据包里其实server端接收到数据包后也能获取到发包方的IP的
byte[] data =ip.getBytes();
dataPacket = new DatagramPacket(data, data.length, inetAddress,BROADCAST_PORT);
while(true)
{
if(isRuning)
{
try
{
multicastSocket.send(dataPacket);
Thread.sleep(3000);
System.out.println("再次发送ip地址广播:.....");
} catch (Exception e)
{
e.printStackTrace();
}
}
}
}
@Override
protected void onDestroy()
{
super.onDestroy();
isRuning=false;
multicastSocket.close();
System.out.println("UDP Server程序退出,关掉socket,停止广播");
finish();
}
}

@ -0,0 +1 @@
Subproject commit 4fbd1e1f1364aba7c85d5c9920d8bde433339b50

@ -0,0 +1 @@
Subproject commit e3dae38f4e371b2d85101e2fd8959f5c8db4f596

@ -0,0 +1 @@
Subproject commit d3f6017a1ef133525f75f4d78e399e6fd6b70ce6

@ -0,0 +1 @@
Subproject commit 6caa6e438f2edeb002a8d31a4746993580b4eafe