Android跳轉系統界面_大全集

Android系統在設計之初就強調重視組件的概念,輕視應用的概念。每一個App都不是互相獨立的,而是以一種組件化地對外對內提供服務,App間的交互很多,比如跨應用獲取數據,跳轉頁面等。

今天這篇文章就來做一個大彙總,記錄常用的跳轉系統界面的代碼。總共52條,後續可能會少量補充。

老規矩,在節目開始之前,先來一個搞笑段子:
同事嫖娼被抓,拘留15天,他老婆衝到派出所大吵大罵。他同事淡定地過去勸說:“嫂子你聽我說,大哥昨晚喝多了,我們不讓他走,他說老婆在家等呢,堅持要回去,結果被查了酒駕。按法律要關6個月,還要重考駕照。我們找了很多關係才改成嫖娼。”她老婆瞬間感動,臨走時還不停地說:“謝謝,謝謝啊!”

<本文主要測試機型:Google Nexus5>

<主要包括兩大部分:Setting及其子頁面、系統App>

1、跳轉Setting應用列表(所有應用)

Intent intent =  new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
this.startActivity(intent);

2、跳轉Setting應用列表(安裝應用)

Intent intent =  new Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);

3、跳轉Setting應用列表

Intent intent =  new Intent(Settings.ACTION_APPLICATION_SETTINGS);

4、開發者選項

Intent intent =  new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);

5、允許在其它應用上層顯示的應用

Intent intent =  new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);

6、無障礙設置

Intent intent =  new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);

7、添加賬戶

Intent intent =  new Intent(Settings.ACTION_ADD_ACCOUNT);

8、WIFI設置

Intent intent =  new Intent(Settings.ACTION_WIFI_SETTINGS);

9、藍牙設置

Intent intent =  new Intent(Settings.ACTION_BLUETOOTH_SETTINGS);

10、移動網絡設置

Intent intent =  new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS);

11、日期時間設置

Intent intent =  new Intent(Settings.ACTION_DATE_SETTINGS);

12、關於手機界面

Intent intent =  new Intent(Settings.ACTION_DEVICE_INFO_SETTINGS);

13、顯示設置界面

Intent intent =  new Intent(Settings.ACTION_DISPLAY_SETTINGS);

14、聲音設置

Intent intent =  new Intent(Settings.ACTION_SOUND_SETTINGS);

15、互動屏保

Intent intent =  new Intent(Settings.ACTION_DREAM_SETTINGS);

16、輸入法

Intent intent =  new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS);

17、輸入法_SubType

Intent intent =  new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);

18、內部存儲設置界面

Intent intent =  new Intent(Settings.ACTION_INTERNAL_STORAGE_SETTINGS);

19、存儲卡設置界面

Intent intent =  new Intent(Settings.ACTION_MEMORY_CARD_SETTINGS);

20、語言選擇界面

Intent intent =  new Intent(Settings.ACTION_LOCALE_SETTINGS);

21、位置服務界面

Intent intent =  new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);

22、運營商

Intent intent =  new Intent(Settings.ACTION_NETWORK_OPERATOR_SETTINGS);

23、NFC共享界面

Intent intent =  new Intent(Settings.ACTION_NFCSHARING_SETTINGS);

24、NFC設置

Intent intent =  new Intent(Settings.ACTION_NFC_SETTINGS);

25、備份和重置

Intent intent =  new Intent(Settings.ACTION_PRIVACY_SETTINGS);

26、快速啓動

Intent intent =  new Intent(Settings.ACTION_QUICK_LAUNCH_SETTINGS);

27、搜索設置

Intent intent =  new Intent(Settings.ACTION_SEARCH_SETTINGS);

28、安全設置

Intent intent =  new Intent(Settings.ACTION_SECURITY_SETTINGS);

29、設置的主頁

Intent intent =  new Intent(Settings.ACTION_SETTINGS);

30、用戶同步界面

Intent intent =  new Intent(Settings.ACTION_SYNC_SETTINGS);

31、用戶字典

Intent intent =  new Intent(Settings.ACTION_USER_DICTIONARY_SETTINGS);

32、IP設置

Intent intent =  new Intent(Settings.ACTION_WIFI_IP_SETTINGS);

33、App設置詳情界面

public void startAppSettingDetail() {
   String packageName = getPackageName();
    Uri packageURI = Uri.parse("package:" + packageName);
    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    intent.setData(packageURI);
    startActivity(intent);
}

34、跳轉應用市場

public void startMarket() {
    Intent intent = new Intent(Intent.ACTION_VIEW);
//  intent.setData(Uri.parse("market://details?id=" + "com.xxx.xxx"));
    intent.setData(Uri.parse("market://search?q=App Name"));
    startActivity(intent);
}

35、獲取Launcherbaoming

public void getLauncherPackageName() {
   Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    final ResolveInfo res = this.getPackageManager().resolveActivity(intent, 0);
    if (res.activityInfo == null) {
        Log.e("TAG", "沒有獲取到");
        return;
    }

    if (res.activityInfo.packageName.equals("android")) {
        Log.e("TAG", "有多個Launcher,且未指定默認");
    } else {
        Log.e("TAG", res.activityInfo.packageName);
    }
}

36、跳轉圖庫獲取圖片

public void startGallery() {
  Intent intent = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    intent.setType("image/*");
    this.startActivityForResult(intent, 1);
}

