android 外部启动activity,…

来源:互联网 发布:硬科幻知乎 编辑:程序博客网 时间:2024/06/07 09:20
转自:http://www.qylk.blog.163.com/blog/static/13468735620130913043889/
从任意app,启动另外一个app的activity:
1. Intent i = newIntent(); 
       ComponentName cn = newComponentName("com.book.android2", "com.book.android2.AndroidSearch"); 
       i.setComponent(cn); 
       i.setAction("android.intent.action.MAIN"); 
       startActivity(i); //or startActivityForResult(i,RESULT_OK); 
我用这种方法时,绝大部分应用可以启动,但是像RootExplorer却无法启动,出现FC对话框,因此建议使用下面这种方式:
2.  Intent it = newIntent("android.intent.action.MAIN");
   it.setClassName("com.speedsoftware.rootexplorer","com.speedsoftware.rootexplorer.RootExplorer");
   startActivity(it);

如果你需要启动一个你自己写的另一个app的activity,你可以在那个的menifest.xml里自定义activity的action:
    
 
 
 
 
 

其他地方启动它:Intent it = newIntent("com.qylk.call.main");  startActivity(it);

3.使用adb启动activity:
 启动RootExolorer:
am start -aandroid.intent.action.MAIN -ncom.speedsoftware.rootexplorer/.RootExplorer
启动系统设置:
am start -aandroid.settings.SETTINGS

附(转载):android系统Action常量(其实不算全)
android intent和intentaction大全 

1.从google搜索内容 
Intent intent = newIntent(); 
intent.setAction(Intent.ACTION_WEB_SEARCH); 
intent.putExtra(SearchManager.QUERY,"searchString") 
startActivity(intent); 

2.浏览网页 
Uri uri =Uri.parse("http://www.google.com"); 
Intent it = newIntent(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("http://maps.google.com/maps?f=dsaddr=startLatstartLng&daddr=endLatendLng&hl=en"); 
Intent it = newIntent(Intent.ACTION_VIEW,URI); 
startActivity(it); 

5.拨打电话 
Uri uri =Uri.parse("tel:xxxxxx"); 
Intent it = newIntent(Intent.ACTION_DIAL, uri);  
startActivity(it); 
 // 


6.调用发短信的程序 
Intent it = newIntent(Intent.ACTION_VIEW);   
it.putExtra("sms_body","The SMS text");   
it.setType("vnd.android-dir/mms-sms");   
startActivity(it); 

7.发送短信 
Uri uri =Uri.parse("smsto:0800000123");   
Intent it = newIntent(Intent.ACTION_SENDTO, uri);   
it.putExtra("sms_body","The SMS text");   
startActivity(it); 

String body="this is smsdemo"; 
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); 

8.发送彩信 
Uri uri =Uri.parse("content://media/external/images/media/23");   
Intent it = newIntent(Intent.ACTION_SEND);   
it.putExtra("sms_body","some text");   
it.putExtra(Intent.EXTRA_STREAM, uri);   
it.setType("image/png");   
startActivity(it); 

StringBuilder sb = newStringBuilder(); 
sb.append("file://"); 
sb.append(fd.getAbsoluteFile()); 
Intent intent = newIntent(Intent.ACTION_SENDTO, Uri.fromParts("mmsto", number,null)); 
// Below extra datas areall optional. 
intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT,subject); 
intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body); 
intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI,sb.toString()); 
intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,composeMode); 
intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,exitOnSent); 
startActivity(intent); 

9.发送Email 
Uri uri =Uri.parse("mailto:xxx@abc.com"); 
Intent it = newIntent(Intent.ACTION_SENDTO,uri); 
startActivity(it); 

Intent it = newIntent(Intent.ACTION_SEND);   
it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");   
it.putExtra(Intent.EXTRA_TEXT, "The email bodytext");    
it.setType("text/plain");  
 
startActivity(Intent.createChooser(it, "ChooseEmail Client")); 
Intent it=newIntent(Intent.ACTION_SEND);     
String[]tos={"me@abc.com"};     
String[]ccs={"you@abc.com"};     
it.putExtra(Intent.EXTRA_EMAIL, tos);    
it.putExtra(Intent.EXTRA_CC, ccs);    
it.putExtra(Intent.EXTRA_TEXT, "The email bodytext");     
it.putExtra(Intent.EXTRA_SUBJECT, "The emailsubject text");     
it.setType("message/rfc822");    
startActivity(Intent.createChooser(it, "ChooseEmail Client"));   

