京城高校纷纷进入开学季,三大电信运营商均瞄准这一潜力巨大的市场。记者近日走访了几所京城高校发现,与往年不同的是,今年联通电信在校园营销力度大为增强,移动昔日垄断地位被动摇。
联通电信强力逆袭
“今年移动的优惠活动真少,不知道办点什么业务好。”一名传媒大学的大四学生小李说。
记者也发现,在联通和电信的摊位前围满了前来咨询3G业务的新生。一名研一新生表示,自己是移动老用户,不想换号,但决定再办理一张联通3G卡,上网方便。
在送礼品方面,移动、联通和电信三家运营商都使出了办卡充值换取自行车、移动硬盘、公交卡、背包、雨伞等赠品的招数。但移动失去往年的大气,“去年充话费就送礼品,今年我想充话费换个自行车,但他们告诉我,必须加办一个不得低于50元的数据业务包。”一名大三老生说。联通的现场促销人员则表示,他们充400元就可送一辆自行车,如果是老用户,还可搭送暖水壶、洗脸盆等用品。
中国联通的一名现场工作人员说:“今年联通活动做得不错,传媒大学现场一天就办了800多个号,一些以前是移动独占的校园市场,今年我们也做到了平分秋色!”
北京邮电大学信息经济与竞争力研究中心主任曾剑秋教授表示,今年的校园促销还是比较激烈的,各大运营商会利用各种方法做营销,这也是拓展市场的重头戏。
营销策略更为隐蔽
为规避“不能在录取通知书中夹寄手机卡”的规定,今年运营商采用了一些较为隐蔽的营销策略。
一名传媒大学的女生对记者说,她在收到录取通知书几天后,又收到一封来自北京的快递,其中夹有一张联通手机卡,还有关于开学新生注意事项等说明。后来她发现其他来北京上学的同学都收到类似快递。
电信则把营销策略主要放在手机方面,记者在北京师范大学开学现场发现,每一名免费师范生均可在电信营业摊点前免费领取一部3G手机。师范新生潘同学说,她的录取通知书里夹着一张单子,填写个人信息后就可以免费领到一部3G手机。
针对有运营商营销中打规定擦边球的现象,著名电信分析师付亮认为,运营商运用各种办法有针对性营销可以理解,但是学生的个人信息来源是个问题。
这个例子实现的功能和上衣个基本类似,只不过识别引擎换成了Google自家的识别器了。
讯飞的语音云主要还是在普通话方面的识别,识别英语的话就会比较坑(比如你想语音输入banana基本是不可能),Google可以识别多种语言,英语当然是毫无压力啦。
效果:
例子中需要注意的一个问题是:startActivity(Intent)和startActivityForResult(Intent,int)的区别使用。
startActivity(Intent)
方法可以用来启动一个新的 activity ,这个 activity 将被放置在 activity 栈的栈顶。这个方法只有一个参数 Intent ,这个参数描述了将被执行的 activity 。
有时候你希望在一个 activity 结束时得到它返回的结果。举个例子,你可能启动一个 activity 来让用户从通讯簿中选择一个人;当它结束的时候将会返回这个所选择的人。为了得到这个返回的信息,你可以使用 startSubActivity(Intent, int) 这个方法来启动新的 activity ,第二个整形参数将会作为这次调用的识别标记。这个 activity 返回的结果你可以通过 onActivityResult(int, int, String, Bundle) 方法来获得,此方法的第一个参数就是之前调用所使用的识别标记。
当 activity 退出的时候,它可以调用 setResult(int) 来将数据返回给他的父进程。这个方法必须提供一个结果码,这个结果码可以使标准结果 RESULT_CANCELED, RESULT_OK ,也可以是其他任何从 RESULT_FIRST_USER 开始的自定义值。此外,它还可以返回一段字符串(经常是一段数据的 URL 地址),一个包含它所有希望值的 Bundle 。这些信息都会在父 activity 的回调函数 Activity.onActivityResult() 中出现,并连同最初提供的识别标记一起(此处有些拗口,意思其实就是子activity
返回的内容、返回码、识别标记都将作为参数,按照不同的返回情况来调用父activity 的Activity.onActivityResult() 方法,以实现出现各种返回时父activity 做出响应的处理)。
代码清单:
package com.example.googlevoice; import java.util.List; import android.app.Activity; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.os.Bundle; import android.speech.RecognizerIntent; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.TextView; public class MainActivity extends Activity implements OnClickListener{ private Button btn ; private TextView myTextView; private static final int REQUEST_CODE = 1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn = (Button) this.findViewById(R.id.btn); myTextView = (TextView) this.findViewById(R.id.ResultText); /** * 下面是判断当前手机是否支持语音识别功能 */ PackageManager pm = getPackageManager(); List<ResolveInfo> list = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); if(list.size()!=0) { btn.setOnClickListener(this); }else{ btn.setEnabled(false); btn.setText("当前语音识别设备不可用..."); } } public void onClick(View v) { if(v.getId()==R.id.btn) { /** * 启动手机内置的语言识别功能 */ Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,"en-US"); //设置为当前手机的语言类型 intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "请说话,我识别");//出现语言识别界面上面需要显示的提示 startActivityForResult(intent,REQUEST_CODE); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { /** * 回调获取从谷歌得到的数据 */ if(requestCode==REQUEST_CODE&&resultCode==RESULT_OK) { List<String> list = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); //只选取第一个结果显示 myTextView.setText(list.get(0)); } super.onActivityResult(requestCode, resultCode, data); } }
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/ResultText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="ResultText" /> <LinearLayout android:id="@+id/bottom" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orientation="horizontal" > <Button android:id="@+id/btn" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="GoogleVoice" /> </LinearLayout> </RelativeLayout>
参考资料:http://blog.csdn.net/vipa1888/article/details/7023928
根据学习笔记一完成一些代码,贴出来看看:
Notepad.java
package com.example.notepad; import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.BroadcastReceiver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; import android.os.Bundle; import android.os.Environment; import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.EditText; // TODO: Auto-generated Javadoc /** * The Class Notepad. */ public class Notepad extends Activity { /** The et. */ private EditText et; /** The Constant RECOGNIZER. */ private static final int RECOGNIZER = 1001; // Intent返回结果验证码 /** The filename. */ private String filename = "新建文档.txt"; // 保存文本时默认文件名 /** The my dialog edit text. */ private EditText myDialogEditText; public static final String INTENAL_ACTION_1 = "com.example.notpad.Internal_1"; static Notepad activity = null; private BroadcastReceiver bcrIntenal1 = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { String msg = intent.getStringExtra("message"); // Toast.makeText(context, "动态:" + msg, 0).show(); try { // byteFile.writeToFile(msg); save(); Log.v("msg", "save in temporary file automatic (temp.txt)"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; public static class LinedEditText extends EditText { private Rect mRect; private Paint mPaint; // This constructor is used by LayoutInflater public LinedEditText(Context context, AttributeSet attrs) { super(context, attrs); // Creates a Rect and a Paint object, and sets the style and color // of the Paint object. mRect = new Rect(); mPaint = new Paint(); mPaint.setStyle(Paint.Style.STROKE); mPaint.setColor(0x800000FF); } public static Activity getActivity() { return activity; } /** * This is called to draw the LinedEditText object * * @param canvas The canvas on which the background is drawn. */ @Override protected void onDraw(Canvas canvas) { // Gets the number of lines of text in the View. int count = getLineCount(); // Gets the global Rect and Paint objects Rect r = mRect; Paint paint = mPaint; /* * Draws one line in the rectangle for every line of text in the * EditText */ for (int i = 0; i < count; i++) { // Gets the baseline coordinates for the current line of text int baseline = getLineBounds(i, r); /* * Draws a line in the background from the left of the rectangle * to the right, at a vertical position one dip below the * baseline, using the "paint" object for details. */ canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint); } // Finishes up by calling the parent method super.onDraw(canvas); } } /* * (non-Javadoc) * @see android.app.Activity#onCreate(android.os.Bundle) */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); et = (EditText) findViewById(R.id.EditText01); activity = this; // 动态注册广播消息 registerReceiver(bcrIntenal1, new IntentFilter( INTENAL_ACTION_1)); Intent serviceIntent = new Intent(Notepad.this, MyService.class); startService(serviceIntent); } public static Activity getActivity() { return activity; } // public void onStart() { // Intent intent = this.getIntent(); // System.out.println(intent.getStringExtra("data")); // et.setText(intent.getStringExtra("data")); // } /* * (non-Javadoc) * @see android.app.Activity#onResume() */ public void onResume() { // 重写onResume,防止程序stop后编辑内容丢失 super.onResume(); registerReceiver(bcrIntenal1, new IntentFilter( INTENAL_ACTION_1)); // try { // File file = new File("/mnt/sdcard/Notepad/temp1.txt"); // 读取临时文件,恢复上一次编辑内容 // RandomAccessFile stream = new RandomAccessFile(file, "rw"); // String s = stream.readLine(); // stream.close(); // et.setText(s); // } catch (Exception e) { // // TODO: handle exception // e.printStackTrace(); // } } // public void onStop() { // super.onStop(); // unregisterReceiver(bcrIntenal1); // } /* * (non-Javadoc) * @see android.app.Activity#onPause() */ public void onPause() { // 编辑内容存入临时文件 super.onPause(); unregisterReceiver(bcrIntenal1); // File file = new File("/mnt/sdcard/Notepad/temp1.txt"); // String data = et.getText().toString(); // // try { // // RandomAccessFile stream = new RandomAccessFile(file, "rw"); // stream.writeBytes(data); // stream.close(); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } } /* * (non-Javadoc) * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu) */ public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } /* * (non-Javadoc) * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem) */ public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menuItemNew: creatNote(); return true; case R.id.menuItemOpen: openNote(); return true; case R.id.menuItemSave: saveNote(); return true; } return super.onOptionsItemSelected(item); } /** * Creat note. */ private void creatNote() { et.setText(""); } /** * Open note. */ private void openNote() { Intent list = new Intent(this, OpenNote.class); startActivityForResult(list, RECOGNIZER); } /* * (non-Javadoc) * @see android.app.Activity#onActivityResult(int, int, * android.content.Intent) */ protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == RECOGNIZER && resultCode == RESULT_OK) { String text = data.getExtras().getString("data"); et.setText(text); } super.onActivityResult(requestCode, resultCode, data); } private void save() { File sdcardDir = Environment .getExternalStorageDirectory(); String path = sdcardDir.getName() + "/Notepad"; File f = new File(path); String fileName = path + java.io.File.separator + "temp.txt"; java.io.BufferedWriter bw; try { bw = new java.io.BufferedWriter( new java.io.FileWriter( new java.io.File(fileName))); String str = et.getText().toString(); bw.write(str, 0, str.length()); bw.newLine(); bw.close(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } /** * Save note. */ private void saveNote() { LayoutInflater factory = LayoutInflater.from(this); final View textEntryView = factory.inflate( R.layout.save_dialog, null); Builder builder = new AlertDialog.Builder(Notepad.this); builder.setView(textEntryView); myDialogEditText = (EditText) textEntryView .findViewById(R.id.myDialogEditText); myDialogEditText.setText(filename); builder.setTitle("保存"); builder.setPositiveButton(R.string.str_alert_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub File sdcardDir = Environment .getExternalStorageDirectory(); String path = sdcardDir.getName() + "/Notepad"; File f = new File(path); File[] files = f.listFiles(); filename = myDialogEditText.getText() .toString(); for (int i = 0; i < files.length; i++) { // 存在同名文件 File file = files[i]; // Log.v("name", file.getName().toString()); if (file.getName().toString() .equals(filename)) { new AlertDialog.Builder(Notepad.this) .setTitle("文件名重复,请重新输入") .setPositiveButton("OK", null) .show(); } } String fileName = path + java.io.File.separator + myDialogEditText.getText() .toString(); java.io.BufferedWriter bw; try { bw = new java.io.BufferedWriter( new java.io.FileWriter( new java.io.File(fileName))); String str = et.getText().toString(); bw.write(str, 0, str.length()); bw.newLine(); bw.close(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } }); builder.setNegativeButton(R.string.str_alert_cancel, null); builder.show(); } }OpenNote.java
package com.example.notepad; import java.io.File; import java.io.FileInputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.TextView; import android.widget.Toast; // TODO: Auto-generated Javadoc /** * The Class OpenNote. */ public class OpenNote extends Activity { /** Called when the activity is first created. */ private ListView listview; /** The items. */ private ArrayList<String> items = null; /** The paths. */ private ArrayList<String> paths = null; /** The root path. */ private String rootPath = "/"; // 根目录 /** The m path. */ private TextView mPath; // 当前路径 /** The currentpath. */ String currentpath; /** The list items. */ private List<Map<String, Object>> listItems = null; /* (non-Javadoc) * @see android.app.Activity#onCreate(android.os.Bundle) */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.open_note); init(); getFileDir(rootPath); } /** * Gets the file dir. * * @param filePath the file path * @return the file dir */ private void getFileDir(String filePath) { mPath.setText("当前目录:" + filePath); currentpath = filePath; List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>(); items = new ArrayList<String>(); paths = new ArrayList<String>(); File f = new File(filePath); File[] files = f.listFiles(); Map<String, Object> listItem = new HashMap<String, Object>(); if (!filePath.equals(rootPath)) { items.add("cd /"); paths.add(rootPath); items.add("cd .."); paths.add(f.getParent()); listItem.put("header", R.drawable.back01); listItem.put("name", "cd /"); listItems.add(listItem); Map<String, Object> listItem1 = new HashMap<String, Object>(); listItem1.put("header", R.drawable.back02); listItem1.put("name", "cd .."); listItems.add(listItem1); } for (int i = 0; i < files.length; i++) { Map<String, Object> listItem2 = new HashMap<String, Object>(); File file = files[i]; items.add(file.getName()); paths.add(file.getPath()); if (file.isDirectory()) { listItem2.put("header", R.drawable.folder); } else { String pathStr = file.getAbsolutePath(); if (pathStr .matches("[^\\S]+(\\.avi|\\.mp4|\\.rmvb)$")) { listItem2.put("header", R.drawable.video); } else if (pathStr.matches("[^\\S]+(\\.asv|\\.mp3)$")) { listItem2.put("header", R.drawable.audio); } else if (pathStr .matches("[^\\S]+(\\.jpg|\\.png|\\.gif)$")) { listItem2.put("header", R.drawable.image); } else { listItem2.put("header", R.drawable.doc); } } listItem2.put("name", file.getName()); listItems.add(listItem2); } String[] from = { "header", "name" }; int[] to = { R.id.header, R.id.name }; SimpleAdapter adapter = new SimpleAdapter(this, listItems, R.layout.file_row, from, to); listview.setAdapter(adapter); } /** * Inits the. */ public void init() { listview = (ListView) findViewById(R.id.file_listview); mPath = (TextView) findViewById(R.id.current_path); listview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) { File file = new File(paths.get(position)); if (file.canRead()) { if (file.isDirectory()) { getFileDir(paths.get(position)); } else { String data = "fail"; try { FileInputStream stream = new FileInputStream( paths.get(position)); StringBuffer sb = new StringBuffer(); int c; while ((c = stream.read()) != -1) { sb.append((char) c); } stream.close(); data = sb.toString(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } Intent i = getIntent(); i.putExtra("data", data); setResult(RESULT_OK, i); finish(); } } else { Toast toast = Toast.makeText(OpenNote.this, "您的权限不足!", Toast.LENGTH_LONG); toast.show(); } } }); } /* (non-Javadoc) * @see android.app.Activity#onKeyDown(int, android.view.KeyEvent) */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == event.KEYCODE_BACK) { if (currentpath == rootPath) { File f = new File(currentpath); getFileDir(currentpath); } else { File f = new File(currentpath); getFileDir(f.getParent()); } } return super.onKeyDown(keyCode, event); } }