Androidで他のアプリとの連携するのに、Intent を使います。
せっかくなので、引用と自分が以前調べた物を貼り付けておきます。
ブラウザ起動
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")); startActivity(i);
ダイアラー起動
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("tel:177")); startActivity(i);
通話開始
Uri uri=Uri.parse("tel:117"); Intent intent=new Intent(Intent.ACTION_CALL,uri); startActivity(intent)
その際、通話には、以下が必要か
<uses-permission android:name="android.permission.CALL_PHONE"/>
SMS送信
Uri smsUri = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, smsUri); intent.setType("vnd.android-dir/mms-sms"); startActivity(intent);
地図起動(Google Maps)
Uri mapUri = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, mapUri); startActivity(intent);
経路検索
Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity"); intent.setData(Uri.parse("http://maps.google.com/maps?myl=saddr&daddr=&dirflg=d")); startActivity(intent);
メール起動
Uri uri =Uri.parse("mailto:xxx@example.com"); Intent it = newIntent(Intent.ACTION_SENDTO, uri); startActivity(it);
複数の宛先へメール
Intent it=new Intent(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, "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"));
MP3の再生
Intent it = new Intent(Intent.ACTION_VIEW); Uri uri =Uri.parse("file:///sdcard/song.mp3"); it.setDataAndType(uri,"audio/mp3"); startActivity(it);
APKファイルのアンインストール
Uri uri =Uri.fromParts("package", strPackageName, null); Intent it = newIntent(Intent.ACTION_DELETE, uri); startActivity(it);
APKファイルのインストール
Uri installUri = Uri.fromParts("package","xxx", null); returnIt = newIntent(Intent.ACTION_PACKAGE_ADDED, installUri);
ギャラリーから写真を選択
Intent i = new Intent(); i.setType("image/*"); i.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(i, 11);