安卓环境变量配置
系统变量
变量名:ANDROID_HOME
变量值:D:\Android\android-sdk-windows
Path中增加:%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools
----返回-------- @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { back(); } return super.onKeyDown(keyCode, event); }
private void back() { Intent intent = new Intent(Msg.this, MainActivity.class); intent.putExtra("userName", userName); intent.putExtra("userId", userId); startActivity(intent); this.finish(); }
----再按一次退出-------- @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { if ((System.currentTimeMillis() - exitTime) > 2000) {// 两次操作间隔 Toast.makeText(getApplicationContext(),
R.string.exit,Toast.LENGTH_SHORT).show(); exitTime = System.currentTimeMillis(); } else { finish(); System.exit(0); } return true; } return super.onKeyDown(keyCode, event); } ------设置全屏--------------
第一种: AndroidManifest.xml <activity android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"../>
第二种:
requestWindowFeature(Window.FEATURE_NO_TITLE);//设置无标题 setContentView(R.layout.activity_main); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//设置全屏 ------设置只能横屏------- android:screenOrientation="landscape"
----------图片锯齿 需要注意 把 <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> 放到application底下就可以解决
-----------调用系统自带播放器 Uri uri = Uri.parse(Constants.VIDEO_PATH); // 调用系统自带的播放器 Intent playIntent = new Intent(Intent.ACTION_VIEW);
playIntent.setDataAndType(uri, "video/mp4"); startActivity(playIntent); ----------调用安卓编写的播放器 Intent localIntent = new Intent(CarDetail.this, WeiDianYing.class);
startActivity(localIntent); //WeiDianYing.class public class WeiDianYing extends Activity { RelativeLayout weidianyingLayout;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.h_activity_wei_dian_ying); this.weidianyingLayout = (RelativeLayout) findViewById(R.id.weidianying);
VideoView localVideoView = new VideoView(this); String url = "android.resource://" + getPackageName() + "/" + R.raw.shuangchengji; MediaController localMediaController = new MediaController(this);
localVideoView.setMediaController(localMediaController); localMediaController.setMediaPlayer(localVideoView); localVideoView.setVideoURI(Uri.parse(url)); RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams( -1, -1);
this.weidianyingLayout.setGravity(17); this.weidianyingLayout.addView(localVideoView, localLayoutParams); localVideoView.start();
} }
//Weidianying.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/weidianying" android:layout_width="fill_parent" android:layout_height="fill_parent" >
</RelativeLayout> ------------------打开html WebView实例.loadUrl("file:///android_asset/moreinfo.html"); //设置全屏 wv.getSettings().setUseWideViewPort(true); wv.getSettings().setLoadWithOverviewMode(true);
------------------android向服务器发送url url包含json格式参数
URLEncoder.encode(参数值也就是json数据值,"UTF-8"); 即可解决。
----------------Monkey 自动测试命令
adb shell monkey -p com.package -v 100
---------------导出logcat到文本文件
adb logcat -d > D:/logcat.txt
------------------------------------------
android 调用已安装市场,进行软件评分的功能实现
Uri uri = Uri.parse("market://details?id="+getPackageName()); Intent intent = new Intent(Intent.ACTION_VIEW,uri); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); 通过以上代码就能够列出您手机上所安装的所有应用市场(如:google player、豌豆荚、360手机助手等),让您选择。 ------------------------------------------
调用分享的代码(手机上的可以走分享的应用)
Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.setType("text/*"); sendIntent.putExtra(Intent.EXTRA_TEXT, "分享的内容"); startActivity(sendIntent);
------------------------------------------