一、打開第三方應用
(1)
Intent intent=new Intent();
//包名 包名+類名(全路徑)
intent.setClassName("com.jack", "com.jack.PlaneActivity");
startActivity(intent);
(2)
Intent intent = new Intent();
ComponentName comp = new ComponentName("com.jack","com.jack.PlaneActivity");
intent.setComponent(comp);
intent.setAction("android.intent.action.MAIN");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
(3)轉載自
https://blog.csdn.net/aaa111/article/details/41833189public static final String APP_PACKAGE_NAME = "com.*.*";//包名
/**
* 啟動薄荷App
* @param context
*/
public static void launchapp(Context context) {
// 判斷是否安裝過App,否則去市場下載下傳
if (isAppInstalled(context, APP_PACKAGE_NAME)) {
context.startActivity(context.getPackageManager().getLaunchIntentForPackage(APP_PACKAGE_NAME));
} else {
goToMarket(context, APP_PACKAGE_NAME);
}
}
/**
* 檢測某個應用是否安裝
*
* @param context
* @param packageName
* @return
*/
public static boolean isAppInstalled(Context context, String packageName) {
try {
context.getPackageManager().getPackageInfo(packageName, 0);
return true;
} catch (NameNotFoundException e) {
return false;
}
}
/**
* 去市場下載下傳頁面
*/
public static void goToMarket(Context context, String packageName) {
Uri uri = Uri.parse("market://details?id=" + packageName);
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
try {
context.startActivity(goToMarket);
} catch (ActivityNotFoundException e) {
}
}
調用系統應用
(1)從 google 搜尋内容
Intent intent = new Intent();
intent.setAction(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, "搜尋内容")
startActivity(intent);
(2)浏覽網頁
Uri uri = Uri.parse("http://www.google.com");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
(3)顯示地圖
Uri uri = Uri.parse("geo:38.899533,-77.036476");
Intent it = newIntent(Intent.Action_VIEW,uri);
startActivity(it);
(4)撥打電話
Uri uri =Uri.parse("tel:xxxxxx");
Intent it = new Intent(Intent.ACTION_DIAL,uri);
startActivity(it);
(5)發短信
//方法1:
Intent it = newIntent(Intent.ACTION_VIEW);
it.putExtra("sms_body", "TheSMS text");
it.setType("vnd.android-dir/mms-sms");
startActivity(it);
//方法2:
Uri uri =Uri.parse("smsto:0800000123");
Intent it = newIntent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "TheSMS text");
startActivity(it);
//方法三:
String body="this is sms demo";
Intent mmsintent = newIntent(Intent.ACTION_SENDTO, Uri.fromParts("smsto", number, null));
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,true);
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,true);
startActivity(mmsintent);
(6)發 Email
Uri uri = Uri.parse("mailto:[email protected]");
Intent it = newIntent(Intent.ACTION_SENDTO, uri);
startActivity(it);
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_EMAIL,"[email protected]");
it.putExtra(Intent.EXTRA_TEXT, "Theemail body text");
it.setType("text/plain");
startActivity(Intent.createChooser(it,"Choose Email Client"));
Intent it=new Intent(Intent.ACTION_SEND);
String[] tos={"[email protected]"};
String[]ccs={"[email protected]"};
it.putExtra(Intent.EXTRA_EMAIL, tos);
it.putExtra(Intent.EXTRA_CC, ccs);
it.putExtra(Intent.EXTRA_TEXT, "Theemail body text");
it.putExtra(Intent.EXTRA_SUBJECT, "Theemail subject text");
it.setType("message/rfc822");
startActivity(Intent.createChooser(it,"Choose Email Client"));
Intent it = newIntent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_SUBJECT, "Theemail subject text");
it.putExtra(Intent.EXTRA_STREAM,"file:///sdcard/mysong.mp3");
sendIntent.setType("audio/mp3");
startActivity(Intent.createChooser(it,"Choose Email Client"));
(7)播放多媒體
Intent it = new Intent(Intent.ACTION_VIEW);
Uri uri =Uri.parse("file:///sdcard/song.mp3");
it.setDataAndType(uri,"audio/mp3");
startActivity(it);
Uri uri =Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"1");
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);
(8)解除安裝 apk
Uri uri =Uri.fromParts("package", strPackageName, null);
Intent it = newIntent(Intent.ACTION_DELETE, uri);
startActivity(it);
(9)安裝 apk
Uri installUri = Uri.fromParts("package","xxx", null);
returnIt = newIntent(Intent.ACTION_PACKAGE_ADDED, installUri);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + filepath),"application/vnd.android.package-archive");
startActivity(intent);// 安裝
(10)顯示應用詳細清單
Uri uri =Uri.parse("market://details?id=app_id");
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);
//where app_id is the application ID, findthe ID
//by clicking on your application on Markethome
//page, and notice the ID from the addressbar
//發現用package name也可以
//Uri uri =Uri.parse("market://details?id=<packagename>");
(11)尋找應用
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 pathfor an application
(12)打開聯系人清單
//1
Intent i = new Intent();
i.setAction(Intent.ACTION_GET_CONTENT);
i.setType("vnd.android.cursor.item/phone");
startActivityForResult(i, REQUEST_TEXT);
//2
Uri uri = Uri.parse("content://contacts/people");
Intent it = new Intent(Intent.ACTION_PICK, uri);
startActivityForResult(it, REQUEST_TEXT);
這篇文章是轉載的,出處在這
,随着 Android 版本的提高,權限也有很多的變化,是以可能會有一些方法不能使用,不過這裡可以作為參考。也算是彌補了以下基本知識。再說了,記不得 Google 不就 OK 了是吧。
願我們成為真實的自己。