Android中通過Intent 調用圖片、視頻、音頻、錄音、拍照

//選擇圖片 requestCode 返回的標識
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); //"android.intent.action.GET_CONTENT"
intent.setType(contentType); //查看類型 String IMAGE_UNSPECIFIED = "image/*";
Intent wrapperIntent = Intent.createChooser(intent, null);
((Activity) context).startActivityForResult(wrapperIntent, requestCode);

//添加音頻
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";
Intent wrapperIntent = Intent.createChooser(intent, null);
((Activity) context).startActivityForResult(wrapperIntent, requestCode);

//拍攝視頻
int durationLimit = getVideoCaptureDurationLimit(); //SystemProperties.getInt("ro.media.enc.lprof.duration", 60);
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, sizeLimit);
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, durationLimit);
startActivityForResult(intent, REQUEST_CODE_TAKE_VIDEO);

//視頻
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";
Intent wrapperIntent = Intent.createChooser(intent, null);
((Activity) context).startActivityForResult(wrapperIntent, requestCode);

//錄音
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(ContentType.AUDIO_AMR); //String AUDIO_AMR = "audio/amr";
intent.setClassName("com.android.soundrecorder",
"com.android.soundrecorder.SoundRecorder");
((Activity) context).startActivityForResult(intent, requestCode);

//拍照 REQUEST_CODE_TAKE_PICTURE 爲返回的標識
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //"android.media.action.IMAGE_CAPTURE";
intent.putExtra(MediaStore.EXTRA_OUTPUT, Mms.ScrapSpace.CONTENT_URI); // output,Uri.parse("content://mms/scrapSpace");
startActivityForResult(intent, REQUEST_CODE_TAKE_PICTURE);

//瀏覽器

Intent browserIntent = new Intent(Intent.ACTION_VIEW);    

   browserIntent.setType("plain/text");

   browserIntent.setData(Uri.parse("www.baidu.com"));    
   startActivity(browserIntent);

//下載市場

//search
Uri uri = Uri.parse("market://search?q=pname:pkg_name");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where pkg_name is the full package path for an application

//show program detail page
Uri uri = Uri.parse("market://details?id=app_id");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);

顯示Web網頁:

  1. Uri uri = Uri.parse(”http://www.android123.com.cn”);

  2. Intent it = new Intent(Intent.ACTION_VIEW,uri);

  3. startActivity(it);

  顯示Google地圖:

  1. Uri uri = Uri.parse(”geo:38.899533,-77.03****76″);

  2. Intent it = new Intent(Intent.Action_VIEW,uri);

  3. startActivity(it);

  Maps路徑規劃:

  1. Uri uri = Uri.parse(”http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en”);

  2. Intent it = new Intent(Intent.ACTION_VIEW,URI);

  3. startActivity(it);

  撥打電話:

  1. Uri uri = Uri.parse(”tel:xxxxxx”);

  2. Intent it = new Intent(Intent.ACTION_DIAL, uri);

  3. startActivity(it);

  1. Uri uri = Uri.parse(”tel.xxxxxx”);

  2. Intent it =new Intent(Intent.ACTION_CALL,uri);

  注意需要權限

  發送SMS/MMS

  1. Intent it = new Intent(Intent.ACTION_VIEW);

  2. it.putExtra(”sms_body”, “android開發網歡迎您”);

  3. it.setType(”vnd.android-dir/mms-sms”);

  4. startActivity(it);

  發送短信

  1. Uri uri = Uri.parse(”smsto:10086″);

  2. Intent it = new Intent(Intent.ACTION_SENDTO, uri);

  3. it.putExtra(”sms_body”, “10086″); //正文爲10086

  4. startActivity(it);

  發送彩信

  1. Uri uri = Uri.parse(”content://media/external/images/media/10″); //該Uri根據實際情況修改,external代表外部存儲即sdcard

  2. Intent it = new Intent(Intent.ACTION_SEND);

  3. it.putExtra(”sms_body”, “android123.com.cn”);

  4. it.putExtra(Intent.EXTRA_STREAM, uri);

  5. it.setType(”image/png”);

  6. startActivity(it);

  發送Email

  2. Uri uri = Uri.parse(”mailto:[email protected]”);

  3. Intent it = new Intent(Intent.ACTION_SENDTO, uri);

  4. startActivity(it);

  1. Intent it = new Intent(Intent.ACTION_SEND);

  2. it.putExtra(Intent.EXTRA_EMAIL, “[email protected]”);

  3. it.putExtra(Intent.EXTRA_TEXT, “android開發網測試”);

  4. it.setType(”text/plain”);

  5. startActivity(Intent.createChooser(it, “選擇一個Email客戶端”));

  1. Intent it=new Intent(Intent.ACTION_SEND);

  2. String[] tos={”[email protected]”}; //發送到

  3. String[] ccs={”[email protected]”}; //抄送

  4. it.putExtra(Intent.EXTRA_EMAIL, tos);

  5. it.putExtra(Intent.EXTRA_CC, ccs);

  6. it.putExtra(Intent.EXTRA_TEXT, “正文”);

  7. it.putExtra(Intent.EXTRA_SUBJECT, “標題”);

  8. it.setType(”message/rfc822″); //編碼類型

  9. startActivity(Intent.createChooser(it, “選擇一個Email客戶端”));

  Email添加附件

  1. Intent it = new Intent(Intent.ACTION_SEND);

  2. it.putExtra(Intent.EXTRA_SUBJECT, “正文”);

  3. it.putExtra(Intent.EXTRA_STREAM, “file:///sdcard/nobody.mp3″); //附件爲sd卡上的nobody MP3文件

  4. sendIntent.setType(”audio/mp3″);

  5. startActivity(Intent.createChooser(it, “選擇一個Email客戶端”));

  播放多媒體

  1.

  2. Intent it = new Intent(Intent.ACTION_VIEW);

  3. Uri uri = Uri.parse(”file:///sdcard/nobody.mp3″);

  4. it.setDataAndType(uri, “audio/mp3″);

  5. startActivity(it);

  1. Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, “1″); //從系統內部的MediaProvider索引中調用播放

  2. Intent it = new Intent(Intent.ACTION_VIEW, uri);

  3. startActivity(it);

  Uninstall卸載程序

  1. Uri uri = Uri.fromParts(”package”, packageName, null); //packageName爲包名,比如com.android123.apkInstaller

  2. Intent it = new Intent(Intent.ACTION_DELETE, uri);

  3. startActivity(it);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章