activity call

http://www.suppul.com/blog/main/177?category=3&TSSESSIONwwwsuppulcomblog=3d3040b04cd0d91775dca7e52dda23e7



Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(android.net.Uri.parse("http://url"))
startActivity(intent);

Intent intent = new Intent();   
intent.setAction(android.content.Intent.ACTION_VIEW);   
File file = new File("/sdcard/test.mp4");   
intent.setDataAndType(Uri.fromFile(file), "video/*");   
startActivity(intent);    

Intent intent = new Intent();   
intent.setAction(android.content.Intent.ACTION_VIEW);   
File file = new File("/sdcard/test.mp3");   
intent.setDataAndType(Uri.fromFile(file), "audio/*");   
startActivity(intent); 

Intent intent = new Intent(Intent.ACTION_VIEW);
File file = new File(filePath);   
intent.setDataAndType(Uri.fromFile(file), "*/*");//
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);


특종!!
어플 설치 할수있는 코드

출처: http://www.androidpub.com/20857
출처: http://dingpong.net/tt/category/Programming/Android?page=3



방법1



public class APKInstall extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
File apkFile = new File("/sdcard/FileBrowser.apk");
Uri apkUri = Uri.fromFile(apkFile);
Log.i("APKInstall", "Set apk path");

try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType( Uri.fromFile(apkFile), "application/vnd.android.package-archive");
startActivity(intent);
Log.i("APKInstall", "APK installed");
} catch (Exception e) {
// TODO: handle exception
Log.i("APKInstall", e.getMessage());
}

//        PackageManager pm = getPackageManager();
//        pm.installPackage(apkUri);
}
}




방법2


packages/apps/PackageInstaller/src/com/android/packageinstaller/InstallAppProgress.java

if((installFlags & PackageManager.REPLACE_EXISTING_PACKAGE )!= 0) {
Log.w(TAG, "Replacing package:"+mAppInfo.packageName);
}
PackageInstallObserver observer = new PackageInstallObserver();
pm.installPackage(mPackageURI, observer, installFlags);



방법3


File apkFile = new File("/sdcard/ApkTest.apk");
Uri apkUri = Uri.fromFile(apkFile);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType( Uri.fromFile(apkFile), "application/vnd.android.package-archive");
startActivity(intent);



안드로이드 인텐트로 Activity기동 ?? - 점검해볼것
Under the system Intent Daquan android
Android 2010-01-06 17:27:34 Read 67 Comments 0 Adjust Font Size:

1. From the google search content

Intent intent = new Intent ();
intent.setAction (Intent.ACT ION_WEB_SEARCH);
intent.putExtra (SearchManager.QUERY, "searchString")
startActivity (intent);

2. Browse the Web

Uri uri = Uri.parse ( "http://www.google.com");
Intent it = new Intent (Intent.ACT ION_VIEW, uri);
startActivity (it);

3. Show map
Uri uri = Uri.parse ( "geo: 38.899533, -77.036476");
Intent it = new Intent (Intent.Act ion_VIEW, uri);
startActivity (it);

4. Path planning

Uri uri = Uri.parse ( "http://maps.google.com/maps?f=dsaddr=startLat% 20startLng & daddr = endLat% 20endLng & hl = en");
Intent it = new Intent (Intent.ACT ION_VIEW, URI);
startActivity (it);


5. Call

Uri uri = Uri.parse ( "tel: xxxxxx");
Intent it = new Intent (Intent.ACT ION_DIAL, uri);
startActivity (it);

6. Call texting program
Intent it = new Intent (Intent.ACT ION_VIEW);
it.putExtra ( "sms_body", "The SMS text");
it.setType ( "vnd.android-dir/mms-sms");
startActivity (it);

7. Send SMS
Uri uri = Uri.parse ( "smsto: 0800000123");
Intent it = new Intent (Intent.ACT ION_SENDTO, uri);
it.putExtra ( "sms_body", "The SMS text");
startActivity (it); 

//2nd?
String body = "this is sms demo";
Intent mmsintent = new Intent (Intent.ACT ION_SENDTO, Uri.fromParts ( "smsto", number, null));
mmsintent.putExtra (Messaging.KEY_ACT ION_SENDTO_MESSAGE_BODY, body);
mmsintent.putExtra (Messaging.KEY_ACT ION_SENDTO_COMPOSE_MODE, true);
mmsintent.putExtra (Messaging.KEY_ACT ION_SENDTO_EXIT_ON_SENT, true);
startActivity (mmsintent);

8. Send MMS
Uri uri = Uri.parse ( "content: / / media/external/images/media/23");
Intent it = new Intent (Intent.ACTION_SEND);
it.putExtra ( "sms_body", "some text");
it.putExtra (Intent.EXTRA_STREAM, uri);
it.setType ( "image / png");
startActivity (it); 

// 2nd ????