Intent it = newIntent(Intent.ACTION_SEND);   
it.putExtra(Intent.EXTRA_SUBJECT, "The emailsubject text");   
it.putExtra(Intent.EXTRA_STREAM,"file:///sdcard/mysong.mp3");   
sendIntent.setType("audio/mp3");   
startActivity(Intent.createChooser(it, "ChooseEmail Client")); 

10.播放多媒体  
Intent it = newIntent(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 = newIntent(Intent.ACTION_VIEW, uri);   
startActivity(it); 

11.卸载
Uri uri =Uri.fromParts("package", strPackageName, null);   
Intent it = newIntent(Intent.ACTION_DELETE, uri);   
startActivity(it); 

12.安装
Uri installUri =Uri.fromParts("package", "xxx",null); 
returnIt = newIntent(Intent.ACTION_PACKAGE_ADDED,installUri); 

13.打开照相机 
   Intent i = newIntent(Intent.ACTION_CAMERA_BUTTON,null); 
   this.sendBroadcast(i);
 
   long dateTaken =System.currentTimeMillis(); 
   String name = createName(dateTaken) +".jpg"; 
   fileName = folder +name; 
   ContentValues values = newContentValues(); 
   values.put(Images.Media.TITLE,fileName); 
   values.put("_data",fileName); 
   values.put(Images.Media.PICASA_ID,fileName); 
   values.put(Images.Media.DISPLAY_NAME,fileName); 
   values.put(Images.Media.DESCRIPTION,fileName); 
  values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME,fileName); 
   Uri photoUri =getContentResolver().insert( 
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values); 
   Intent inttPhoto = newIntent(MediaStore.ACTION_IMAGE_CAPTURE); 
   inttPhoto.putExtra(MediaStore.EXTRA_OUTPUT,photoUri); 
   startActivityForResult(inttPhoto,10); 

14.从gallery选取图片 
  Intenti = new Intent(); 
 i.setType("image/*"); 
 i.setAction(Intent.ACTION_GET_CONTENT); 
 startActivityForResult(i,11); 

15.打开录音机 
  Intent mi = newIntent(Media.RECORD_SOUND_ACTION); 
  startActivity(mi); 

16.显示应用详细列表     
Uri uri =Uri.parse("market://details?id=app_id");       
Intent it = newIntent(Intent.ACTION_VIEW, uri);       
startActivity(it);       
    


17.寻找应用    
刚才找app id未果,结果发现用packagename也可以 
Uri uri =Uri.parse("market://details?id="); 
这个简单多了 
 
Uri uri =Uri.parse("market://search?q=pname:pkg_name");       
Intent it = newIntent(Intent.ACTION_VIEW, uri);       
startActivity(it); 
    
18.打开联系人列表         
         Intent i = newIntent(); 
        i.setAction(Intent.ACTION_GET_CONTENT); 
        i.setType("vnd.android.cursor.item/phone"); 
         startActivityForResult(i,REQUEST_TEXT); 

          Uri uri =Uri.parse("content://contacts/people"); 
          Intent it = newIntent(Intent.ACTION_PICK,uri); 
          startActivityForResult(it,REQUEST_TEXT); 

20.调用系统编辑添加联系人(高版本SDK有效): 
  Intentit = newIntent(Intent.ACTION_INSERT_OR_EDIT); 
            it.setType("vnd.android.cursor.item/contact"); 
             //it.setType(Contacts.CONTENT_ITEM_TYPE); 
             it.putExtra("name","myName"); 
            it.putExtra(android.provider.Contacts.Intents.Insert.COMPANY, "organization"); 
            it.putExtra(android.provider.Contacts.Intents.Insert.EMAIL,"email"); 
            it.putExtra(android.provider.Contacts.Intents.Insert.PHONE,"homePhone"); 
             it.putExtra(android.provider.Contacts.Intents.Insert.SECONDARY_PHONE, 
                          "mobilePhone"); 
             it.putExtra( android.provider.Contacts.Intents.Insert.TERTIARY_PHONE, 
                          "workPhone"); 
            it.putExtra(android.provider.Contacts.Intents.Insert.JOB_TITLE,"title"); 
            startActivity(it); 

