当前位置:  编程技术>移动开发
本页文章导读:
    ▪简略的录音保存        简单的录音保存 import java.io.File; import android.app.Activity; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Intent; import android.media.MediaRecorder; import android.net.Uri; import an.........
    ▪ 动态平添菜单        动态添加菜单 Dynamically add intentsIf there are potentially multiple activities that are relevant to your current Activity or selected item, then the application can dynamically add menu items that execute other services.During menu creatio.........
    ▪ 简略的动态加入item       简单的动态加入item public class HTMLListActivity extends ListActivity {     private List<String> filesEntries = new ArrayList<String>();      public void onCreate(Bundle icicle) {        super.onCreate(icicle);   .........

[1]简略的录音保存
    来源: 互联网  发布时间: 2014-02-18
简单的录音保存
import java.io.File;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Intent;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.provider.MediaStore.MediaColumns;
import android.util.Log;
import android.view.View;
import android.widget.Button;

/**
 * This is main class which shows how to capture/record audio
 * @author The Developer's Info
 *
 */
public class Main extends Activity {
	private MediaRecorder mediaRecorder;
	private File file = null;
	static final String PREFIX = "record";
	static final String EXTENSION = ".3gpp";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		mediaRecorder = new MediaRecorder();

		Button startRecording = (Button) findViewById(R.id.startBtn);
		Button stopRecording = (Button) findViewById(R.id.stopBtn);
		startRecording.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				try {
					startRecording();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});

		stopRecording.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				stopRecording();
				saveToDB();
			}
		});
	}

	/**
	 * This method starts recording process
	 * @throws Exception
	 */
	private void startRecording() throws Exception {
		mediaRecorder = new MediaRecorder();
		mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
		mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
		mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
		if (file == null) {
			File rootDir = Environment.getExternalStorageDirectory();
			file = File.createTempFile(PREFIX, EXTENSION, rootDir);
		}
		mediaRecorder.setOutputFile(file.getAbsolutePath());
		mediaRecorder.prepare();
		mediaRecorder.start();
	}

	/**
	 * This method stops recording
	 */
	private void stopRecording() {
		mediaRecorder.stop();
		mediaRecorder.release();
	}

	/**
	 * This method sets all metadata for audio file
	 */
	private void saveToDB() {
		ContentValues values = new ContentValues(3);
		long current = System.currentTimeMillis();
		values.put(MediaColumns.TITLE, "My Audio record");
		values.put(MediaColumns.DATE_ADDED, (int) (current / 1000));
		values.put(MediaColumns.MIME_TYPE, "audio/mp3");
		values.put(MediaColumns.DATA, file.getAbsolutePath());
		ContentResolver contentResolver = getContentResolver();
		Uri base = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
		Uri newUri = contentResolver.insert(base, values);
		sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, newUri));
	}
}

 


    
[2] 动态平添菜单
    来源: 互联网  发布时间: 2014-02-18
动态添加菜单
Dynamically add intents

If there are potentially multiple activities that are relevant to your current Activity or selected item, then the application can dynamically add menu items that execute other services.

During menu creation, define an Intent with the category Intent.ALTERNATIVE_CATEGORY and/or Intent.SELECTED_ALTERNATIVE, the MIME type currently selected (if any), and any other requirements, the same way as you would satisfy an intent filter to open a new Activity. Then call addIntentOptions() to have Android search for any services meeting those requirements and add them to the menu for you. If there are no applications installed that satisfy the Intent, then no additional menu items are added.

Note: SELECTED_ALTERNATIVE is used to handle the currently selected element on the screen. So, it should only be used when creating a Menu in onCreateContextMenu() or onPrepareOptionsMenu(), which is called every time the Options Menu is opened.

Here's an example demonstrating how an application would search for additional services to display on its menu.
public boolean onCreateOptionsMenu(Menu menu){
    super.onCreateOptionsMenu(menu);

    // Create an Intent that describes the requirements to fulfill, to be included
    // in our menu. The offering app must include a category value of Intent.CATEGORY_ALTERNATIVE. 
    Intent intent = new Intent(null, getIntent().getData());
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
        
    // Search for, and populate the menu with, acceptable offering applications.
    menu.addIntentOptions(
         thisClass.INTENT_OPTIONS,  // Menu group 
         0,      // Unique item ID (none)
         0,      // Order for the items (none)
         this.getComponentName(),   // The current Activity name
         null,   // Specific items to place first (none)
         intent, // Intent created above that describes our requirements
         0,      // Additional flags to control items (none)
         null);  // Array of MenuItems that corrolate to specific items (none)

    return true;
}

For each Activity found that provides an Intent Filter matching the Intent defined, a menu item will be added, using the android:label value of the intent filter as the text for the menu item. The addIntentOptions() method will also return the number of menu items added.

Also be aware that, when addIntentOptions() is called, it will override any and all menu items in the menu group specified in the first argument.

If you wish to offer the services of your Activity to other application menus, then you only need to define an intent filter as usual. Just be sure to include the ALTERNATIVE and/or SELECTED_ALTERNATIVE values in the name attribute of a <category> element in the intent filter. For example:

<intent-filter label="Resize Image">
    ...
    <category android:name="android.intent.category.ALTERNATIVE" />
    <category android:name="android.intent.category.SELECTED_ALTERNATIVE" />
    ...
</intent-filter>

read more about writing intent filters in the Intents and Intent Filters document.

For a sample application using this technique, see the Note Pad sample code.

    
[3] 简略的动态加入item
    来源: 互联网  发布时间: 2014-02-18
简单的动态加入item

public class HTMLListActivity extends ListActivity {

    private List<String> filesEntries = new ArrayList<String>();

 
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
       
        AppUtils.showDebug(getApplicationContext(), "HTMLListActivity - onCreate!!");

        filesEntries.add("a1_bienvenida");
        filesEntries.add("a2_info_tabaquismo");
        filesEntries.add("a3_tests");
        filesEntries.add("diez_mandamientos");
        filesEntries.add("test");
        filesEntries.add("mitos_del_tabaco");
       
       
        ArrayAdapter<String> directoryList = new ArrayAdapter<String>(this,
                R.layout.cigar_row, this.filesEntries);
      
      this.setListAdapter(directoryList);
       

    }
   
 protected void onListItemClick(ListView l, View v, int position, long id) {

  TextView tv = (TextView)v;
  Intent i = new Intent( getApplicationContext(), HTMLViewer.class );
  i.putExtra( "fileName", tv.getText());
  startActivity( i );

 }
   
}

只要使用filesEntries list泛型就可以了


    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3