이것은 맞춤식 박수 갈채 플러그인입니다. 이 응용 프로그램은이 directlly 응용 프로그램 코드
AppChecker이 서비스를 시작하는 버튼 클릭에
귀하의 index.js
개방 PLAYSTORE
이상인 경우 시작 설치 될 때 작동합니다. appcheker가 조치입니다.
com.outfit7.mytalkingtomfree
은 실행할 앱의 패키지 이름입니다.
$(".appopenclass").on("click",function() {
cordova.exec(function(winParam) {},
function(error) {
utils.setAlertMsg("Plugin failed " + error);
},
"AppChecker",
"appchecker",
["com.outfit7.mytalkingtomfree"]);
});
프로젝트 -> RES-> XML-> config.xml에
<feature name="AppChecker">
<param name="android-package" value="com.appview.openapp.AppChecker" />
</feature>
이름 com.appview.openapp
같은 하나 개의 패키지를 만들고 AppChecker.java
같은 새로운 클래스 이름을 만들 AppChecker.Java
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.util.Log;
public class AppChecker extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray args,
CallbackContext callbackContext) throws JSONException {
if (action.equals("appchecker")) {
String message = args.getString(0);
this.appchecker(message, callbackContext);
return true;
}
return false;
}
private void appchecker(final String message, CallbackContext callbackContext) {
if (message != null && message.length() > 0) {
// callbackContext.success(message);
Log.i("test", "" + message);
// appInstalledOrNot(message);
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
boolean installed = appInstalledOrNot(message);
if (installed) {
// This intent will help you to launch if the package is already
// installed
Intent LaunchIntent = cordova.getActivity().getPackageManager()
.getLaunchIntentForPackage(message);
cordova.getActivity().startActivity(LaunchIntent);
System.out.println("App already installed on your phone");
} else {
System.out.println("App is not installed on your phone");
try {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + message));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
cordova.getActivity().startActivity(i);
} catch (android.content.ActivityNotFoundException anfe) {
}
}
}
});
} else {
callbackContext.error("Expected one non-empty string argument.");
}
}
private boolean appInstalledOrNot(String uri) {
PackageManager pm = cordova.getActivity().getPackageManager();
boolean app_installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
} catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
}
phonegap 빌드 또는 CLI를 사용하고 있습니까? – QuickFix
내가 phonegap 빌드를 사용하고 있습니다 – Sdog