기본 콘텐츠로 건너뛰기

[안드로이드] 외부 앱 실행 파라메터 주기

설치 여부 확인하기

public boolean getPackageList() {
    boolean isExist = false;

    PackageManager pkgMgr = getPackageManager();
    List mApps;
    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    mApps = pkgMgr.queryIntentActivities(mainIntent, 0);

    try {
        for (int i = 0; i < mApps.size(); i++) {
            if(mApps.get(i).activityInfo.packageName.startsWith("com.kor.app")){
                isExist = true;
                break;
            }
        }
    }
    catch (Exception e) {
        isExist = false;
    }
    return isExist;
}


외부 실행
Intent intent = getPackageManager().getLaunchIntentForPackage("com.kor.app");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//파라메터 넣기
intent.putExtra("my_text", "This is my text to send.");
startActivity(intent);


앱이 설치되어 있지 않다면 앱스토어로 이동합니다.

String url = "market://details?id=" + "com.kor.apptest";
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(i);

댓글

이 블로그의 인기 게시물

java 특정 디렉토리에 있는 파일 목록을 읽어내기, 정렬해서 가져오기

폴더 리스트 가져오기 String path="C:\"; File dirFile=new File(path); File []fileList=dirFile.listFiles(); for(File tempFile : fileList) {   if(tempFile.isFile()) {     String tempPath=tempFile.getParent();     String tempFileName=tempFile.getName();     System.out.println("Path="+tempPath);     System.out.println("FileName="+tempFileName);     /*** Do something withd tempPath and temp FileName ^^; ***/   } } 정렬해서 가져오기 import java.io.FileFilter; import java.io.IOException; import java.util.Arrays; import java.util.Date; import org.apache.commons.io.comparator.LastModifiedFileComparator; import org.apache.commons.io.filefilter.FileFileFilter; public class LastModifiedFileComparatorTest { public static void main(String[] args) throws IOException { File directory = new File("."); // get just files, not directories File[] files = directory.listFiles((FileFilter) FileFileFilter.FILE); System.out.println("Defaul...

dmesg 메시지 실시간으로 보기

참조사이트 http://imitator.kr/Linux/556 # tail -f /var/log/messages # tail -f |dmesg //기본 2초 단위로 갱신 된다. # watch "dmesg | tail -f" //1초 단위로 갱신하면서 보여준다. # watch -n 1 "dmesg | tail -f" // 보여주는 줄을 20으로 늘린다. (기본 10줄) # watch -n 1 "dmesg | tail -f -n 20"