21.调用系统编辑添加联系人(全有效): 
Intent intent = newIntent(Intent.ACTION_INSERT_OR_EDIT); 
         intent.setType(People.CONTENT_ITEM_TYPE); 
         intent.putExtra(Contacts.Intents.Insert.NAME, "MyName"); 
         intent.putExtra(Contacts.Intents.Insert.PHONE,"+1234567890"); 
         intent.putExtra(Contacts.Intents.Insert.PHONE_TYPE,Contacts.PhonesColumns.TYPE_MOBILE); 
         intent.putExtra(Contacts.Intents.Insert.EMAIL,"com@com.com"); 
         intent.putExtra(Contacts.Intents.Insert.EMAIL_TYPE,                Contacts.ContactMethodsColumns.TYPE_WORK); 
         startActivity(intent); 



23.最基本的share信息的intent,可以传一段text信息到各个手机上已安装程序:如SMS,Email,sina微波,米聊,facebook,twitter等等 
          Intent it = newIntent(Intent.ACTION_SEND);    
    it.putExtra(Intent.EXTRA_TEXT,"The email subject text"); 
         it.setType("text/plain"); 
         startActivity(Intent.createChooser(it, "Choose EmailClient")); 
        

★intentaction大全: 
ACTION_MAIN                    作为一个主要的进入口,而并不期望去接受数据 
ACTION_VIEW                    向用户去显示数据 
ACTION_ATTACH_DATA              用于指定一些数据应该附属于一些其他的地方,例如,图片数据应该附属于联系人 
ACTION_EDIT                    访问已给的数据,提供明确的可编辑 
ACTION_PICK                    从数据中选择一个子项目,并返回你所选中的项目 
ACTION_CHOOSER                 显示一个activity选择器,允许用户在进程之前选择他们想要的 
ACTION_GET_CONTENT              允许用户选择特殊种类的数据,并返回(特殊种类的数据:照一张相片或录一段音) 
ACTION_DIAL                    拨打一个指定的号码,显示一个带有号码的用户界面,允许用户去启动呼叫 
ACTION_CALL                    根据指定的数据执行一次呼叫(ACTION_CALL在应用中启动一次呼叫有缺陷,多数应用ACTION_DIAL,ACTION_CALL不能用在紧急呼叫上,紧急呼叫可以用ACTION_DIAL来实现) 
ACTION_SEND                    传递数据,被传送的数据没有指定,接收的action请求用户发数据 
ACTION_SENDTO                  发送一跳信息到指定的某人 
ACTION_ANSWER                  处理一个打进电话呼叫 
ACTION_INSERT                  插入一条空项目到已给的容器 
ACTION_DELETE                  从容器中删除已给的数据 
ACTION_RUN                     运行数据,无论怎么 
ACTION_SYNC                    同步执行一个数据 
ACTION_PICK_ACTIVITY            为已知的Intent选择一个Activity,返回选中的类 
ACTION_SEARCH                  执行一次搜索 
ACTION_WEB_SEARCH               执行一次web搜索 
ACTION_FACTORY_TEST             工场测试的主要进入点, 


标准的广播Actions 
ACTION_TIME_TICK               当前时间改变,每分钟都发送,不能通过组件声明来接收,只有通过Context.registerReceiver()方法来注册 
ACTION_TIME_CHANGED            时间被设置 
ACTION_TIMEZONE_CHANGED         时间区改变 
ACTION_BOOT_COMPLETED           系统完成启动后,一次广播 
ACTION_PACKAGE_ADDED           一个新应用包已经安装在设备上,数据包括包名(最新安装的包程序不能接收到这个广播) 
ACTION_PACKAGE_CHANGED          一个已存在的应用程序包已经改变,包括包名 
ACTION_PACKAGE_REMOVED          一个已存在的应用程序包已经从设备上移除,包括包名(正在被安装的包程序不能接收到这个广播) 
ACTION_PACKAGE_RESTARTED        用户重新开始一个包,包的所有进程将被杀死,所有与其联系的运行时间状态应该被移除,包括包名(重新开始包程序不能接收到这个广播) 
ACTION_PACKAGE_DATA_CLEARED      用户已经清除一个包的数据,包括包名(清除包程序不能接收到这个广播) 
ACTION_BATTERY_CHANGED          电池的充电状态、电荷级别改变,不能通过组建声明接收这个广播,只有通过Context.registerReceiver()注册 
ACTION_UID_REMOVED    一个用户ID已经从系统中移除