StringBuilder sb = new StringBuilder ();
sb.append ( "file ://");
sb.append (fd.getAbsoluteFile ());
Intent intent = new Intent (Intent.ACT ION_SENDTO, Uri.fromParts ( "mmsto", number, null));
/ / Below extra datas are all optional.
intent.putExtra (Messaging.KEY_ACT ION_SENDTO_MESSAGE_SUBJECT, subject);
intent.putExtra (Messaging.KEY_ACT ION_SENDTO_MESSAGE_BODY, body);
intent.putExtra (Messaging.KEY_ACT ION_SENDTO_CONTENT_URI, sb.toString ());
intent.putExtra (Messaging.KEY_ACT ION_SENDTO_COMPOSE_MODE, composeMode);
intent.putExtra (Messaging.KEY_ACT ION_SENDTO_EXIT_ON_SENT, exitOnSent);
startActivity (intent);

-->되는지 조금 바꾸어야 함
Uri mmsUri = Uri.parse("mmsto:");
Intent sendIntent = new Intent(Intent.ACTION_VIEW, mmsUri );  
sendIntent.addCategory("android.intent.category.DEFAULT");
sendIntent.addCategory("android.intent.category.BROWSABLE");

sendIntent.putExtra("address", destinationAddress);
sendIntent.putExtra("exit_on_sent", true);
sendIntent.putExtra("subject", subject);
sendIntent.putExtra("sms_body", body);
Uri dataUri = Uri.parse("content://media/external/images/media/1");
sendIntent.putExtra(Intent.EXTRA_STREAM, dataUri);

getContext().startActivity(sendIntent);

9. Send Email

Uri uri = Uri.parse ( "mailto: xxx@abc.com");
Intent it = new Intent (Intent.ACT ION_SENDTO, uri);
startActivity (it); 

Intent it = new Intent (Intent.ACT ION_SEND);
it.putExtra (Intent.EXTRA_EMAIL, "me@abc.com");  //????
it.putExtra (Intent.EXTRA_TEXT, "The email body text");
it.setType ( "text / plain");
startActivity (Intent.createChooser (it, "Choose Email Client")); 


String[] mailto = { "a@a.com" };
sendIntent.putExtra(Intent.EXTRA_EMAIL, mailto); // <- 맞음


Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "subject");
sendIntent.setType("text/csv");
sendIntent.putExtra(Intent.EXTRA_EMAIL, "test@gmail.com"); //??????
sendIntent.putExtra(Intent.EXTRA_TEXT, body);
act.startActivity(Intent.createChooser(sendIntent, "Send email"));


// 3

Intent it = new Intent (Intent.ACT ION_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 body text");
it.putExtra (Intent.EXTRA_SUBJECT, "The email subject text");
it.setType ( "message/rfc822");
startActivity (Intent.createChooser (it, "Choose Email Client"));

// 4
Intent it = new Intent (Intent.ACT ION_SEND);
it.putExtra (Intent.EXTRA_SUBJECT, "The email subject text");
it.putExtra (Intent.EXTRA_STREAM, "file: / / / sdcard/mysong.mp3");
sendIntent.setType ( "audio/mp3");
startActivity (Intent.createChooser (it, "Choose Email Client"));

10. Play Media

Intent it = new Intent (Intent.ACT ION_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 = new Intent (Intent.ACT ION_VIEW, uri);
startActivity (it);

11.uninstall apk

Uri uri = Uri.fromParts ( "package", strPackageName, null);
Intent it = new Intent (Intent.ACT ION_DELETE, uri);
startActivity (it);

12.install apk
Uri installUri = Uri.fromParts ( "package", "xxx", null);
returnIt = new Intent (Intent.ACT ION_PACKAGE_ADDED, installUri); 


-----

메일 추가

private void sendEmail(String[] address, String subject, String msg) { 
Intent send = new Intent(Intent.ACTION_SEND); 
send.putExtra(Intent.EXTRA_EMAIL, address); 
send.putExtra(Intent.EXTRA_SUBJECT, subject); 
send.putExtra(Intent.EXTRA_TEXT, msg); 
send.setType("text/plain"); 
startActivity(Intent.createChooser(send, "MySendMail")); 
}


---


Intent msg=new Intent(Intent.ACTION_SEND); 
msg.putExtra(Intent.EXTRA_EMAIL ,"testto@test.net"); 
msg.putExtra(Intent.EXTRA_SUBJECT, "Here is the subject for the email"); 
//this next line adds an attachment, but I'm having some issues with the file location 
msg.putExtra(Intent.EXTRA_STREAM, Uri.parse ("file://" + Environment.getExternalStorageDirectory() + "test.txt")); 
msg.putExtra(Intent.EXTRA_BCC, "testbcc@test.net"); 
msg.putExtra(Intent.EXTRA_CC, "testcc@test.net"); 
//This next line puts in the body of the message 
msg.putExtra(Intent.EXTRA_TEXT,"Attached is your file "); 
msg.setType("text/csv"); 
//Another type to try 
//msg.setType("message/rfc822");  
startActivity(Intent.createChooser(msg, "Send Email"));

댓글

이 블로그의 인기 게시물

유니티 오브젝트 서서히 사라지게

WebView에서 YOUTUBE 동영상 플레이 방법