我们曾经在其他文章中通过对录音以及录像的实现方法具体讲解过有Android多媒体录制功能的实现方式介绍 的相关操作技巧。在这里我们将会为大家详细介绍一下Android多媒体播放的应用方式,以帮助大家对这方面的应用知识有一个深刻的印象。
Android多媒体播放代码:
代码如下 |
复制代码 |
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.VideoView;
public class VideoPlayer extends Activity {
/** Called when the activity is first created.
*/
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
final VideoView w =(VideoView)findViewById(R.id.vdoplayer);
Button cmdload = (Button)this.findViewById(R.id.cmd_load); cmdload.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
w.setVideoPath("/sdcard/android/kongfu.mp4");
}
}
);
Button cmdplay = (Button)this.findViewById(R.id.cmd_play);
cmdplay.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
w.start();
}
}
);
Button cmdpause = (Button)this.findViewById(R.id.cmd_pause); cmdpause.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
w.pause();
}
}
);
}
|
Android多媒体播放实现代码:
xml文件:
代码如下 |
复制代码 |
< ?xml version="1.0" encoding="utf-8"?>
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
< Button android:id="@+id/cmd_load"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="load" />
< Button android:id="@+id/cmd_play"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Play" />
< Button android:id="@+id/cmd_pause"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="pause" />
< VideoView android:id="@+id/vdoplayer"
android:layout_width="fill_parent"
android:layout_height="300px" />
< /LinearLayout>
|
本文章为安卓开发者入门者介绍关于Android Debug Bridge (ADB)的使用方法,有需要学习的朋友可进入参考。
Android系统调试工具——ADB
Android Debug Bridge是个多功能的工具,可以管理设备上的执行状况。
即ADB是管理模拟器的一个工具。
包括下列三个部分:
客户端程序(Client):在开发环境上运行,也可以通过命令行模式shell接口执行adb命令来操作客户端程序。其他Android工具如开发工具ADT或调试监控系统DDMS都可以创建一个adb客户端。
服务器程序(Server):在开发环境的后台运行,服务器程序负责管理介于客户端程序和守护进程程序的通信沟通。
守护进程程序(Daemon):在实际硬件设备或虚拟设备的后台运行。
adb命令位于安装路径下的platform-tools路径中,把这个路径加在环境变量PATH中就可以在其他目录下使用adb命令。
adb命令的标准格式
adb [-d|-e|-s <serialNumber>] <command>
这是adb命令的标准格式,当你正在执行的仿真器有多个时,要加上仿真器序号来区别:
使用“-s <serialNumber>”选项参数;
使用“-d”选项参数,adb命令只会送到连接USB的实际硬设备;
使用“-e”选项参数,adb命令只会送到Android仿真器。
后面<command>是必要的命令。
安装与卸载应用程序apk文件
安装:
adb [-s <serialNumber>] install <path_to_apk>
范例:安装helloWorld.apk到Android仿真器序列号是5556的虚拟设备上:
adb –s emulator-5556 install helloWorld.apk
adb install helloWorld.apk
使用adb install安装apk组件程序时,安装在Android仿真器上的apk组件会被放在Android系统目录的/data/app下,这个目录下的应用程序文件名就是写程序时设置的Package name
卸载:
adb [-s <serialNumber>] uninstall <package>
范例:
adb –s emulator-5556 uninstall com.example.android.helloWorld.apk
adb uninstall com.example.android.helloWorld.apk
注意安装是接apk文件路径名称,而移除是接package名称。
手动删除:
adb shell
cd data/app
rm app.apk
Android操作系统命令行模式,使用shell命令
执行
adb shell
可以进入Android操作系统命令行模式,如此一来你就可以管理和查询Android操作系统的目录和执行相关的命令。
因为Android操作系统是Linux操作系统的一种,所以shell命令和Linux操作系统是相同的,例如ls命令显示文件目录,cd命令更改文件目录,mkdir命令创建目录,rmdir命令删除目录,rm命令删除文件,mv命令移动文件。
进入Android操作系统命令行模式后,要离开回到控制台窗口,可以使用exit命令。
上传文件到/sdcard或自/sdcard下载文件(复制文件)
上传,即从系统复制文件到设备:
adb push <local> <remote>
如:adb push d:test.txt /sdcard/
下载,即从设备复制文件到系统:
adb pull <remote> <local>
如:adb pull /sdcard/test.txt d:/
发布端口
可以设置任意的端口号,作为主机向模拟器或设备的请求端口。如:
adb forward tcp:5555 tcp:8000
搜索/等待模拟器、设备实例
取得当前运行的模拟器,设备的实例列表及每个实例的状态|等待正在运行的设备。
adb devices
adb wait-for-device
查看Bug报告
adb bugreport
记录无线通讯日志
adb shell
logcat –b radio
获取设备ID和序列号
adb get-product
adb get-serialno
访问数据库SQLite3
adb shell
sqlite3
本文章来介绍在android开发中,我们通过button按钮来动态改变字体大小、字体颜色、背景颜色代码,有需要了解的朋友可参考参考。
实现的逻辑:通过遍历View的方式,判断View是否是TextView、EditText和Button类型,如果是的话,就修改。
代码如下:
1、xml布局文件,文件名:test4.xml,内容如下:
代码如下 |
复制代码 |
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/mainLayout">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText android:id="@+id/fontSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="30"
android:hint="请输入数字"/>
<Button android:id="@+id/ChangeSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="改变字体"/>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText android:id="@+id/fontColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#ffffff"
android:hint="请输入字体颜色"/>
<Button android:id="@+id/ChangeColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="改变字体颜色" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText android:id="@+id/bgColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#ff0000"
android:hint="请输入背景颜色"/>
<Button android:id="@+id/ChangeBgColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="改变背景颜色"/>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="@+id/TextView01"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="top"
android:gravity="top"
android:textColor="#ffffff"
android:background="#00ff00"
android:layout_margin="2px"/>
<TextView android:id="@+id/TextView02"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="bottom"
android:gravity="bottom"
android:textColor="#ffffff"
android:background="#00ff00"
android:layout_margin="2px"/>
<TextView android:id="@+id/TextView03"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="left"
android:gravity="left"
android:textColor="#ffffff"
android:background="#00ff00"
android:layout_margin="2px"/>
<TextView android:id="@+id/TextView04"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="right"
android:gravity="right"
android:textColor="#ffffff"
android:background="#00ff00"
android:layout_margin="2px"/>
<TextView android:id="@+id/TextView05"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="center_vertical"
android:gravity="center_vertical"
android:textColor="#ffffff"
android:background="#00ff00"
android:layout_margin="2px"/>
<TextView android:id="@+id/TextView06"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="fill_vertical"
android:gravity="fill_vertical"
android:textColor="#ffffff"
android:background="#00ff00"
android:layout_margin="2px"/>
<TextView android:id="@+id/TextView07"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="center_horizontal"
android:gravity="center_horizontal"
android:textColor="#ffffff"
android:background="#00ff00"
android:layout_margin="2px"/>
<TextView android:id="@+id/TextView08"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="fill_horizontal"
android:gravity="fill_horizontal"
android:textColor="#ffffff"
android:background="#00ff00"
android:layout_margin="2px"/>
<TextView android:id="@+id/TextView09"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="center"
android:gravity="center"
android:textColor="#ffffff"
android:background="#00ff00"
android:layout_margin="2px"/>
<TextView android:id="@+id/TextView10"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="fill"
android:gravity="fill"
android:textColor="#ffffff"
android:background="#00ff00"
android:layout_margin="2px"/>
<TextView android:id="@+id/TextView11"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="clip_vertical"
android:gravity="clip_vertical"
android:textColor="#ffffff"
android:background="#00ff00"
android:layout_margin="2px"/>
<TextView android:id="@+id/TextView12"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="clip_horizontal"
android:gravity="clip_horizontal"
android:textColor="#ffffff"
android:background="#00ff00"
android:layout_margin="2px"/>
</LinearLayout>
</LinearLayout>
|
2、实现的代码文件:MainActivity.java,代码如下:
代码如下 |
复制代码 |
package org.shuxiang.test;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends Activity{
private LinearLayout mainLayout;
private Button changeSize, changeColor, changeBgColor;
private EditText fontSize, fontColor, bgColor;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.test4);
mainLayout = (LinearLayout) findViewById(R.id.mainLayout);
changeSize = (Button) findViewById(R.id.ChangeSize);
fontSize = (EditText) findViewById(R.id.fontSize);
changeSize.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
setFontSize(mainLayout, Float.parseFloat(fontSize.getText().toString()));
}
});
changeColor = (Button) findViewById(R.id.ChangeColor);
fontColor = (EditText) findViewById(R.id.fontColor);
changeColor.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
int color = Integer.parseInt(fontColor.getText().toString().replace("#", ""), 16);
int red = (color & 0xff0000) >> 16;
int green = (color & 0x00ff00) >> 8;
int blue = (color & 0x0000ff);
setFontColor(mainLayout, Color.rgb(red, green, blue));
}
});
changeBgColor = (Button) findViewById(R.id.ChangeBgColor);
bgColor = (EditText) findViewById(R.id.bgColor);
changeBgColor.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
int color = Integer.parseInt(bgColor.getText().toString().replace("#", ""), 16);
int red = (color & 0xff0000) >> 16;
int green = (color & 0x00ff00) >> 8;
int blue = (color & 0x0000ff);
setBgColor(mainLayout, Color.rgb(red, green, blue));
}
});
}
/**
* 改变字体
* @param v
* @param fontSize
*/
public void setFontSize(View v, float fontSizeValue)
{
if(v instanceof TextView)
{
((TextView) v).setTextSize(fontSizeValue);
}
else if(v instanceof EditText)
{
((EditText) v).setTextSize(fontSizeValue);
}
else if(v instanceof Button)
{
((Button) v).setTextSize(fontSizeValue);
}
else
{
int vChildCount = ((ViewGroup) v).getChildCount();
for(int i=0; i<vChildCount; i++)
{
View v1 = ((ViewGroup) v).getChildAt(i);
setFontSize(v1, fontSizeValue);
}
}
}
/**
* 改变字体颜色
* @param v
* @param fontSize
*/
public void setFontColor(View v, int fontColorValue)
{
if(v instanceof TextView)
{
((TextView) v).setTextColor(fontColorValue);
}
else if(v instanceof EditText)
{
((EditText) v).setTextColor(fontColorValue);
}
else if(v instanceof Button)
{
((Button) v).setTextColor(fontColorValue);
}
else
{
int vChildCount = ((ViewGroup) v).getChildCount();
for(int i=0; i<vChildCount; i++)
{
View v1 = ((ViewGroup) v).getChildAt(i);
setFontColor(v1, fontColorValue);
}
}
}
/**
* 改变背景字体
* @param v
* @param fontSize
*/
public void setBgColor(View v, int bgColorValue)
{
if(v instanceof TextView)
{
((TextView) v).setBackgroundColor(bgColorValue);
}
else if(v instanceof EditText)
{
((EditText) v).setBackgroundColor(bgColorValue);
}
else if(v instanceof Button)
{
((Button) v).setBackgroundColor(bgColorValue);
}
else
{
int vChildCount = ((ViewGroup) v).getChildCount();
for(int i=0; i<vChildCount; i++)
{
View v1 = ((ViewGroup) v).getChildAt(i);
setBgColor(v1, bgColorValue);
}
}
}
}
|
本文章介绍一段超张简单的关于android如何判断是用户还机器代码,有需要的朋友可参考。
我们写程序的时候可能需要判断用户到底使用的是模拟器还是真机,可以使用如下的代码
代码如下 |
复制代码 |
private boolean isEmulator() {
return (Build.MODEL.equals("sdk")) || (Build.MODEL.equals("google_sdk"));
}
|
本文章介绍一个入门型号的教程,关于android 如何判断当前设备是模拟器还是真机和设置当前的Activity的屏幕亮度实例有需要的朋友可参考。
/** 判断是否模拟器。如果返回TRUE,则当前是模拟器
* @param context
* @return
*/
代码如下 |
复制代码 |
public static boolean isEmulator(Context context){
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String imei = tm.getDeviceId();
if (imei == null || imei.equals("000000000000000")){
return true;
}
return false;
}
|
这个方法没大量测试过,应该是WORK的,一般真机都有IMEI的,不过也见过工程机的IMEI是000000000000000还是0。
二
设置当前的Activity的屏幕亮度,而不是设置系统的屏幕亮度,退出当前的Activity后恢复系统的亮度。 直接看代码好了
代码如下 |
复制代码 |
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 0.5f;
getWindow().setAttributes(lp);
|
screenBrightness的值范围是0到1。 注意不要设成0,屏幕会黑掉,完全看不到。