37、跳轉相機,拍照並保存

public void startCamera() {
 String dir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/test.jpg";
    Uri headCacheUri = Uri.fromFile(new File(dir));
    Intent takePicIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    takePicIntent.putExtra(MediaStore.EXTRA_OUTPUT, headCacheUri);
    startActivityForResult(takePicIntent, 2);
}

38、跳轉文件管理器

public void startFileManager() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    intent.setType("file/*");
    this.startActivityForResult(intent, 3);
}

39、直接撥打電話

public void startCall() {
 Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.setData(Uri.parse("tel:" + "13843894038"));
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    startActivity(callIntent);
}

40、跳轉電話應用

public void startPhone() {
Intent intent = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:" + "13843894038"));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}

41、發送短信

public void startSMS() {
    Uri smsToUri = Uri.parse("smsto://10086");
    Intent mIntent = new Intent( android.content.Intent.ACTION_SENDTO, smsToUri );
    startActivity(mIntent);
}

42、發送彩信

public void startMMS() {
 Uri uri = Uri.parse("content://media/external/images/media/11");
    Intent it = new Intent(Intent.ACTION_SEND);
    it.putExtra("sms_body", "some text");
    it.putExtra(Intent.EXTRA_STREAM, uri);
    it.setType("image/png");
    startActivity(it);
}

43、發送郵件

public void startEmail() {
   Uri uri = Uri.parse("mailto:[email protected]");
    String[] email = {"[email protected]"};
    Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
    intent.putExtra(Intent.EXTRA_CC, email); // 抄送人
    intent.putExtra(Intent.EXTRA_SUBJECT, "這是郵件的主題部分"); // 主題
    intent.putExtra(Intent.EXTRA_TEXT, "這是郵件的正文部分"); // 正文
    startActivity(Intent.createChooser(intent, "請選擇郵件類應用"));
}

44、跳轉聯繫人

public void startContact() {
  Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setData(Contacts.People.CONTENT_URI);
    startActivity(intent);

    /*Intent intent = new Intent();
    intent.setAction(Intent.ACTION_PICK);
    intent.setData(Uri.parse("content://contacts/people"));
    startActivityForResult(intent, 5);*/
}

45、插入聯繫人

public void insertContact() {
  Intent intent = new Intent(Intent.ACTION_INSERT);
    intent.setData(ContactsContract.Contacts.CONTENT_URI);
    intent.putExtra(ContactsContract.Intents.Insert.PHONE, "18688888888");
    startActivityForResult(intent, 1);
}

46、插入日曆事件

public void startCalender() {
 Intent intent = new Intent(Intent.ACTION_INSERT);
    intent.setData(CalendarContract.Events.CONTENT_URI);
    intent.putExtra(CalendarContract.Events.TITLE, "開會");
    startActivityForResult(intent, 1);
}

47、跳轉瀏覽器

public void startBrowser() {
  Uri uri = Uri.parse("http://www.baidu.com");
    Intent intent = new Intent(Intent.ACTION_VIEW,uri);
    startActivity(intent);
}

48、安裝應用

public void startInstall() {
 String filePath="/xx/xx/abc.apk";
    Intent intent = new  Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.parse("file://" + filePath),
            "application/vnd.android.package-archive");
    startActivity(intent);
}

49、卸載應用

public void startUnInstall() {
  String packageName="cn.memedai.mas.debug";
    Uri packageUri = Uri.parse("package:"+packageName);//包名,指定該應用
    Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageUri);
    startActivity(uninstallIntent);
}

50、回到桌面

public void startLauncherHome() {
  Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    startActivity(intent);
}

51、打開任意文件(根據其MIME TYPE自動選擇打開的應用)

private void openFile(File f) {
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(android.content.Intent.ACTION_VIEW);
    String type = getMIMEType(f);
    intent.setDataAndType(Uri.fromFile(f), type);
    startActivity(intent);
}

private String getMIMEType(File f) {
    String end = f.getName().substring(f.getName().lastIndexOf(".") + 1,
            f.getName().length()).toLowerCase();
    String type = "";
    if (end.equalsIgnoreCase("mp3")
            || end.equalsIgnoreCase("aac")
            || end.equalsIgnoreCase("amr")
            || end.equalsIgnoreCase("mpeg")
            || end.equalsIgnoreCase("mp4")) {
        type = "audio";
    } else if(end.equalsIgnoreCase("mp4")
            || end.equalsIgnoreCase("3gp")
            || end.equalsIgnoreCase("mpeg4")
            || end.equalsIgnoreCase("3gpp")
            || end.equalsIgnoreCase("3gpp2")
            || end.equalsIgnoreCase("flv")
            || end.equalsIgnoreCase("avi")) {
        type = "video";
    } else if (end.equalsIgnoreCase("jpg")
            || end.equalsIgnoreCase("gif")
            || end.equalsIgnoreCase("bmp")
            || end.equalsIgnoreCase("png")
            || end.equalsIgnoreCase("jpeg")) {
        type = "image";
    } else {
        type = "*";
    }
    type += "/*";
    return type;
}

52、跳轉錄音

public void startRecord() {
 Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
    startActivity(intent);
}

目前就先寫這麼多,有新的後續再補充。
如果這篇文章對你有幫助就贊一個吧!

本期節目就到這裏,感謝您的收看,我們下期再見~

發佈了40 篇原創文章 · 獲贊 88 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章