隱式Intent

隱式Intent在Activity中調用Activityandroid

    //web瀏覽器
    Uri uri= Uri.parse("http://www.baidu.com:8080/image/a.jpg");
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    startActivity(intent);
    
    //地圖(要在 Android 手機上才能測試)
    Uri uri = Uri.parse("geo:38.899533,-77.036476");
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    startActivity(intent);
    
    //路徑規劃
    Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
    Intent it = new Intent(Intent.ACTION_VIEW, uri);
    startActivity(it);
    
    //撥打電話-調用撥號程序,這個用戶體驗要比下面的那個要好一些
    Uri uri = Uri.parse("tel:15980665805");
    Intent intent = new Intent(Intent.ACTION_DIAL, uri);
    startActivity(intent);
    
    //撥打電話-直接撥打電話
    //要使用這個必須在配置文件中加入<uses-permission android:name="android.permission.CALL_PHONE"/>
    Uri uri = Uri.parse("tel:15980665805");
    Intent intent = new Intent(Intent.ACTION_CALL, uri);
    startActivity(intent);
 
    //調用發送短信程序(方法一)
    Uri uri = Uri.parse("smsto:15980665805");
    Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
    intent.putExtra("sms_body", "The SMS text");
    startActivity(intent);
    
    //調用發送短信程序(方法二)
    Intent intent = new Intent(Intent.ACTION_VIEW);     
    intent.putExtra("sms_body", "The SMS text");     
    intent.setType("vnd.android-dir/mms-sms");     
    startActivity(intent);
    
    //發送彩信
    Uri uri = Uri.parse("content://media/external/images/media/23");
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra("sms_body", "some text");
    intent.putExtra(Intent.EXTRA_STREAM, uri);
    intent.setType("image/png");
    startActivity(intent);
    
    //發送Email(方法一)(要在 Android 手機上才能測試)
    Uri uri = Uri.parse("mailto:zhangsan@gmail.com");
    Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
    startActivity(intent);
    
    //發送Email(方法二)(要在 Android 手機上才能測試)
    Intent intent = new Intent(Intent.ACTION_SENDTO);  
    intent.setData(Uri.parse("mailto:zhangsan@gmail.com"));  
    intent.putExtra(Intent.EXTRA_SUBJECT, "這是標題");  
    intent.putExtra(Intent.EXTRA_TEXT, "這是內容");  
    startActivity(intent); 
    
    //發送Email(方法三)(要在 Android 手機上才能測試)
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");
    intent.putExtra(Intent.EXTRA_SUBJECT, "這是標題");  
    intent.putExtra(Intent.EXTRA_TEXT, "這是內容");
    intent.setType("text/plain");
    //選擇一個郵件客戶端
    startActivity(Intent.createChooser(intent, "Choose Email Client"));  
    
    //發送Email(方法四)(要在 Android 手機上才能測試)
    Intent intent = new Intent(Intent.ACTION_SEND);
    //收件人
    String[] tos = {"to1@abc.com", "to2@abc.com"};
    //抄送人
    String[] ccs = {"cc1@abc.com", "cc2@abc.com"};
    //密送人
    String[] bcc = {"bcc1@abc.com", "bcc2@abc.com"};
    intent.putExtra(Intent.EXTRA_EMAIL, tos);    
    intent.putExtra(Intent.EXTRA_CC, ccs);
    intent.putExtra(Intent.EXTRA_BCC, bcc);
    intent.putExtra(Intent.EXTRA_SUBJECT, "這是標題"); 
    intent.putExtra(Intent.EXTRA_TEXT, "這是內容");    
    intent.setType("message/rfc822");    
    startActivity(Intent.createChooser(intent, "Choose Email Client"));
    
    //發送Email且發送附件(要在 Android 手機上才能測試)
    Intent intent = new Intent(Intent.ACTION_SEND);    
    intent.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");    
    intent.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mp3/醉紅顏.mp3");    
    intent.setType("audio/mp3");    
    startActivity(Intent.createChooser(intent, "Choose Email Client"));
    
    //播放媒體文件(android 對中文名的文件支持很差)
    Intent intent = new Intent(Intent.ACTION_VIEW);
    //Uri uri = Uri.parse("file:///sdcard/zhy.mp3");
    Uri uri = Uri.parse("file:///sdcard/a.mp3"); 
    intent.setDataAndType(uri, "audio/mp3"); 
    startActivity(intent);
    
    Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");     
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);     
    startActivity(intent); 
    
    //音樂選擇器
    //它使用了Intent.ACTION_GET_CONTENT 和 MIME 類型來查找支持 audio/* 的全部 Data Picker,容許用戶選擇其中之一
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
    intent.setType("audio/*");
    //Intent.createChooser:應用選擇器,這個方法建立一個 ACTION_CHOOSER Intent
    startActivity(Intent.createChooser(intent, "選擇音樂"));
    
    Intent intent1 = new Intent(Intent.ACTION_GET_CONTENT); 
    intent1.setType("audio/*");
    
    Intent intent2 = new Intent(Intent.ACTION_CHOOSER);
    intent2.putExtra(Intent.EXTRA_INTENT, intent1);
    intent2.putExtra(Intent.EXTRA_TITLE, "aaaa");
    startActivity(intent2);
    
    
//                //設置壁紙
//                Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);  
//                startActivity(Intent.createChooser(intent, "設置壁紙"));  
    
    //卸載APK
    //fromParts方法
    //參數1:URI 的 scheme
    //參數2:包路徑
    //參數3:
    Uri uri = Uri.fromParts("package", "com.great.activity_intent", null);    
    Intent intent = new Intent(Intent.ACTION_DELETE, uri);     
    startActivity(intent);
    
    //安裝APK(???)
    Uri uri = Uri.fromParts("package", "com.great.activity_intent", null);  
    Intent intent = new Intent(Intent.ACTION_PACKAGE_ADDED, uri);
    startActivity(intent);
    
    //調用搜索
    Intent intent = new Intent();  
    intent.setAction(Intent.ACTION_WEB_SEARCH);  
    intent.putExtra(SearchManager.QUERY, "android");  
    startActivity(intent);

若是你不知道那個APP的Activity,可是知道包名(package name),那麼能夠使用以下的方法:web

Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");  
startActivity(LaunchIntent);  

若是APP之間有合做關係,能夠得到合做APP的清單文件(manifest),那麼能夠從該文件中獲知package/activity, 
可以使用以下的方法來啓動該APP特定活動界面:瀏覽器

Intent intent = new Intent(Intent.ACTION_MAIN);  
intent.setComponent(new ComponentName("com.package.address","com.package.address.MainActivity"));  
startActivity(intent);  

若是要在啓動APP時傳遞參數,能夠在乎圖(Intent)中設置:測試

intent.putExtra("firstKeyName","FirstKeyValue");  
intent.putExtra("secondKeyName","SecondKeyValue"); 
相關文章
相關標籤/搜索