Mendayagunakan Activity External Pemrograman Bergerak Mendayagunakan Activity External 1
Pengaktifan Activity secara Implicit Pengaktifan Activity secara Implicit memungkinkan kita untuk mendayagunakan Activity yang sudah tersedia pada aplikasi bawaan di Android maupun aplikasi- aplikasi yang memiliki intent-filter pada saat deklarasi Activity tersebut pada AndroidManifest. Scara umum untuk mendayagunakan Activity bawaan di Android: 1. Menggunakan Permisi pada AndroidManifest.xml 2, Mengirim intent dan uri ataupun data tambahan lainnya.
Melakukan Call Intent intent= new Intent(Intent.ACTION_CALL,Uri.parse("tel:+81533113285")); startActivity(intent); Anda perlu menggunakan CALL_PHONE permission pada AndroidManifest.XML <uses-permission android:name= "android.permission.CALL_PHONE"> </uses-permission>
Menampilkan Website Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")); startActivity(intent); Anda perlu menggunakan INTERNET permission pada AndroidManifest.xml <uses-permission android:name= "android.permission.INTERNET"> </uses-permission>
Mengirim Email Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("plain/text"); intent.putExtra(Intent.EXTRA_EMAIL,new String[]{"hendra.soewarno@gmail.com"}); intent.putExtra(Intent.EXTRA_SUBJECT,"Hello World"); intent.putExtra(Intent.EXTRA_TEXT,"Selamat Pagi"); startActivity(Intent.createChooser(intent, "Send mail...")); Anda perlu menggunakan INTERNET permission pada AndroidManifest.xml <uses-permission android:name= "android.permission.INTERNET"> </uses-permission>
Mengirim SMS Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("sms:+81533113285")); intent.putExtra("sms_body","hello world"); startActivity(intent); Anda perlu menggunakan SEND_SMS permission pada AndroidManifest,XML <uses-permission android:name= "android.permission.SEND_SMS"> </uses-permission>
Mengaktifkan Google Map Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=medan")); StartActivity(intent); Mengaktifkan Google Map IBBI Kampus Topaz Uri.parse("geo:3.59865,98.664441?z=19"));
Mengaktifkan Camera dan Capture private static final int CAMERA_PIC_REQUEST = 1337; @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.main); Button buttonCapture = (Button) findViewById(R.id.buttonCapture); buttonCapture.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(intent, CAMERA_PIC_REQUEST); } }); public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK && requestCode == CAMERA_PIC_REQUEST) { Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); ImageView image = (ImageView) findViewById(R.id.imagePhotoResultView); image.setImageBitmap(thumbnail); Permission yang diperlukan <uses-permission android:name="android.permission.CAMERA" /> <uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera.autofocus" />
Mengambil Posisi Permission <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission> // Acquire a reference to the system Location Manager LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); Criteria c=new Criteria(); String provider=locationManager.getBestProvider(c, false); Location location=locationManager.getLastKnownLocation(provider); makeUseOfNewLocation(location); private void makeUseOfNewLocation(Location location) { tampilToast("ada2"); Double longitude = location.getLongitude(); Double latitude = location.getLatitude(); TextView textLat = (TextView) findViewById(R.id.textLat); TextView textLong = (TextView) findViewById(R.id.textLong); textLat.setText(longitude.toString()); textLong.setText(latitude.toString()); }
Sekian & Terima Kasih 10