android.intent.action.ALL_APPS
android.intent.action.ANSWER
android.intent.action.ATTACH_DATA
android.intent.action.BUG_REPORT
android.intent.action.CALL
android.intent.action.CALL_BUTTON
android.intent.action.CHOOSER
android.intent.action.CREATE_LIVE_FOLDER
android.intent.action.CREATE_SHORTCUT
android.intent.action.DELETE
android.intent.action.DIAL
android.intent.action.EDIT
android.intent.action.GET_CONTENT
android.intent.action.INSERT
android.intent.action.INSERT_OR_EDIT
android.intent.action.MAIN
android.intent.action.MEDIA_SEARCH
android.intent.action.PICK
android.intent.action.PICK_ACTIVITY
android.intent.action.RINGTONE_PICKER
android.intent.action.RUN
android.intent.action.SEARCH
android.intent.action.SEARCH_LONG_PRESS
android.intent.action.SEND
android.intent.action.SENDTO
android.intent.action.SET_WALLPAPER
android.intent.action.SYNC
android.intent.action.SYSTEM_TUTORIAL
android.intent.action.VIEW
android.intent.action.VOICE_COMMAND
android.intent.action.WEB_SEARCH
android.net.wifi.PICK_WIFI_NETWORK

SETTING:
android.settings.AIRPLANE_MODE_SETTINGS
android.settings.APN_SETTINGS
android.settings.APPLICATION_DEVELOPMENT_SETTINGS
android.settings.APPLICATION_SETTINGS
android.settings.BLUETOOTH_SETTINGS
android.settings.DATA_ROAMING_SETTINGS
android.settings.DATE_SETTINGS
android.settings.DISPLAY_SETTINGS
android.settings.INPUT_METHOD_SETTINGS
android.settings.INTERNAL_STORAGE_SETTINGS
android.settings.LOCALE_SETTINGS
android.settings.LOCATION_SOURCE_SETTINGS
android.settings.MANAGE_APPLICATIONS_SETTINGS
android.settings.MEMORY_CARD_SETTINGS
android.settings.NETWORK_OPERATOR_SETTINGS
android.settings.QUICK_LAUNCH_SETTINGS
android.settings.SECURITY_SETTINGS
android.settings.SETTINGS
android.settings.SOUND_SETTINGS
android.settings.SYNC_SETTINGS
android.settings.USER_DICTIONARY_SETTINGS
android.settings.WIFI_IP_SETTINGS
android.settings.WIFI_SETTINGS
android.settings.WIRELESS_SETTINGS

在androidSDK文档中有这样一个类,android.provider.Settings类提供android系统各个页面的跳转常量:
使用实例例:startActivity(newIntent(Settings.ACTION_WIRELESS_SETTINGS)),即可跳到android手机网络设置页面。
如果要launch Mobile NetworksSetting页面按如下方法:
Intent intent=newIntent(Settings.ACTION_DATA_ROAMING_SETTINGS);
ComponentName cName = newComponentName(“com.android.phone”,”com.android.phone.Settings”);
intent.setComponent(cName);
startActivity(intent);

如果要进入NetworksOperators页面按如下方法:
Intent intent = newIntent(Intent.ACTION_MAIN);
intent.setClassName(“com.android.phone”,“com.android.phone.NetworkSetting”);
startActivity(intent);

