編輯:關於Android編程
本文實現android系統照相機的調用來拍照
項目的布局相當簡單,只有一個Button:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<Button
android:onClick="click"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="調用系統相機拍照" />
</RelativeLayout>
首先打開packages\apps\Camera文件夾下面的清單文件,找到下面的代碼:
<activity android:name="com.android.camera.Camera"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:screenOrientation="landscape"
android:clearTaskOnLaunch="true"
android:taskAffinity="android.task.camera">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.media.action.STILL_IMAGE_CAMERA" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
相關代碼如下:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void click(View view) {
/*
* <intent-filter> <action
* android:name="android.media.action.IMAGE_CAPTURE" /> <category
* android:name="android.intent.category.DEFAULT" /> </intent-filter>
*/
// 激活系統的照相機進行拍照
Intent intent = new Intent();
intent.setAction("android.media.action.IMAGE_CAPTURE");
intent.addCategory("android.intent.category.DEFAULT");
//保存照片到指定的路徑
File file = new File("/sdcard/image.jpg");
Uri uri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivity(intent);
}
}
實現激活錄像功能的相關代碼也很簡單:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void click(View view) {
/*
* <intent-filter> <action
* android:name="android.media.action.VIDEO_CAPTURE" /> <category
* android:name="android.intent.category.DEFAULT" /> </intent-filter>
*/
// 激活系統的照相機進行錄像
Intent intent = new Intent();
intent.setAction("android.media.action.VIDEO_CAPTURE");
intent.addCategory("android.intent.category.DEFAULT");
// 保存錄像到指定的路徑
File file = new File("/sdcard/video.3pg");
Uri uri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(intent, 0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Toast.makeText(this, "調用照相機完畢", 0).show();
super.onActivityResult(requestCode, resultCode, data);
}
}
出處:http://www.cnblogs.com/wuyudong/
以一個著色游戲展開講解Android中區域圖像填色的方法
一、著色游戲概述近期群裡偶然看到一哥們在群裡聊不規則圖像填充什麼四聯通、八聯通什麼的,就本身好學務實的態度去查閱了相關資料。對於這類著色的資料,最好的就是去搜索些相關ap
安卓Android-x86 4.4聯網設置教程 解決不能上網
Android-x86 4.4安裝完成後一般都是不能上網的,需要給網卡設置IP地址和DNS服務器方可聯網。Android-x86在本質上就是Linux系統,
Android Animation中關於Interpolator的解釋
網上有很多解釋Interpolator屬性的文章,但是基本上都是停留在直接翻譯SDK的意思層面上。Interpolator英文意思是: 篡改者; 分類機;
安卓實戰開發之CardView的selector及GrideView的item按下狀態保留selector(state_activated)的實現
android的selector對於android開發者而言再熟悉不過了,只要定義一個drawable目錄下定義一個selector的xml文件,在布局文件中backgr