안녕하세요
특정 app가 스마트폰에 설치가 되어있는지 알 수 있는 방법이 있나요???
예를들어 abcd 라는 앱이 있을때 그 앱이 제 스마트폰에 설치가 되어있으면 설치되었다는 Toast를 띄우고 설치가 안되어있으면 해당 앱스토어 url로 보낼려고 합니다.
이럴땐 어떻게 하나요???
답변 많이 부탁드리겠습니다..
java
package loss.prevention;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.widget.TextView;
public class APP_Admin extends Activity{
String pl;
String pl2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.app_admin);
// PackageManager 검색
PackageManager pm = this.getPackageManager();
TextView textView1 = (TextView)findViewById(R.id.textView1);
pl = "설치된 목록\n";
// 설치된 프로그램 목록을 가져
List <ApplicationInfo> list = pm.getInstalledApplications (0);
for (ApplicationInfo ai : list) {
// Toast.makeText(APP_Admin.this, "PackageManagerTest" + ai.packageName, Toast.LENGTH_SHORT).show();
pl += ai.packageName+"\n";
}
textView1.setText(pl);
TextView textView2 = (TextView)findViewById(R.id.textView2);
// 특정 패키지가 설치되어 있는지 확인
try {
ApplicationInfo ai = pm.getApplicationInfo ("loss.prevention", 0);
// Toast.makeText(APP_Admin.this, "PackageManagerTest" + "com.android.browser is found", Toast.LENGTH_SHORT).show();
textView2.setText("loss.prevention is found");
} catch (NameNotFoundException e) {
// Toast.makeText(APP_Admin.this, "PackageManagerTest" + "com.android.browser is not found", Toast.LENGTH_SHORT).show();
textView2.setText("loss.prevention is not found");
}
Intent intent = pm.getLaunchIntentForPackage("com.dgo.VitalPlayer");
startActivity(intent);
}
}
xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
</ScrollView>
</LinearLayout>




}