Android > ÀÎÅÙÆ®(Intent) - ±âº» ±â´Éµé
µî·ÏÀÏ : 2017-07-05 11:28
Á¶È¸¼ö : 53,277
1. URI(Uniform Resource Identifier)
: ÀÎÅÙÆ® ÀÚ·á¿¡¼ »ç¿ëÇÏ´Â URI´Â ÀÚ¹Ù¿¡¼ Á¦°øÇÏ´Â URI Ŭ·¡½º¿Í ¾Èµå·ÎÀÌµå ³»ºÎ¿¡¼ »ç¿ëÇÏ´Â URI Ŭ·¡½º·Î Á¦°øÇÑ´Ù.
Áï, ÀÚ¹Ù¿¡¼ Á¦°øÇÏ´Â URI Ŭ·¡½º´Â ÀϹÝÀûÀÎ ÀÎÅͳÝÀ̳ª À¥ »çÀÌÆ®¸¦ ÁöĪÇÒ ¶§ »ç¿ëÇϸç, URI Ŭ·¡½º´Â ¾Èµå·ÎÀÌµå ³»ºÎ ÀڷḦ
°¡¸®Å°°Å³ª ¶Ç´Â ÄÜÅÙÆ®ÇÁ·Î¹ÙÀÌ´õ¿Í °°Àº ÄÄÆ÷³ÍÆ®¿¡¼ »ç¿ëÇϴ Ŭ·¡½ºÀÌ´Ù.
2. [scheme:][//±â°ü][°æ·Î][?Äõ¸®][#fragment]
- ½ºÅ´(schema) : ÇÁ·ÎÅäÄÝÀº Åë½Å»ó¿¡¼ »ç¿ëÇÏ´Â ¿ë¾îÀÌ°í URI ¿¡¼´Â 'http', 'content', ±×¸®°í 'tel' µî°ú °°Àº ÇÁ·ÎÅäÄÝÀ» ½ºÅ´(Scheme)À̶ó ºÎ¸¥´Ù.
- ±â°ü(Authority) : ±â°üÀº ´Ù¸¥ ÀڷḦ ±¸ºÐÇϱâ À§ÇØ »ç¿ëÇÑ´Ù. content ½ºÅ´À» »ç¿ëÇÏ´Â °æ¿ì °Á¦ ±ÔÁ¤Àº ¾Æ´ÏÁö¸¸
'com.android.example'¿Í °°ÀÌ ÀÚ¹Ù °íÀ¯ ÆÐÅ°Áö À̸§À» »ç¿ëÇÑ´Ù. º¸´Ù ÀϹÝÀûÀÎ http´Â ÀÎÅÍ³Ý ÁÖ¼Ò ±ÔÁ¤¿¡ µû¶ó 'www.google.com'À¸·Î Ç¥±âÇÏ°Ô µÈ´Ù.
- °æ·Î(PATH) : ±¸Ã¼ÀûÀÎ ÀÚ·áÀÇ À§Ä¡¸¦ ³ªÅ¸³½´Ù.
- Äõ¸®(Query) : ¹°À½Ç¥('?') µÚ¿¡ À§Ä¡ÇÏ¿© Ãß°¡ÀûÀÎ ÀÚ·áÀÇ °Ë»öÀ» ¿ä±¸ÇÑ´Ù.
- ÇÁ·¹±×¸ÕÆ®(fragment) : ÀڷḦ ºÐ·ùÇÑ »öÀÎÀÌ´Ù.
¾Èµå·ÎÀÌµå ¾×ƼºñƼ¸Å´ÏÀú´Â ÀÎÅÙÆ®¿Í ÇÔ²² ÀÚ·á ŸÀÔÀ» ±âÁØÀ¸·Î Àü´ÞÇÒ ÄÄÆ÷³ÍÆ®¸¦ ¼±Á¤ÇÏ°Ô µÈ´Ù.
´ëºÎºÐ URI¸¦ º¸°í ÃßÃøÇÒ ¼ö ÀÖÁö¸¸ °¡²û URI¸¦ º¸°í ÃßÃøÇÒ ¼ö ÀÖÁö¸¸ °¡²û URI¸¸À¸·Î ÆÇ´ÜÇϱ⠾î·Á¿î °æ¿ì,
Ãß°¡ÀûÀÎ Á¤º¸·Î ÀÚ·á ŸÀÔ(MIME ŸÀÔ)À» ÂüÁ¶ÇÑ´Ù.
- setData() ¸Þ¼µå´Â URI¸¸ »ç¿ëÇؼ ÀڷḦ ÁöÁ¤Çϸç, getData()¿¡ ÀÇÇØ ÀÐÇôÁö°Ô µÈ´Ù.
- setType()Àº MIME ŸÀÔÀ» ÁöÁ¤Çϸç, getType()¿¡ ÀÇÇØ Àд´Ù.
- setDataAndType()Àº URI¿Í MIME ŸÀÔ ¸ðµÎ ´Ù ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.
¾Æ·¡´Â ¾Èµå·ÎÀÌµå ¸Å´ÏÆ佺Ʈ¿¡¼ »ç¿ëÇÏ´Â MIME ŸÀÔÀÇ ¿¹ÀÌ´Ù. ÇÏÀ§Å¸ÀÔ Çʵå´Â '*'¿Í °°ÀÌ ¿ÍÀϵåÄ«µå¸¦ »ç¿ëÇÒ ¼ö ÀÖ´Ù.
data android:scheme="file"
data android:scheme="content"
data android:mimeType="text/html"
data android:mimeType="text/plain"
data android:mimeType="audio/*"
data android:mimeType="video/*"
data android:mimeType="image/*"
data android:mimeType="application/vnd.android.package-archive"
data android:mimeType="text/xml"
data android:mimeType="application/zip"
data android:mimeType="image/tiff" /<
data android:mimeType="application/rtf"
data android:mimeType="application/excel"
data android:mimeType="application/msword"
data android:mimeType="video/mpeg" android:scheme="http"
public class MainActivity extends Activity {
public static final String DEBUG_TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button goButton = (Button)findViewById(R.id.go);
goButton.setOnClickListener(mGoListener);
}
private final OnClickListener mGoListener = new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("audio/*");
try {
startActivity(Intent.createChooser(intent, "select music"));
} catch (ActivityNotFoundException e) {
// TODO: handle exception
Log.e(DEBUG_TAG, "ActivityNotFoundException !!!");
}
}
};
}
// À¥ºê¶ó¿ìÀú¸¦ »ç¿ëÇÏ¿© À¥»çÀÌÆ®¸¦ È£ÃâÇÏ´Â ¹æ¹ý
Intent result = null;
Uri cafeUri = Uri.parse("http://www.google.com");
result = new Intent(Intent.ACTION_VIEW, cafeUri);
// Google map È£ÃâÇÏ´Â ¹æ¹ý
Uri mapUri = Uri.parse("geo:45.5,-5,5");
result = new Intent(Intent.ACTION_VIEW, mapUri);
// ÀüÈ °É±â ¹æ¹ý
Uri telUri = Uri.parse("tel:01066542126");
result = new Intent(Intent.ACTION_DIAL, telUri);
// ÆÐÅ°Áö ¼³Ä¡ ÀÛ¾÷
Uri packageUri = Uri.fromParts("package", "xxx", null);
result = new Intent(Intent.ACTION_PACKAGE_ADDED, packageUri);
result = new Intent(Intent.ACTION_DELETE, packageUri);
// À½¾Ç È£Ãâ
Uri playUri = Uri.parse("file://sdcard/download/everything.mp3");
result = new Intent(Intent.ACTION_VIEW, playUri);
// À̸ÞÀÏ Àü¼Û
Uri emailUri = Uri.parse("maito:root@gmail.com");
result = new Intent(Intent.ACTION_SENDTO, emailUri);