StringACTION_ACCESSIBILITY_SETTINGS
辅助功能模块的显示设置。 ActivityAction: Show settings for accessibilitymodules.
StringACTION_ADD_ACCOUNT
显示屏幕上创建一个新帐户添加帐户。Activity Action: Show add account screen for creating a newaccount.
StringACTION_AIRPLANE_MODE_SETTINGS
显示设置,以允许进入/退出飞行模式。Activity Action: Show settings to allow entering/exiting airplanemode.
StringACTION_APN_SETTINGS
显示设置,以允许配置的APN。 ActivityAction: Show settings to allow configuration ofAPNs.
StringACTION_APPLICATION_DETAILS_SETTINGS
有关特定应用程序的详细信息的显示屏幕。Activity Action: Show screen of details about a particularapplication.
StringACTION_APPLICATION_DEVELOPMENT_SETTINGS
显示设置,以允许应用程序开发相关的设置配置Activity Action: Show settings to allow configuration ofapplication development-related settings.
StringACTION_APPLICATION_SETTINGS
显示设置,以允许应用程序相关的设置配置Activity Action: Show settings to allow configuration ofapplication-related settings.
StringACTION_BLUETOOTH_SETTINGS
显示设置,以允许蓝牙配置 ActivityAction: Show settings to allow configuration ofBluetooth.
StringACTION_DATA_ROAMING_SETTINGS
选择of2G/3G显示设置 ActivityAction: Show settings for selection of2G/3G.
StringACTION_DATE_SETTINGS
显示日期和时间设置,以允许配置 ActivityAction: Show settings to allow configuration of date andtime.
StringACTION_DEVICE_INFO_SETTINGS
显示一般的设备信息设置(序列号,软件版本,电话号码,等) Activity Action:Show general device information settings (serial number, softwareversion, phone number, etc.).
StringACTION_DISPLAY_SETTINGS
显示设置,以允许配置显示 ActivityAction: Show settings to allow configuration ofdisplay.
StringACTION_INPUT_METHOD_SETTINGS
特别配置的输入方法,允许用户启用输入法的显示设置Activity Action: Show settings to configure input methods, inparticular allowing the user to enable inputmethods.
StringACTION_INPUT_METHOD_SUBTYPE_SETTINGS
显示设置来启用/禁用输入法亚型 ActivityAction: Show settings to enable/disable input methodsubtypes.
StringACTION_INTERNAL_STORAGE_SETTINGS
内部存储的显示设置 ActivityAction: Show settings for internal storage.
StringACTION_LOCALE_SETTINGS
显示设置,以允许配置的语言环境 ActivityAction: Show settings to allow configuration oflocale.
StringACTION_LOCATION_SOURCE_SETTINGS
显示设置,以允许当前位置源的配置 ActivityAction: Show settings to allow configuration of current locationsources.
StringACTION_MANAGE_ALL_APPLICATIONS_SETTINGS
显示设置来管理所有的应用程序 ActivityAction: Show settings to manage allapplications.
StringACTION_MANAGE_APPLICATIONS_SETTINGS
显示设置来管理安装的应用程序 ActivityAction: Show settings to manage installedapplications.
StringACTION_MEMORY_CARD_SETTINGS
显示设置为存储卡存储 ActivityAction: Show settings for memory card storage.
StringACTION_NETWORK_OPERATOR_SETTINGS
选择网络运营商的显示设置 ActivityAction: Show settings for selecting the networkoperator.
StringACTION_PRIVACY_SETTINGS
显示设置,以允许配置隐私选项 ActivityAction: Show settings to allow configuration of privacyoptions.
StringACTION_QUICK_LAUNCH_SETTINGS
显示设置,以允许快速启动快捷键的配置Activity Action: Show settings to allow configuration of quicklaunch shortcuts.
StringACTION_SEARCH_SETTINGS
全局搜索显示设置 Activity Action:Show settings for global search.
StringACTION_SECURITY_SETTINGS
显示设置,以允许配置的安全性和位置隐私Activity Action: Show settings to allow configuration of securityand location privacy.
StringACTION_SETTINGS
显示系统设置 Activity Action:Show system settings.
StringACTION_SOUND_SETTINGS
显示设置,以允许配置声音和音量 ActivityAction: Show settings to allow configuration of sound andvolume.
StringACTION_SYNC_SETTINGS
显示设置,以允许配置同步设置 ActivityAction: Show settings to allow configuration of syncsettings.
StringACTION_USER_DICTIONARY_SETTINGS
显示设置来管理用户输入字典 ActivityAction: Show settings to manage the user inputdictionary.
StringACTION_WIFI_IP_SETTINGS
显示设置,以允许配置一个静态IP地址的Wi –Fi Activity Action: Show settings to allow configuration of astatic IP address for Wi-Fi.
StringACTION_WIFI_SETTINGS
显示设置,以允许Wi – Fi配置Activity Action: Show settings to allow configuration ofWi-Fi.
StringACTION_WIRELESS_SETTINGS
显示设置,以允许配置,如Wi –Fi,蓝牙和移动网络的无线控制 Activity Action: Show settings to allowconfiguration of wireless controls such as Wi-Fi, Bluetooth andMobile networks.
StringAUTHORITY 
StringEXTRA_AUTHORITIES
在推出活动的基础上给予的权力限制可选项。Activity Extra: Limit available options in launched activity basedon the given authority.
StringEXTRA_INPUT_METHOD_ID
0 0
原创粉丝点击