1.Lcd测试代码:
view plaincopy to clipboardprint?
package com.android.factorytest;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class TestColor extends Activity{
private static final String TAG = "TestColor";
private Button mReturn = null;
private Button mChangeColor = null;
private Button mNext = null;
private TextView mText1 = null;
private TextView mText2 = null;
private TextView mText3 = null;
private Intent mIntent = null;
private int mNum = 0;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_color);
initView();
}
private void initView()
{
setTitle(R.string.test_color_mess);
mReturn = (Button)findViewById(R.id.but_return);
mChangeColor = (Button)findViewById(R.id.but_changecolor);
mNext = (Button)findViewById(R.id.but_next);
mText1 = (TextView)findViewById(R.id.test_color_text1);
mText2 = (TextView)findViewById(R.id.test_color_text2);
mText3 = (TextView)findViewById(R.id.test_color_text3);
mReturn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestColor.this, MainActivity.class);
startActivity(mIntent);
}
});
mNext.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestColor.this, TestSd.class);
//mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(mIntent);
}
});
mChangeColor.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mNum ++;
changeColor(mNum);
}
});
}
private void changeColor(int num)
{
Log.e(TAG, "num = " + (num%6));
switch(num % 6)
{
case 0:
mText1.setBackgroundColor(Color.RED);
mText2.setBackgroundColor(Color.RED);
mText3.setBackgroundColor(Color.RED);
break;
case 1:
mText1.setBackgroundColor(Color.GREEN);
mText2.setBackgroundColor(Color.GREEN);
mText3.setBackgroundColor(Color.GREEN);
break;
case 2:
mText1.setBackgroundColor(Color.BLUE);
mText2.setBackgroundColor(Color.BLUE);
mText3.setBackgroundColor(Color.BLUE);
break;
case 3:
mText1.setBackgroundColor(Color.RED);
mText2.setBackgroundColor(Color.RED);
mText3.setBackgroundColor(Color.RED);
break;
case 4:
mText1.setBackgroundColor(Color.GREEN);
mText2.setBackgroundColor(Color.GREEN);
mText3.setBackgroundColor(Color.GREEN);
break;
case 5:
mText1.setBackgroundColor(Color.BLUE);
mText2.setBackgroundColor(Color.BLUE);
mText3.setBackgroundColor(Color.BLUE);
break;
}
}
}
package com.android.factorytest;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class TestColor extends Activity{
private static final String TAG = "TestColor";
private Button mReturn = null;
private Button mChangeColor = null;
private Button mNext = null;
private TextView mText1 = null;
private TextView mText2 = null;
private TextView mText3 = null;
private Intent mIntent = null;
private int mNum = 0;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_color);
initView();
}
private void initView()
{
setTitle(R.string.test_color_mess);
mReturn = (Button)findViewById(R.id.but_return);
mChangeColor = (Button)findViewById(R.id.but_changecolor);
mNext = (Button)findViewById(R.id.but_next);
mText1 = (TextView)findViewById(R.id.test_color_text1);
mText2 = (TextView)findViewById(R.id.test_color_text2);
mText3 = (TextView)findViewById(R.id.test_color_text3);
mReturn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestColor.this, MainActivity.class);
startActivity(mIntent);
}
});
mNext.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestColor.this, TestSd.class);
//mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(mIntent);
}
});
mChangeColor.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mNum ++;
changeColor(mNum);
}
});
}
private void changeColor(int num)
{
Log.e(TAG, "num = " + (num%6));
switch(num % 6)
{
case 0:
mText1.setBackgroundColor(Color.RED);
mText2.setBackgroundColor(Color.RED);
mText3.setBackgroundColor(Color.RED);
break;
case 1:
mText1.setBackgroundColor(Color.GREEN);
mText2.setBackgroundColor(Color.GREEN);
mText3.setBackgroundColor(Color.GREEN);
break;
case 2:
mText1.setBackgroundColor(Color.BLUE);
mText2.setBackgroundColor(Color.BLUE);
mText3.setBackgroundColor(Color.BLUE);
break;
case 3:
mText1.setBackgroundColor(Color.RED);
mText2.setBackgroundColor(Color.RED);
mText3.setBackgroundColor(Color.RED);
break;
case 4:
mText1.setBackgroundColor(Color.GREEN);
mText2.setBackgroundColor(Color.GREEN);
mText3.setBackgroundColor(Color.GREEN);
break;
case 5:
mText1.setBackgroundColor(Color.BLUE);
mText2.setBackgroundColor(Color.BLUE);
mText3.setBackgroundColor(Color.BLUE);
break;
}
}
}
LCD测试XML:
view plaincopy to clipboardprint?
<?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:background="#383838"
android:orientation="vertical"
android:gravity="center" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<TextView android:id="@+id/test_color_text1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffff0000" />
<TextView android:id="@+id/test_color_text2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffff0000" />
<TextView android:id="@+id/test_color_text3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffff0000" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center">
<Button android:id="@+id/but_return"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="@string/but_return" />
<Button android:id="@+id/but_changecolor"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_changecolor" />
<Button android:id="@+id/but_next"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:text="@string/but_next" />
</LinearLayout>
</LinearLayout>
<?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:background="#383838"
android:orientation="vertical"
android:gravity="center" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<TextView android:id="@+id/test_color_text1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffff0000" />
<TextView android:id="@+id/test_color_text2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffff0000" />
<TextView android:id="@+id/test_color_text3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffff0000" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center">
<Button android:id="@+id/but_return"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="@string/but_return" />
<Button android:id="@+id/but_changecolor"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_changecolor" />
<Button android:id="@+id/but_next"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:text="@string/but_next" />
</LinearLayout>
</LinearLayout>
2.SD卡测试代码:
view plaincopy to clipboardprint?
package com.android.factorytest;
import java.io.File;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
public class TestSd extends Activity
{
private static final String LOG_TAG = null;
private TextView mTestSd = null;
private Button mReturn = null;
private Button mNext = null;
private Intent mIntent = null;
private File sdcardDir;
//private String PATH ="/abc";
private String FILENAME = "/sdcard/cet4hard.txt";
//private String FILENAME = "/mnt/sdcard/cet4hard.txt";//emulator test
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_sd);
sdcardDir = Environment.getExternalStorageDirectory();
initView();
}
private void initView()
{
try
{
Log.d(LOG_TAG,"Start Write");
if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
{
//File path = new File(sdcardDir+PATH);
File f = new File(sdcardDir + FILENAME);
//File f = new File(FILENAME);//emulator test
boolean flag = false;
//if(!path.exists())
//{
// flag = path.mkdirs();
// if(flag)
// {
// mTestSd = (TextView)findViewById(R.id.test_sd);
// mTestSd.setText(R.string.test_sd_mess3);
// }
// else
// {
// mTestSd = (TextView)findViewById(R.id.test_sd_delete);
// setContentView(R.id.test_sd_delete);
// }
//}
if(!f.exists())
{
flag = f.createNewFile();
if(flag)
{
mTestSd = (TextView)findViewById(R.id.test_sd_create);
mTestSd.setText(R.string.test_sd_mess3);
mTestSd.setTextColor(Color.GREEN);
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(f));
String editor = "fdfd";
osw.write(editor.toString());
osw.close();
}
else
{
mTestSd = (TextView)findViewById(R.id.test_sd_create);
mTestSd.setText(R.string.test_sd_mess5);
mTestSd.setTextColor(Color.RED);
}
}
else
{
mTestSd = (TextView)findViewById(R.id.test_sd_create);
mTestSd.setText(R.string.test_sd_mess5);
mTestSd.setTextColor(Color.RED);
}
if(f.exists())
{
flag = f.delete();
if(flag)
{
mTestSd = (TextView)findViewById(R.id.test_sd_delete);
mTestSd.setText(R.string.test_sd_mess4);
mTestSd.setTextColor(Color.GREEN);
}
else
{
mTestSd = (TextView)findViewById(R.id.test_sd_delete);
mTestSd.setText(R.string.test_sd_mess6);
mTestSd.setTextColor(Color.RED);
}
}
else
{
mTestSd = (TextView)findViewById(R.id.test_sd_delete);
mTestSd.setText(R.string.test_sd_mess6);
mTestSd.setTextColor(Color.RED);
}
}
else
{
mTestSd = (TextView)findViewById(R.id.test_sd);
mTestSd.setText(R.string.test_sd_mess2);
mTestSd.setTextColor(Color.RED);
}
}
catch(Exception e)
{
Log.d(LOG_TAG,"file create error");
}
mReturn = (Button)findViewById(R.id.but_return);
mNext = (Button)findViewById(R.id.but_next);
mReturn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestSd.this, MainActivity.class);
startActivity(mIntent);
}
});
mNext.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestSd.this, TestCamera.class);
//mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(mIntent);
}
});
}
}
package com.android.factorytest;
import java.io.File;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
public class TestSd extends Activity
{
private static final String LOG_TAG = null;
private TextView mTestSd = null;
private Button mReturn = null;
private Button mNext = null;
private Intent mIntent = null;
private File sdcardDir;
//private String PATH ="/abc";
private String FILENAME = "/sdcard/cet4hard.txt";
//private String FILENAME = "/mnt/sdcard/cet4hard.txt";//emulator test
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_sd);
sdcardDir = Environment.getExternalStorageDirectory();
initView();
}
private void initView()
{
try
{
Log.d(LOG_TAG,"Start Write");
if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
{
//File path = new File(sdcardDir+PATH);
File f = new File(sdcardDir + FILENAME);
//File f = new File(FILENAME);//emulator test
boolean flag = false;
//if(!path.exists())
//{
// flag = path.mkdirs();
// if(flag)
// {
// mTestSd = (TextView)findViewById(R.id.test_sd);
// mTestSd.setText(R.string.test_sd_mess3);
// }
// else
// {
// mTestSd = (TextView)findViewById(R.id.test_sd_delete);
// setContentView(R.id.test_sd_delete);
// }
//}
if(!f.exists())
{
flag = f.createNewFile();
if(flag)
{
mTestSd = (TextView)findViewById(R.id.test_sd_create);
mTestSd.setText(R.string.test_sd_mess3);
mTestSd.setTextColor(Color.GREEN);
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(f));
String editor = "fdfd";
osw.write(editor.toString());
osw.close();
}
else
{
mTestSd = (TextView)findViewById(R.id.test_sd_create);
mTestSd.setText(R.string.test_sd_mess5);
mTestSd.setTextColor(Color.RED);
}
}
else
{
mTestSd = (TextView)findViewById(R.id.test_sd_create);
mTestSd.setText(R.string.test_sd_mess5);
mTestSd.setTextColor(Color.RED);
}
if(f.exists())
{
flag = f.delete();
if(flag)
{
mTestSd = (TextView)findViewById(R.id.test_sd_delete);
mTestSd.setText(R.string.test_sd_mess4);
mTestSd.setTextColor(Color.GREEN);
}
else
{
mTestSd = (TextView)findViewById(R.id.test_sd_delete);
mTestSd.setText(R.string.test_sd_mess6);
mTestSd.setTextColor(Color.RED);
}
}
else
{
mTestSd = (TextView)findViewById(R.id.test_sd_delete);
mTestSd.setText(R.string.test_sd_mess6);
mTestSd.setTextColor(Color.RED);
}
}
else
{
mTestSd = (TextView)findViewById(R.id.test_sd);
mTestSd.setText(R.string.test_sd_mess2);
mTestSd.setTextColor(Color.RED);
}
}
catch(Exception e)
{
Log.d(LOG_TAG,"file create error");
}
mReturn = (Button)findViewById(R.id.but_return);
mNext = (Button)findViewById(R.id.but_next);
mReturn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestSd.this, MainActivity.class);
startActivity(mIntent);
}
});
mNext.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestSd.this, TestCamera.class);
//mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(mIntent);
}
});
}
}
SD卡测试XML:
view plaincopy to clipboardprint?
<?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:background="#383838"
android:orientation="vertical"
android:gravity="center" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center" >
<TextView
android:id="@+id/test_sd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center" >
<TextView
android:id="@+id/test_sd_create"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center" >
<TextView
android:id="@+id/test_sd_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center">
<Button android:id="@+id/but_return"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_return" />
<Button android:id="@+id/but_next"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_next" />
</LinearLayout>
</LinearLayout>
<?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:background="#383838"
android:orientation="vertical"
android:gravity="center" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center" >
<TextView
android:id="@+id/test_sd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center" >
<TextView
android:id="@+id/test_sd_create"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center" >
<TextView
android:id="@+id/test_sd_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center">
<Button android:id="@+id/but_return"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_return" />
<Button android:id="@+id/but_next"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_next" />
</LinearLayout>
</LinearLayout>
3.Camera测试代码:
view plaincopy to clipboardprint?
package com.android.factorytest;
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.provider.MediaStore;
import android.view.View;
import android.widget.Button;
public class TestCamera extends Activity
{
private Button mReturn = null;
private Button mChangeCamera = null;
private Button mNext = null;
private Intent mIntent = null;
private static int TAKE_PICTURE = 1;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_camera);
initView();
RegListener();
}
public void RegListener() {
ExitListenerReceiver exitre = new ExitListenerReceiver();
IntentFilter intentfilter = new IntentFilter();
intentfilter.addAction(this.getPackageName() + "."
+ "ExitListenerReceiver");
this.registerReceiver(exitre, intentfilter);
}
class ExitListenerReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
((Activity) arg0).finish();
}
}
private void initView()
{
setTitle(R.string.test_camera_mess);
mReturn = (Button)findViewById(R.id.but_return);
mChangeCamera = (Button)findViewById(R.id.but_changecamera);
mNext = (Button)findViewById(R.id.but_next);
mReturn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestCamera.this, MainActivity.class);
startActivity(mIntent);
}
});
mNext.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestCamera.this, TestWiFi.class);
//mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(mIntent);
}
});
mChangeCamera.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(mIntent,TAKE_PICTURE);
}
});
}
}
package com.android.factorytest;
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.provider.MediaStore;
import android.view.View;
import android.widget.Button;
public class TestCamera extends Activity
{
private Button mReturn = null;
private Button mChangeCamera = null;
private Button mNext = null;
private Intent mIntent = null;
private static int TAKE_PICTURE = 1;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_camera);
initView();
RegListener();
}
public void RegListener() {
ExitListenerReceiver exitre = new ExitListenerReceiver();
IntentFilter intentfilter = new IntentFilter();
intentfilter.addAction(this.getPackageName() + "."
+ "ExitListenerReceiver");
this.registerReceiver(exitre, intentfilter);
}
class ExitListenerReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
((Activity) arg0).finish();
}
}
private void initView()
{
setTitle(R.string.test_camera_mess);
mReturn = (Button)findViewById(R.id.but_return);
mChangeCamera = (Button)findViewById(R.id.but_changecamera);
mNext = (Button)findViewById(R.id.but_next);
mReturn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestCamera.this, MainActivity.class);
startActivity(mIntent);
}
});
mNext.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestCamera.this, TestWiFi.class);
//mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(mIntent);
}
});
mChangeCamera.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(mIntent,TAKE_PICTURE);
}
});
}
}
Camera测试XML:
view plaincopy to clipboardprint?
<?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:background="#383838"
android:orientation="vertical"
android:gravity="center" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/test_camera_mess" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center">
<Button android:id="@+id/but_return"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="@string/but_return" />
<Button android:id="@+id/but_changecamera"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_camera_open" />
<Button android:id="@+id/but_next"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:text="@string/but_next" />
</LinearLayout>
</LinearLayout>
<?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:background="#383838"
android:orientation="vertical"
android:gravity="center" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/test_camera_mess" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center">
<Button android:id="@+id/but_return"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="@string/but_return" />
<Button android:id="@+id/but_changecamera"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_camera_open" />
<Button android:id="@+id/but_next"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:text="@string/but_next" />
</LinearLayout>
</LinearLayout>
4.Wifi测试代码:
view plaincopy to clipboardprint?
package com.android.factorytest;
import android.app.Activity;
import android.content.Intent;
//import android.net.ConnectivityManager;
//import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class TestWiFi extends Activity
{
private static final String TAG = "TestWiFi";
private Button mReturn = null;
private Button mChangeState = null;
private Button mNext = null;
private Intent mIntent = null;
private WifiManager mWifiManager = null;
//private ConnectivityManager connectivity = null;
private int mWifiState = -1;
//private int networkPreference = -1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_wifi);
initView();
}
private void initView()
{
mReturn = (Button) findViewById(R.id.but_return);
mNext = (Button) findViewById(R.id.but_next);
mChangeState = (Button) findViewById(R.id.but_changestate);
if (mChangeState == null)
Log.e(TAG, "mChangeState is null ");
mReturn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestWiFi.this, MainActivity.class);
startActivity(mIntent);
}
});
mNext.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestWiFi.this, TestBluetooth.class);
//mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(mIntent);
}
});
mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
if (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED)
{
mWifiState = 1;
//将当前网络设置为首选网络
//connectivity = (ConnectivityManager)getSystemService(WIFI_SERVICE);
//networkPreference = connectivity .getNetworkPreference();
//connectivity.setNetworkPreference(networkPreference);
//mChangeState.setText(R.string.but_wifi_close);
mChangeState.setText(R.string.test_wifi_mess_enter_wifisetting);
}
else if (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLED)
{
mWifiState = 0;
//mChangeState.setText(R.string.but_wifi_open);
mChangeState.setText(R.string.test_wifi_mess_enter_wifisetting);
}
else
{
Log.e(TAG, "Wifi State = " + mWifiManager.getWifiState());
}
mChangeState.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
changeWifiState(mWifiState);
mWifiState ++;
}
});
}
private void changeWifiState(int state)
{
Log.e(TAG, "mWifiState = " + state);
Toast.makeText(this, R.string.test_wifi_mess_enter_wifisetting, Toast.LENGTH_LONG).show();
//startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));//进入无线网络配置界面
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS)); //直接进入wifi网络设置界面
switch (state % 2)
{
case 0:
{
new Thread()
{
public void run()
{
Log.e(TAG, "setWifiEnabled(true)");
mWifiManager.setWifiEnabled(true);
}
}.start();
// if(mIntent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION))
// {
// Toast.makeText(this, R.string.test_wifi_mess_state_changed, Toast.LENGTH_LONG).show();
// }
while ((mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLING) ||
(mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED))
{
Toast.makeText(this, R.string.test_wifi_mess_enable, Toast.LENGTH_LONG).show();
break;
}
//获取网络列表并激活一个网络连接
//List<WifiConfiguration> configurations = mWifiManager.getConfiguredNetworks();
//if(configurations.size() > 0)
//{
// int netID = configurations.get(0).networkId;
// boolean disableAllOthers = true;
// mWifiManager.enableNetwork(netID, disableAllOthers);
//}
//mChangeState.setText(R.string.but_wifi_close);
mChangeState.setText(R.string.test_wifi_mess_enter_wifisetting);
break;
}
case 1:
{
new Thread()
{
public void run()
{
Log.e(TAG, "setWifiEnabled(false)");
mWifiManager.setWifiEnabled(false);
}
}.start();
//mChangeState.setText(R.string.but_wifi_open);
mChangeState.setText(R.string.test_wifi_mess_enter_wifisetting);
// if(mIntent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION))
// {
// Toast.makeText(this, R.string.test_wifi_mess_state_changed, Toast.LENGTH_LONG).show();
// }
while ((mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLING) ||
(mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLED))
{
Toast.makeText(this, R.string.test_wifi_mess_disable, Toast.LENGTH_LONG).show();
break;
}
break;
}
default:
Log.e(TAG, "Wifi state error !");
Toast.makeText(this, R.string.test_wifi_mess_error, Toast.LENGTH_LONG).show();
break;
}
}
}
package com.android.factorytest;
import android.app.Activity;
import android.content.Intent;
//import android.net.ConnectivityManager;
//import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class TestWiFi extends Activity
{
private static final String TAG = "TestWiFi";
private Button mReturn = null;
private Button mChangeState = null;
private Button mNext = null;
private Intent mIntent = null;
private WifiManager mWifiManager = null;
//private ConnectivityManager connectivity = null;
private int mWifiState = -1;
//private int networkPreference = -1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_wifi);
initView();
}
private void initView()
{
mReturn = (Button) findViewById(R.id.but_return);
mNext = (Button) findViewById(R.id.but_next);
mChangeState = (Button) findViewById(R.id.but_changestate);
if (mChangeState == null)
Log.e(TAG, "mChangeState is null ");
mReturn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestWiFi.this, MainActivity.class);
startActivity(mIntent);
}
});
mNext.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestWiFi.this, TestBluetooth.class);
//mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(mIntent);
}
});
mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
if (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED)
{
mWifiState = 1;
//将当前网络设置为首选网络
//connectivity = (ConnectivityManager)getSystemService(WIFI_SERVICE);
//networkPreference = connectivity .getNetworkPreference();
//connectivity.setNetworkPreference(networkPreference);
//mChangeState.setText(R.string.but_wifi_close);
mChangeState.setText(R.string.test_wifi_mess_enter_wifisetting);
}
else if (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLED)
{
mWifiState = 0;
//mChangeState.setText(R.string.but_wifi_open);
mChangeState.setText(R.string.test_wifi_mess_enter_wifisetting);
}
else
{
Log.e(TAG, "Wifi State = " + mWifiManager.getWifiState());
}
mChangeState.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
changeWifiState(mWifiState);
mWifiState ++;
}
});
}
private void changeWifiState(int state)
{
Log.e(TAG, "mWifiState = " + state);
Toast.makeText(this, R.string.test_wifi_mess_enter_wifisetting, Toast.LENGTH_LONG).show();
//startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));//进入无线网络配置界面
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS)); //直接进入wifi网络设置界面
switch (state % 2)
{
case 0:
{
new Thread()
{
public void run()
{
Log.e(TAG, "setWifiEnabled(true)");
mWifiManager.setWifiEnabled(true);
}
}.start();
// if(mIntent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION))
// {
// Toast.makeText(this, R.string.test_wifi_mess_state_changed, Toast.LENGTH_LONG).show();
// }
while ((mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLING) ||
(mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED))
{
Toast.makeText(this, R.string.test_wifi_mess_enable, Toast.LENGTH_LONG).show();
break;
}
//获取网络列表并激活一个网络连接
//List<WifiConfiguration> configurations = mWifiManager.getConfiguredNetworks();
//if(configurations.size() > 0)
//{
// int netID = configurations.get(0).networkId;
// boolean disableAllOthers = true;
// mWifiManager.enableNetwork(netID, disableAllOthers);
//}
//mChangeState.setText(R.string.but_wifi_close);
mChangeState.setText(R.string.test_wifi_mess_enter_wifisetting);
break;
}
case 1:
{
new Thread()
{
public void run()
{
Log.e(TAG, "setWifiEnabled(false)");
mWifiManager.setWifiEnabled(false);
}
}.start();
//mChangeState.setText(R.string.but_wifi_open);
mChangeState.setText(R.string.test_wifi_mess_enter_wifisetting);
// if(mIntent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION))
// {
// Toast.makeText(this, R.string.test_wifi_mess_state_changed, Toast.LENGTH_LONG).show();
// }
while ((mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLING) ||
(mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLED))
{
Toast.makeText(this, R.string.test_wifi_mess_disable, Toast.LENGTH_LONG).show();
break;
}
break;
}
default:
Log.e(TAG, "Wifi state error !");
Toast.makeText(this, R.string.test_wifi_mess_error, Toast.LENGTH_LONG).show();
break;
}
}
}
Wifi测试XML:
view plaincopy to clipboardprint?
<?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:background="#383838"
android:orientation="vertical"
android:gravity="center" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/test_wifi_mess" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center">
<Button android:id="@+id/but_return"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_return" />
<Button android:id="@+id/but_changestate"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_wifi_close" />
<Button android:id="@+id/but_next"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_next" />
</LinearLayout>
</LinearLayout>
<?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:background="#383838"
android:orientation="vertical"
android:gravity="center" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/test_wifi_mess" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center">
<Button android:id="@+id/but_return"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_return" />
<Button android:id="@+id/but_changestate"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_wifi_close" />
<Button android:id="@+id/but_next"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_next" />
</LinearLayout>
</LinearLayout>
5.Bluetooth测试代码:
view plaincopy to clipboardprint?
package com.android.factorytest;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class TestBluetooth extends Activity
{
private static final String TAG = "TestBluetooth";
private TextView mBluetoothstate = null;
private Button mReturn = null;
private Button mChangeState = null;
private Button mNext = null;
private Intent mIntent = null;
private BluetoothAdapter mBluetooth = null;
private int mBluetoothState = -1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_bluetooth);
initView();
}
private void initView()
{
mReturn = (Button) findViewById(R.id.but_return);
mNext = (Button) findViewById(R.id.but_next);
mChangeState = (Button) findViewById(R.id.but_changestate);
mBluetoothstate = (TextView)findViewById(R.id.bluetooth_state);
if (mChangeState == null)
Log.e(TAG, "mChangeState is null ");
mReturn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestBluetooth.this, MainActivity.class);
startActivity(mIntent);
}
});
mNext.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestBluetooth.this, TestColor.class);
finish();
startActivity(mIntent);
}
});
mBluetooth = BluetoothAdapter.getDefaultAdapter();
if(null == mBluetooth)
{
mBluetoothstate.setText("No Bluetooth Device");
mBluetoothstate.setTextColor(Color.RED);
}
if (mBluetooth.isEnabled())
{
mBluetoothState = 1;
mChangeState.setText(R.string.but_bluetooth_close);
}
else if (!mBluetooth.isEnabled())
{
mBluetoothState = 0;
mChangeState.setText(R.string.but_bluetooth_open);
}
else
{
Log.e(TAG, "Bluetooth State = ");
}
mChangeState.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
startActivity(new Intent(Settings.ACTION_BLUETOOTH_SETTINGS));//进入Bluetooth配置界面
changeBluetoothState(mBluetoothState);
mBluetoothState ++;
}
});
}
private void changeBluetoothState(int state)
{
Log.e(TAG, "mBluetoothState = " + state);
switch (state % 2)
{
case 0:
{
startBluetooth();
Toast.makeText(this, R.string.test_bluetooth_mess_state_changed, Toast.LENGTH_LONG).show();
mChangeState.setText(R.string.but_bluetooth_close);
break;
}
case 1:
{
stopBluetooth();
Toast.makeText(this, R.string.test_bluetooth_mess_state_changed, Toast.LENGTH_LONG).show();
mChangeState.setText(R.string.but_bluetooth_open);
break;
}
default:
Log.e(TAG, "Wifi state error !");
Toast.makeText(this, R.string.test_bluetooth_mess_error, Toast.LENGTH_LONG).show();
break;
}
}
private void startBluetooth()
{
mBluetoothstate = (TextView)findViewById(R.id.bluetooth_state);
mBluetooth = BluetoothAdapter.getDefaultAdapter();
if(null == mBluetooth)
{
mBluetoothstate.setText("No Bluetooth Device");
mBluetoothstate.setTextColor(Color.RED);
}
BroadcastReceiver BluetoothState = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
//String prevStateExtra = BluetoothAdapter.EXTRA_PREVIOUS_STATE;
String stateExtra = BluetoothAdapter.EXTRA_STATE;
int state = intent.getIntExtra(stateExtra, -1);
//int previousState = intent.getIntExtra(prevStateExtra, -1);
String tt = "";
switch(state)
{
case (BluetoothAdapter.STATE_TURNING_ON):
{
tt = "Bluetooth turning on";
break;
}
case (BluetoothAdapter.STATE_ON):
{
tt = "Bluetooth on";
unregisterReceiver(this);
break;
}
case (BluetoothAdapter.STATE_TURNING_OFF):
{
tt = "Bluetooth turning off";
break;
}
case (BluetoothAdapter.STATE_OFF):
{
tt = "Bluetooth off";
break;
}
default:
tt = "Unkown Bluetooth state!";
break;
}
//Toast.makeText(this, tt, Toast.LENGTH_LONG).show();
mBluetoothstate.setText(tt);
}
};
if(!mBluetooth.isEnabled())
{
String actionStateChanged = BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED;
//String actionRequestEnable = BluetoothAdapter.ACTION_REQUEST_ENABLE;
registerReceiver(BluetoothState, new IntentFilter(actionStateChanged));
//startActivityForResult(new Intent(actionRequestEnable),0);
mBluetooth.enable();
}
}
private void stopBluetooth()
{
mBluetoothstate = (TextView)findViewById(R.id.bluetooth_state);
mBluetooth = BluetoothAdapter.getDefaultAdapter();
if(null == mBluetooth)
{
mBluetoothstate.setText("No Bluetooth Device");
mBluetoothstate.setTextColor(Color.RED);
}
BroadcastReceiver BluetoothState = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
//String prevStateExtra = BluetoothAdapter.EXTRA_PREVIOUS_STATE;
String stateExtra = BluetoothAdapter.EXTRA_STATE;
int state = intent.getIntExtra(stateExtra, -1);
//int previousState = intent.getIntExtra(prevStateExtra, -1);
String tt = "Unkown Bluetooth";
switch(state)
{
case (BluetoothAdapter.STATE_TURNING_ON):
{
tt = "Bluetooth turning on";
break;
}
case (BluetoothAdapter.STATE_ON):
{
tt = "Bluetooth on";
unregisterReceiver(this);
break;
}
case (BluetoothAdapter.STATE_TURNING_OFF):
{
tt = "Bluetooth turning off";
break;
}
case (BluetoothAdapter.STATE_OFF):
{
tt = "Bluetooth off";
break;
}
default:
tt = "Unkown Bluetooth state!";
break;
}
//Toast.makeText(this, tt, Toast.LENGTH_LONG).show();
mBluetoothstate.setText(tt);
}
};
if(mBluetooth.isEnabled())
{
String actionStateChanged = BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED;
registerReceiver(BluetoothState, new IntentFilter(actionStateChanged));
mBluetooth.disable();
}
}
}
package com.android.factorytest;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class TestBluetooth extends Activity
{
private static final String TAG = "TestBluetooth";
private TextView mBluetoothstate = null;
private Button mReturn = null;
private Button mChangeState = null;
private Button mNext = null;
private Intent mIntent = null;
private BluetoothAdapter mBluetooth = null;
private int mBluetoothState = -1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_bluetooth);
initView();
}
private void initView()
{
mReturn = (Button) findViewById(R.id.but_return);
mNext = (Button) findViewById(R.id.but_next);
mChangeState = (Button) findViewById(R.id.but_changestate);
mBluetoothstate = (TextView)findViewById(R.id.bluetooth_state);
if (mChangeState == null)
Log.e(TAG, "mChangeState is null ");
mReturn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestBluetooth.this, MainActivity.class);
startActivity(mIntent);
}
});
mNext.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestBluetooth.this, TestColor.class);
finish();
startActivity(mIntent);
}
});
mBluetooth = BluetoothAdapter.getDefaultAdapter();
if(null == mBluetooth)
{
mBluetoothstate.setText("No Bluetooth Device");
mBluetoothstate.setTextColor(Color.RED);
}
if (mBluetooth.isEnabled())
{
mBluetoothState = 1;
mChangeState.setText(R.string.but_bluetooth_close);
}
else if (!mBluetooth.isEnabled())
{
mBluetoothState = 0;
mChangeState.setText(R.string.but_bluetooth_open);
}
else
{
Log.e(TAG, "Bluetooth State = ");
}
mChangeState.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
startActivity(new Intent(Settings.ACTION_BLUETOOTH_SETTINGS));//进入Bluetooth配置界面
changeBluetoothState(mBluetoothState);
mBluetoothState ++;
}
});
}
private void changeBluetoothState(int state)
{
Log.e(TAG, "mBluetoothState = " + state);
switch (state % 2)
{
case 0:
{
startBluetooth();
Toast.makeText(this, R.string.test_bluetooth_mess_state_changed, Toast.LENGTH_LONG).show();
mChangeState.setText(R.string.but_bluetooth_close);
break;
}
case 1:
{
stopBluetooth();
Toast.makeText(this, R.string.test_bluetooth_mess_state_changed, Toast.LENGTH_LONG).show();
mChangeState.setText(R.string.but_bluetooth_open);
break;
}
default:
Log.e(TAG, "Wifi state error !");
Toast.makeText(this, R.string.test_bluetooth_mess_error, Toast.LENGTH_LONG).show();
break;
}
}
private void startBluetooth()
{
mBluetoothstate = (TextView)findViewById(R.id.bluetooth_state);
mBluetooth = BluetoothAdapter.getDefaultAdapter();
if(null == mBluetooth)
{
mBluetoothstate.setText("No Bluetooth Device");
mBluetoothstate.setTextColor(Color.RED);
}
BroadcastReceiver BluetoothState = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
//String prevStateExtra = BluetoothAdapter.EXTRA_PREVIOUS_STATE;
String stateExtra = BluetoothAdapter.EXTRA_STATE;
int state = intent.getIntExtra(stateExtra, -1);
//int previousState = intent.getIntExtra(prevStateExtra, -1);
String tt = "";
switch(state)
{
case (BluetoothAdapter.STATE_TURNING_ON):
{
tt = "Bluetooth turning on";
break;
}
case (BluetoothAdapter.STATE_ON):
{
tt = "Bluetooth on";
unregisterReceiver(this);
break;
}
case (BluetoothAdapter.STATE_TURNING_OFF):
{
tt = "Bluetooth turning off";
break;
}
case (BluetoothAdapter.STATE_OFF):
{
tt = "Bluetooth off";
break;
}
default:
tt = "Unkown Bluetooth state!";
break;
}
//Toast.makeText(this, tt, Toast.LENGTH_LONG).show();
mBluetoothstate.setText(tt);
}
};
if(!mBluetooth.isEnabled())
{
String actionStateChanged = BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED;
//String actionRequestEnable = BluetoothAdapter.ACTION_REQUEST_ENABLE;
registerReceiver(BluetoothState, new IntentFilter(actionStateChanged));
//startActivityForResult(new Intent(actionRequestEnable),0);
mBluetooth.enable();
}
}
private void stopBluetooth()
{
mBluetoothstate = (TextView)findViewById(R.id.bluetooth_state);
mBluetooth = BluetoothAdapter.getDefaultAdapter();
if(null == mBluetooth)
{
mBluetoothstate.setText("No Bluetooth Device");
mBluetoothstate.setTextColor(Color.RED);
}
BroadcastReceiver BluetoothState = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
//String prevStateExtra = BluetoothAdapter.EXTRA_PREVIOUS_STATE;
String stateExtra = BluetoothAdapter.EXTRA_STATE;
int state = intent.getIntExtra(stateExtra, -1);
//int previousState = intent.getIntExtra(prevStateExtra, -1);
String tt = "Unkown Bluetooth";
switch(state)
{
case (BluetoothAdapter.STATE_TURNING_ON):
{
tt = "Bluetooth turning on";
break;
}
case (BluetoothAdapter.STATE_ON):
{
tt = "Bluetooth on";
unregisterReceiver(this);
break;
}
case (BluetoothAdapter.STATE_TURNING_OFF):
{
tt = "Bluetooth turning off";
break;
}
case (BluetoothAdapter.STATE_OFF):
{
tt = "Bluetooth off";
break;
}
default:
tt = "Unkown Bluetooth state!";
break;
}
//Toast.makeText(this, tt, Toast.LE
view plaincopy to clipboardprint?
package com.android.factorytest;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class TestColor extends Activity{
private static final String TAG = "TestColor";
private Button mReturn = null;
private Button mChangeColor = null;
private Button mNext = null;
private TextView mText1 = null;
private TextView mText2 = null;
private TextView mText3 = null;
private Intent mIntent = null;
private int mNum = 0;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_color);
initView();
}
private void initView()
{
setTitle(R.string.test_color_mess);
mReturn = (Button)findViewById(R.id.but_return);
mChangeColor = (Button)findViewById(R.id.but_changecolor);
mNext = (Button)findViewById(R.id.but_next);
mText1 = (TextView)findViewById(R.id.test_color_text1);
mText2 = (TextView)findViewById(R.id.test_color_text2);
mText3 = (TextView)findViewById(R.id.test_color_text3);
mReturn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestColor.this, MainActivity.class);
startActivity(mIntent);
}
});
mNext.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestColor.this, TestSd.class);
//mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(mIntent);
}
});
mChangeColor.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mNum ++;
changeColor(mNum);
}
});
}
private void changeColor(int num)
{
Log.e(TAG, "num = " + (num%6));
switch(num % 6)
{
case 0:
mText1.setBackgroundColor(Color.RED);
mText2.setBackgroundColor(Color.RED);
mText3.setBackgroundColor(Color.RED);
break;
case 1:
mText1.setBackgroundColor(Color.GREEN);
mText2.setBackgroundColor(Color.GREEN);
mText3.setBackgroundColor(Color.GREEN);
break;
case 2:
mText1.setBackgroundColor(Color.BLUE);
mText2.setBackgroundColor(Color.BLUE);
mText3.setBackgroundColor(Color.BLUE);
break;
case 3:
mText1.setBackgroundColor(Color.RED);
mText2.setBackgroundColor(Color.RED);
mText3.setBackgroundColor(Color.RED);
break;
case 4:
mText1.setBackgroundColor(Color.GREEN);
mText2.setBackgroundColor(Color.GREEN);
mText3.setBackgroundColor(Color.GREEN);
break;
case 5:
mText1.setBackgroundColor(Color.BLUE);
mText2.setBackgroundColor(Color.BLUE);
mText3.setBackgroundColor(Color.BLUE);
break;
}
}
}
package com.android.factorytest;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class TestColor extends Activity{
private static final String TAG = "TestColor";
private Button mReturn = null;
private Button mChangeColor = null;
private Button mNext = null;
private TextView mText1 = null;
private TextView mText2 = null;
private TextView mText3 = null;
private Intent mIntent = null;
private int mNum = 0;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_color);
initView();
}
private void initView()
{
setTitle(R.string.test_color_mess);
mReturn = (Button)findViewById(R.id.but_return);
mChangeColor = (Button)findViewById(R.id.but_changecolor);
mNext = (Button)findViewById(R.id.but_next);
mText1 = (TextView)findViewById(R.id.test_color_text1);
mText2 = (TextView)findViewById(R.id.test_color_text2);
mText3 = (TextView)findViewById(R.id.test_color_text3);
mReturn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestColor.this, MainActivity.class);
startActivity(mIntent);
}
});
mNext.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestColor.this, TestSd.class);
//mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(mIntent);
}
});
mChangeColor.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mNum ++;
changeColor(mNum);
}
});
}
private void changeColor(int num)
{
Log.e(TAG, "num = " + (num%6));
switch(num % 6)
{
case 0:
mText1.setBackgroundColor(Color.RED);
mText2.setBackgroundColor(Color.RED);
mText3.setBackgroundColor(Color.RED);
break;
case 1:
mText1.setBackgroundColor(Color.GREEN);
mText2.setBackgroundColor(Color.GREEN);
mText3.setBackgroundColor(Color.GREEN);
break;
case 2:
mText1.setBackgroundColor(Color.BLUE);
mText2.setBackgroundColor(Color.BLUE);
mText3.setBackgroundColor(Color.BLUE);
break;
case 3:
mText1.setBackgroundColor(Color.RED);
mText2.setBackgroundColor(Color.RED);
mText3.setBackgroundColor(Color.RED);
break;
case 4:
mText1.setBackgroundColor(Color.GREEN);
mText2.setBackgroundColor(Color.GREEN);
mText3.setBackgroundColor(Color.GREEN);
break;
case 5:
mText1.setBackgroundColor(Color.BLUE);
mText2.setBackgroundColor(Color.BLUE);
mText3.setBackgroundColor(Color.BLUE);
break;
}
}
}
LCD测试XML:
view plaincopy to clipboardprint?
<?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:background="#383838"
android:orientation="vertical"
android:gravity="center" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<TextView android:id="@+id/test_color_text1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffff0000" />
<TextView android:id="@+id/test_color_text2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffff0000" />
<TextView android:id="@+id/test_color_text3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffff0000" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center">
<Button android:id="@+id/but_return"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="@string/but_return" />
<Button android:id="@+id/but_changecolor"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_changecolor" />
<Button android:id="@+id/but_next"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:text="@string/but_next" />
</LinearLayout>
</LinearLayout>
<?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:background="#383838"
android:orientation="vertical"
android:gravity="center" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<TextView android:id="@+id/test_color_text1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffff0000" />
<TextView android:id="@+id/test_color_text2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffff0000" />
<TextView android:id="@+id/test_color_text3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffff0000" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center">
<Button android:id="@+id/but_return"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="@string/but_return" />
<Button android:id="@+id/but_changecolor"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_changecolor" />
<Button android:id="@+id/but_next"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:text="@string/but_next" />
</LinearLayout>
</LinearLayout>
2.SD卡测试代码:
view plaincopy to clipboardprint?
package com.android.factorytest;
import java.io.File;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
public class TestSd extends Activity
{
private static final String LOG_TAG = null;
private TextView mTestSd = null;
private Button mReturn = null;
private Button mNext = null;
private Intent mIntent = null;
private File sdcardDir;
//private String PATH ="/abc";
private String FILENAME = "/sdcard/cet4hard.txt";
//private String FILENAME = "/mnt/sdcard/cet4hard.txt";//emulator test
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_sd);
sdcardDir = Environment.getExternalStorageDirectory();
initView();
}
private void initView()
{
try
{
Log.d(LOG_TAG,"Start Write");
if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
{
//File path = new File(sdcardDir+PATH);
File f = new File(sdcardDir + FILENAME);
//File f = new File(FILENAME);//emulator test
boolean flag = false;
//if(!path.exists())
//{
// flag = path.mkdirs();
// if(flag)
// {
// mTestSd = (TextView)findViewById(R.id.test_sd);
// mTestSd.setText(R.string.test_sd_mess3);
// }
// else
// {
// mTestSd = (TextView)findViewById(R.id.test_sd_delete);
// setContentView(R.id.test_sd_delete);
// }
//}
if(!f.exists())
{
flag = f.createNewFile();
if(flag)
{
mTestSd = (TextView)findViewById(R.id.test_sd_create);
mTestSd.setText(R.string.test_sd_mess3);
mTestSd.setTextColor(Color.GREEN);
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(f));
String editor = "fdfd";
osw.write(editor.toString());
osw.close();
}
else
{
mTestSd = (TextView)findViewById(R.id.test_sd_create);
mTestSd.setText(R.string.test_sd_mess5);
mTestSd.setTextColor(Color.RED);
}
}
else
{
mTestSd = (TextView)findViewById(R.id.test_sd_create);
mTestSd.setText(R.string.test_sd_mess5);
mTestSd.setTextColor(Color.RED);
}
if(f.exists())
{
flag = f.delete();
if(flag)
{
mTestSd = (TextView)findViewById(R.id.test_sd_delete);
mTestSd.setText(R.string.test_sd_mess4);
mTestSd.setTextColor(Color.GREEN);
}
else
{
mTestSd = (TextView)findViewById(R.id.test_sd_delete);
mTestSd.setText(R.string.test_sd_mess6);
mTestSd.setTextColor(Color.RED);
}
}
else
{
mTestSd = (TextView)findViewById(R.id.test_sd_delete);
mTestSd.setText(R.string.test_sd_mess6);
mTestSd.setTextColor(Color.RED);
}
}
else
{
mTestSd = (TextView)findViewById(R.id.test_sd);
mTestSd.setText(R.string.test_sd_mess2);
mTestSd.setTextColor(Color.RED);
}
}
catch(Exception e)
{
Log.d(LOG_TAG,"file create error");
}
mReturn = (Button)findViewById(R.id.but_return);
mNext = (Button)findViewById(R.id.but_next);
mReturn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestSd.this, MainActivity.class);
startActivity(mIntent);
}
});
mNext.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestSd.this, TestCamera.class);
//mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(mIntent);
}
});
}
}
package com.android.factorytest;
import java.io.File;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
public class TestSd extends Activity
{
private static final String LOG_TAG = null;
private TextView mTestSd = null;
private Button mReturn = null;
private Button mNext = null;
private Intent mIntent = null;
private File sdcardDir;
//private String PATH ="/abc";
private String FILENAME = "/sdcard/cet4hard.txt";
//private String FILENAME = "/mnt/sdcard/cet4hard.txt";//emulator test
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_sd);
sdcardDir = Environment.getExternalStorageDirectory();
initView();
}
private void initView()
{
try
{
Log.d(LOG_TAG,"Start Write");
if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
{
//File path = new File(sdcardDir+PATH);
File f = new File(sdcardDir + FILENAME);
//File f = new File(FILENAME);//emulator test
boolean flag = false;
//if(!path.exists())
//{
// flag = path.mkdirs();
// if(flag)
// {
// mTestSd = (TextView)findViewById(R.id.test_sd);
// mTestSd.setText(R.string.test_sd_mess3);
// }
// else
// {
// mTestSd = (TextView)findViewById(R.id.test_sd_delete);
// setContentView(R.id.test_sd_delete);
// }
//}
if(!f.exists())
{
flag = f.createNewFile();
if(flag)
{
mTestSd = (TextView)findViewById(R.id.test_sd_create);
mTestSd.setText(R.string.test_sd_mess3);
mTestSd.setTextColor(Color.GREEN);
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(f));
String editor = "fdfd";
osw.write(editor.toString());
osw.close();
}
else
{
mTestSd = (TextView)findViewById(R.id.test_sd_create);
mTestSd.setText(R.string.test_sd_mess5);
mTestSd.setTextColor(Color.RED);
}
}
else
{
mTestSd = (TextView)findViewById(R.id.test_sd_create);
mTestSd.setText(R.string.test_sd_mess5);
mTestSd.setTextColor(Color.RED);
}
if(f.exists())
{
flag = f.delete();
if(flag)
{
mTestSd = (TextView)findViewById(R.id.test_sd_delete);
mTestSd.setText(R.string.test_sd_mess4);
mTestSd.setTextColor(Color.GREEN);
}
else
{
mTestSd = (TextView)findViewById(R.id.test_sd_delete);
mTestSd.setText(R.string.test_sd_mess6);
mTestSd.setTextColor(Color.RED);
}
}
else
{
mTestSd = (TextView)findViewById(R.id.test_sd_delete);
mTestSd.setText(R.string.test_sd_mess6);
mTestSd.setTextColor(Color.RED);
}
}
else
{
mTestSd = (TextView)findViewById(R.id.test_sd);
mTestSd.setText(R.string.test_sd_mess2);
mTestSd.setTextColor(Color.RED);
}
}
catch(Exception e)
{
Log.d(LOG_TAG,"file create error");
}
mReturn = (Button)findViewById(R.id.but_return);
mNext = (Button)findViewById(R.id.but_next);
mReturn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestSd.this, MainActivity.class);
startActivity(mIntent);
}
});
mNext.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestSd.this, TestCamera.class);
//mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(mIntent);
}
});
}
}
SD卡测试XML:
view plaincopy to clipboardprint?
<?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:background="#383838"
android:orientation="vertical"
android:gravity="center" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center" >
<TextView
android:id="@+id/test_sd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center" >
<TextView
android:id="@+id/test_sd_create"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center" >
<TextView
android:id="@+id/test_sd_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center">
<Button android:id="@+id/but_return"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_return" />
<Button android:id="@+id/but_next"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_next" />
</LinearLayout>
</LinearLayout>
<?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:background="#383838"
android:orientation="vertical"
android:gravity="center" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center" >
<TextView
android:id="@+id/test_sd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center" >
<TextView
android:id="@+id/test_sd_create"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center" >
<TextView
android:id="@+id/test_sd_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center">
<Button android:id="@+id/but_return"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_return" />
<Button android:id="@+id/but_next"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_next" />
</LinearLayout>
</LinearLayout>
3.Camera测试代码:
view plaincopy to clipboardprint?
package com.android.factorytest;
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.provider.MediaStore;
import android.view.View;
import android.widget.Button;
public class TestCamera extends Activity
{
private Button mReturn = null;
private Button mChangeCamera = null;
private Button mNext = null;
private Intent mIntent = null;
private static int TAKE_PICTURE = 1;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_camera);
initView();
RegListener();
}
public void RegListener() {
ExitListenerReceiver exitre = new ExitListenerReceiver();
IntentFilter intentfilter = new IntentFilter();
intentfilter.addAction(this.getPackageName() + "."
+ "ExitListenerReceiver");
this.registerReceiver(exitre, intentfilter);
}
class ExitListenerReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
((Activity) arg0).finish();
}
}
private void initView()
{
setTitle(R.string.test_camera_mess);
mReturn = (Button)findViewById(R.id.but_return);
mChangeCamera = (Button)findViewById(R.id.but_changecamera);
mNext = (Button)findViewById(R.id.but_next);
mReturn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestCamera.this, MainActivity.class);
startActivity(mIntent);
}
});
mNext.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestCamera.this, TestWiFi.class);
//mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(mIntent);
}
});
mChangeCamera.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(mIntent,TAKE_PICTURE);
}
});
}
}
package com.android.factorytest;
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.provider.MediaStore;
import android.view.View;
import android.widget.Button;
public class TestCamera extends Activity
{
private Button mReturn = null;
private Button mChangeCamera = null;
private Button mNext = null;
private Intent mIntent = null;
private static int TAKE_PICTURE = 1;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_camera);
initView();
RegListener();
}
public void RegListener() {
ExitListenerReceiver exitre = new ExitListenerReceiver();
IntentFilter intentfilter = new IntentFilter();
intentfilter.addAction(this.getPackageName() + "."
+ "ExitListenerReceiver");
this.registerReceiver(exitre, intentfilter);
}
class ExitListenerReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
((Activity) arg0).finish();
}
}
private void initView()
{
setTitle(R.string.test_camera_mess);
mReturn = (Button)findViewById(R.id.but_return);
mChangeCamera = (Button)findViewById(R.id.but_changecamera);
mNext = (Button)findViewById(R.id.but_next);
mReturn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestCamera.this, MainActivity.class);
startActivity(mIntent);
}
});
mNext.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestCamera.this, TestWiFi.class);
//mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(mIntent);
}
});
mChangeCamera.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(mIntent,TAKE_PICTURE);
}
});
}
}
Camera测试XML:
view plaincopy to clipboardprint?
<?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:background="#383838"
android:orientation="vertical"
android:gravity="center" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/test_camera_mess" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center">
<Button android:id="@+id/but_return"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="@string/but_return" />
<Button android:id="@+id/but_changecamera"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_camera_open" />
<Button android:id="@+id/but_next"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:text="@string/but_next" />
</LinearLayout>
</LinearLayout>
<?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:background="#383838"
android:orientation="vertical"
android:gravity="center" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/test_camera_mess" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center">
<Button android:id="@+id/but_return"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="@string/but_return" />
<Button android:id="@+id/but_changecamera"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_camera_open" />
<Button android:id="@+id/but_next"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:text="@string/but_next" />
</LinearLayout>
</LinearLayout>
4.Wifi测试代码:
view plaincopy to clipboardprint?
package com.android.factorytest;
import android.app.Activity;
import android.content.Intent;
//import android.net.ConnectivityManager;
//import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class TestWiFi extends Activity
{
private static final String TAG = "TestWiFi";
private Button mReturn = null;
private Button mChangeState = null;
private Button mNext = null;
private Intent mIntent = null;
private WifiManager mWifiManager = null;
//private ConnectivityManager connectivity = null;
private int mWifiState = -1;
//private int networkPreference = -1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_wifi);
initView();
}
private void initView()
{
mReturn = (Button) findViewById(R.id.but_return);
mNext = (Button) findViewById(R.id.but_next);
mChangeState = (Button) findViewById(R.id.but_changestate);
if (mChangeState == null)
Log.e(TAG, "mChangeState is null ");
mReturn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestWiFi.this, MainActivity.class);
startActivity(mIntent);
}
});
mNext.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestWiFi.this, TestBluetooth.class);
//mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(mIntent);
}
});
mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
if (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED)
{
mWifiState = 1;
//将当前网络设置为首选网络
//connectivity = (ConnectivityManager)getSystemService(WIFI_SERVICE);
//networkPreference = connectivity .getNetworkPreference();
//connectivity.setNetworkPreference(networkPreference);
//mChangeState.setText(R.string.but_wifi_close);
mChangeState.setText(R.string.test_wifi_mess_enter_wifisetting);
}
else if (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLED)
{
mWifiState = 0;
//mChangeState.setText(R.string.but_wifi_open);
mChangeState.setText(R.string.test_wifi_mess_enter_wifisetting);
}
else
{
Log.e(TAG, "Wifi State = " + mWifiManager.getWifiState());
}
mChangeState.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
changeWifiState(mWifiState);
mWifiState ++;
}
});
}
private void changeWifiState(int state)
{
Log.e(TAG, "mWifiState = " + state);
Toast.makeText(this, R.string.test_wifi_mess_enter_wifisetting, Toast.LENGTH_LONG).show();
//startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));//进入无线网络配置界面
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS)); //直接进入wifi网络设置界面
switch (state % 2)
{
case 0:
{
new Thread()
{
public void run()
{
Log.e(TAG, "setWifiEnabled(true)");
mWifiManager.setWifiEnabled(true);
}
}.start();
// if(mIntent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION))
// {
// Toast.makeText(this, R.string.test_wifi_mess_state_changed, Toast.LENGTH_LONG).show();
// }
while ((mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLING) ||
(mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED))
{
Toast.makeText(this, R.string.test_wifi_mess_enable, Toast.LENGTH_LONG).show();
break;
}
//获取网络列表并激活一个网络连接
//List<WifiConfiguration> configurations = mWifiManager.getConfiguredNetworks();
//if(configurations.size() > 0)
//{
// int netID = configurations.get(0).networkId;
// boolean disableAllOthers = true;
// mWifiManager.enableNetwork(netID, disableAllOthers);
//}
//mChangeState.setText(R.string.but_wifi_close);
mChangeState.setText(R.string.test_wifi_mess_enter_wifisetting);
break;
}
case 1:
{
new Thread()
{
public void run()
{
Log.e(TAG, "setWifiEnabled(false)");
mWifiManager.setWifiEnabled(false);
}
}.start();
//mChangeState.setText(R.string.but_wifi_open);
mChangeState.setText(R.string.test_wifi_mess_enter_wifisetting);
// if(mIntent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION))
// {
// Toast.makeText(this, R.string.test_wifi_mess_state_changed, Toast.LENGTH_LONG).show();
// }
while ((mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLING) ||
(mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLED))
{
Toast.makeText(this, R.string.test_wifi_mess_disable, Toast.LENGTH_LONG).show();
break;
}
break;
}
default:
Log.e(TAG, "Wifi state error !");
Toast.makeText(this, R.string.test_wifi_mess_error, Toast.LENGTH_LONG).show();
break;
}
}
}
package com.android.factorytest;
import android.app.Activity;
import android.content.Intent;
//import android.net.ConnectivityManager;
//import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class TestWiFi extends Activity
{
private static final String TAG = "TestWiFi";
private Button mReturn = null;
private Button mChangeState = null;
private Button mNext = null;
private Intent mIntent = null;
private WifiManager mWifiManager = null;
//private ConnectivityManager connectivity = null;
private int mWifiState = -1;
//private int networkPreference = -1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_wifi);
initView();
}
private void initView()
{
mReturn = (Button) findViewById(R.id.but_return);
mNext = (Button) findViewById(R.id.but_next);
mChangeState = (Button) findViewById(R.id.but_changestate);
if (mChangeState == null)
Log.e(TAG, "mChangeState is null ");
mReturn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestWiFi.this, MainActivity.class);
startActivity(mIntent);
}
});
mNext.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestWiFi.this, TestBluetooth.class);
//mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(mIntent);
}
});
mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
if (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED)
{
mWifiState = 1;
//将当前网络设置为首选网络
//connectivity = (ConnectivityManager)getSystemService(WIFI_SERVICE);
//networkPreference = connectivity .getNetworkPreference();
//connectivity.setNetworkPreference(networkPreference);
//mChangeState.setText(R.string.but_wifi_close);
mChangeState.setText(R.string.test_wifi_mess_enter_wifisetting);
}
else if (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLED)
{
mWifiState = 0;
//mChangeState.setText(R.string.but_wifi_open);
mChangeState.setText(R.string.test_wifi_mess_enter_wifisetting);
}
else
{
Log.e(TAG, "Wifi State = " + mWifiManager.getWifiState());
}
mChangeState.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
changeWifiState(mWifiState);
mWifiState ++;
}
});
}
private void changeWifiState(int state)
{
Log.e(TAG, "mWifiState = " + state);
Toast.makeText(this, R.string.test_wifi_mess_enter_wifisetting, Toast.LENGTH_LONG).show();
//startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));//进入无线网络配置界面
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS)); //直接进入wifi网络设置界面
switch (state % 2)
{
case 0:
{
new Thread()
{
public void run()
{
Log.e(TAG, "setWifiEnabled(true)");
mWifiManager.setWifiEnabled(true);
}
}.start();
// if(mIntent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION))
// {
// Toast.makeText(this, R.string.test_wifi_mess_state_changed, Toast.LENGTH_LONG).show();
// }
while ((mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLING) ||
(mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED))
{
Toast.makeText(this, R.string.test_wifi_mess_enable, Toast.LENGTH_LONG).show();
break;
}
//获取网络列表并激活一个网络连接
//List<WifiConfiguration> configurations = mWifiManager.getConfiguredNetworks();
//if(configurations.size() > 0)
//{
// int netID = configurations.get(0).networkId;
// boolean disableAllOthers = true;
// mWifiManager.enableNetwork(netID, disableAllOthers);
//}
//mChangeState.setText(R.string.but_wifi_close);
mChangeState.setText(R.string.test_wifi_mess_enter_wifisetting);
break;
}
case 1:
{
new Thread()
{
public void run()
{
Log.e(TAG, "setWifiEnabled(false)");
mWifiManager.setWifiEnabled(false);
}
}.start();
//mChangeState.setText(R.string.but_wifi_open);
mChangeState.setText(R.string.test_wifi_mess_enter_wifisetting);
// if(mIntent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION))
// {
// Toast.makeText(this, R.string.test_wifi_mess_state_changed, Toast.LENGTH_LONG).show();
// }
while ((mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLING) ||
(mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLED))
{
Toast.makeText(this, R.string.test_wifi_mess_disable, Toast.LENGTH_LONG).show();
break;
}
break;
}
default:
Log.e(TAG, "Wifi state error !");
Toast.makeText(this, R.string.test_wifi_mess_error, Toast.LENGTH_LONG).show();
break;
}
}
}
Wifi测试XML:
view plaincopy to clipboardprint?
<?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:background="#383838"
android:orientation="vertical"
android:gravity="center" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/test_wifi_mess" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center">
<Button android:id="@+id/but_return"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_return" />
<Button android:id="@+id/but_changestate"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_wifi_close" />
<Button android:id="@+id/but_next"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_next" />
</LinearLayout>
</LinearLayout>
<?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:background="#383838"
android:orientation="vertical"
android:gravity="center" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/test_wifi_mess" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center">
<Button android:id="@+id/but_return"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_return" />
<Button android:id="@+id/but_changestate"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_wifi_close" />
<Button android:id="@+id/but_next"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/but_next" />
</LinearLayout>
</LinearLayout>
5.Bluetooth测试代码:
view plaincopy to clipboardprint?
package com.android.factorytest;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class TestBluetooth extends Activity
{
private static final String TAG = "TestBluetooth";
private TextView mBluetoothstate = null;
private Button mReturn = null;
private Button mChangeState = null;
private Button mNext = null;
private Intent mIntent = null;
private BluetoothAdapter mBluetooth = null;
private int mBluetoothState = -1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_bluetooth);
initView();
}
private void initView()
{
mReturn = (Button) findViewById(R.id.but_return);
mNext = (Button) findViewById(R.id.but_next);
mChangeState = (Button) findViewById(R.id.but_changestate);
mBluetoothstate = (TextView)findViewById(R.id.bluetooth_state);
if (mChangeState == null)
Log.e(TAG, "mChangeState is null ");
mReturn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestBluetooth.this, MainActivity.class);
startActivity(mIntent);
}
});
mNext.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestBluetooth.this, TestColor.class);
finish();
startActivity(mIntent);
}
});
mBluetooth = BluetoothAdapter.getDefaultAdapter();
if(null == mBluetooth)
{
mBluetoothstate.setText("No Bluetooth Device");
mBluetoothstate.setTextColor(Color.RED);
}
if (mBluetooth.isEnabled())
{
mBluetoothState = 1;
mChangeState.setText(R.string.but_bluetooth_close);
}
else if (!mBluetooth.isEnabled())
{
mBluetoothState = 0;
mChangeState.setText(R.string.but_bluetooth_open);
}
else
{
Log.e(TAG, "Bluetooth State = ");
}
mChangeState.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
startActivity(new Intent(Settings.ACTION_BLUETOOTH_SETTINGS));//进入Bluetooth配置界面
changeBluetoothState(mBluetoothState);
mBluetoothState ++;
}
});
}
private void changeBluetoothState(int state)
{
Log.e(TAG, "mBluetoothState = " + state);
switch (state % 2)
{
case 0:
{
startBluetooth();
Toast.makeText(this, R.string.test_bluetooth_mess_state_changed, Toast.LENGTH_LONG).show();
mChangeState.setText(R.string.but_bluetooth_close);
break;
}
case 1:
{
stopBluetooth();
Toast.makeText(this, R.string.test_bluetooth_mess_state_changed, Toast.LENGTH_LONG).show();
mChangeState.setText(R.string.but_bluetooth_open);
break;
}
default:
Log.e(TAG, "Wifi state error !");
Toast.makeText(this, R.string.test_bluetooth_mess_error, Toast.LENGTH_LONG).show();
break;
}
}
private void startBluetooth()
{
mBluetoothstate = (TextView)findViewById(R.id.bluetooth_state);
mBluetooth = BluetoothAdapter.getDefaultAdapter();
if(null == mBluetooth)
{
mBluetoothstate.setText("No Bluetooth Device");
mBluetoothstate.setTextColor(Color.RED);
}
BroadcastReceiver BluetoothState = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
//String prevStateExtra = BluetoothAdapter.EXTRA_PREVIOUS_STATE;
String stateExtra = BluetoothAdapter.EXTRA_STATE;
int state = intent.getIntExtra(stateExtra, -1);
//int previousState = intent.getIntExtra(prevStateExtra, -1);
String tt = "";
switch(state)
{
case (BluetoothAdapter.STATE_TURNING_ON):
{
tt = "Bluetooth turning on";
break;
}
case (BluetoothAdapter.STATE_ON):
{
tt = "Bluetooth on";
unregisterReceiver(this);
break;
}
case (BluetoothAdapter.STATE_TURNING_OFF):
{
tt = "Bluetooth turning off";
break;
}
case (BluetoothAdapter.STATE_OFF):
{
tt = "Bluetooth off";
break;
}
default:
tt = "Unkown Bluetooth state!";
break;
}
//Toast.makeText(this, tt, Toast.LENGTH_LONG).show();
mBluetoothstate.setText(tt);
}
};
if(!mBluetooth.isEnabled())
{
String actionStateChanged = BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED;
//String actionRequestEnable = BluetoothAdapter.ACTION_REQUEST_ENABLE;
registerReceiver(BluetoothState, new IntentFilter(actionStateChanged));
//startActivityForResult(new Intent(actionRequestEnable),0);
mBluetooth.enable();
}
}
private void stopBluetooth()
{
mBluetoothstate = (TextView)findViewById(R.id.bluetooth_state);
mBluetooth = BluetoothAdapter.getDefaultAdapter();
if(null == mBluetooth)
{
mBluetoothstate.setText("No Bluetooth Device");
mBluetoothstate.setTextColor(Color.RED);
}
BroadcastReceiver BluetoothState = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
//String prevStateExtra = BluetoothAdapter.EXTRA_PREVIOUS_STATE;
String stateExtra = BluetoothAdapter.EXTRA_STATE;
int state = intent.getIntExtra(stateExtra, -1);
//int previousState = intent.getIntExtra(prevStateExtra, -1);
String tt = "Unkown Bluetooth";
switch(state)
{
case (BluetoothAdapter.STATE_TURNING_ON):
{
tt = "Bluetooth turning on";
break;
}
case (BluetoothAdapter.STATE_ON):
{
tt = "Bluetooth on";
unregisterReceiver(this);
break;
}
case (BluetoothAdapter.STATE_TURNING_OFF):
{
tt = "Bluetooth turning off";
break;
}
case (BluetoothAdapter.STATE_OFF):
{
tt = "Bluetooth off";
break;
}
default:
tt = "Unkown Bluetooth state!";
break;
}
//Toast.makeText(this, tt, Toast.LENGTH_LONG).show();
mBluetoothstate.setText(tt);
}
};
if(mBluetooth.isEnabled())
{
String actionStateChanged = BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED;
registerReceiver(BluetoothState, new IntentFilter(actionStateChanged));
mBluetooth.disable();
}
}
}
package com.android.factorytest;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class TestBluetooth extends Activity
{
private static final String TAG = "TestBluetooth";
private TextView mBluetoothstate = null;
private Button mReturn = null;
private Button mChangeState = null;
private Button mNext = null;
private Intent mIntent = null;
private BluetoothAdapter mBluetooth = null;
private int mBluetoothState = -1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_bluetooth);
initView();
}
private void initView()
{
mReturn = (Button) findViewById(R.id.but_return);
mNext = (Button) findViewById(R.id.but_next);
mChangeState = (Button) findViewById(R.id.but_changestate);
mBluetoothstate = (TextView)findViewById(R.id.bluetooth_state);
if (mChangeState == null)
Log.e(TAG, "mChangeState is null ");
mReturn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestBluetooth.this, MainActivity.class);
startActivity(mIntent);
}
});
mNext.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mIntent = new Intent(TestBluetooth.this, TestColor.class);
finish();
startActivity(mIntent);
}
});
mBluetooth = BluetoothAdapter.getDefaultAdapter();
if(null == mBluetooth)
{
mBluetoothstate.setText("No Bluetooth Device");
mBluetoothstate.setTextColor(Color.RED);
}
if (mBluetooth.isEnabled())
{
mBluetoothState = 1;
mChangeState.setText(R.string.but_bluetooth_close);
}
else if (!mBluetooth.isEnabled())
{
mBluetoothState = 0;
mChangeState.setText(R.string.but_bluetooth_open);
}
else
{
Log.e(TAG, "Bluetooth State = ");
}
mChangeState.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
startActivity(new Intent(Settings.ACTION_BLUETOOTH_SETTINGS));//进入Bluetooth配置界面
changeBluetoothState(mBluetoothState);
mBluetoothState ++;
}
});
}
private void changeBluetoothState(int state)
{
Log.e(TAG, "mBluetoothState = " + state);
switch (state % 2)
{
case 0:
{
startBluetooth();
Toast.makeText(this, R.string.test_bluetooth_mess_state_changed, Toast.LENGTH_LONG).show();
mChangeState.setText(R.string.but_bluetooth_close);
break;
}
case 1:
{
stopBluetooth();
Toast.makeText(this, R.string.test_bluetooth_mess_state_changed, Toast.LENGTH_LONG).show();
mChangeState.setText(R.string.but_bluetooth_open);
break;
}
default:
Log.e(TAG, "Wifi state error !");
Toast.makeText(this, R.string.test_bluetooth_mess_error, Toast.LENGTH_LONG).show();
break;
}
}
private void startBluetooth()
{
mBluetoothstate = (TextView)findViewById(R.id.bluetooth_state);
mBluetooth = BluetoothAdapter.getDefaultAdapter();
if(null == mBluetooth)
{
mBluetoothstate.setText("No Bluetooth Device");
mBluetoothstate.setTextColor(Color.RED);
}
BroadcastReceiver BluetoothState = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
//String prevStateExtra = BluetoothAdapter.EXTRA_PREVIOUS_STATE;
String stateExtra = BluetoothAdapter.EXTRA_STATE;
int state = intent.getIntExtra(stateExtra, -1);
//int previousState = intent.getIntExtra(prevStateExtra, -1);
String tt = "";
switch(state)
{
case (BluetoothAdapter.STATE_TURNING_ON):
{
tt = "Bluetooth turning on";
break;
}
case (BluetoothAdapter.STATE_ON):
{
tt = "Bluetooth on";
unregisterReceiver(this);
break;
}
case (BluetoothAdapter.STATE_TURNING_OFF):
{
tt = "Bluetooth turning off";
break;
}
case (BluetoothAdapter.STATE_OFF):
{
tt = "Bluetooth off";
break;
}
default:
tt = "Unkown Bluetooth state!";
break;
}
//Toast.makeText(this, tt, Toast.LENGTH_LONG).show();
mBluetoothstate.setText(tt);
}
};
if(!mBluetooth.isEnabled())
{
String actionStateChanged = BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED;
//String actionRequestEnable = BluetoothAdapter.ACTION_REQUEST_ENABLE;
registerReceiver(BluetoothState, new IntentFilter(actionStateChanged));
//startActivityForResult(new Intent(actionRequestEnable),0);
mBluetooth.enable();
}
}
private void stopBluetooth()
{
mBluetoothstate = (TextView)findViewById(R.id.bluetooth_state);
mBluetooth = BluetoothAdapter.getDefaultAdapter();
if(null == mBluetooth)
{
mBluetoothstate.setText("No Bluetooth Device");
mBluetoothstate.setTextColor(Color.RED);
}
BroadcastReceiver BluetoothState = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
//String prevStateExtra = BluetoothAdapter.EXTRA_PREVIOUS_STATE;
String stateExtra = BluetoothAdapter.EXTRA_STATE;
int state = intent.getIntExtra(stateExtra, -1);
//int previousState = intent.getIntExtra(prevStateExtra, -1);
String tt = "Unkown Bluetooth";
switch(state)
{
case (BluetoothAdapter.STATE_TURNING_ON):
{
tt = "Bluetooth turning on";
break;
}
case (BluetoothAdapter.STATE_ON):
{
tt = "Bluetooth on";
unregisterReceiver(this);
break;
}
case (BluetoothAdapter.STATE_TURNING_OFF):
{
tt = "Bluetooth turning off";
break;
}
case (BluetoothAdapter.STATE_OFF):
{
tt = "Bluetooth off";
break;
}
default:
tt = "Unkown Bluetooth state!";
break;
}
//Toast.makeText(this, tt, Toast.LE