Skip to content

Commit

Permalink
add 'hasPackageInstalled' for android
Browse files Browse the repository at this point in the history
  • Loading branch information
mateo-kozomara committed May 2, 2022
1 parent d26d178 commit 0afb2d3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,17 @@ import com.freshplanet.ane.AirCapabilities.events.AirCapabilitiesOpenURLEvent;
_extContext.call("switchToPortrait");
}

/**
* Android only!
*/
public function hasPackageInstalled(packageName:String):Boolean
{
if(Capabilities.manufacturer.indexOf("Android") < 0)
return false;

return _extContext.call("hasPackageInstalled", packageName);
}

/**
* MacOS only!
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.freshplanet.ane.AirCapabilities.functions.GetDeviceModelFunction;
import com.freshplanet.ane.AirCapabilities.functions.GetOSVersionFunction;
import com.freshplanet.ane.AirCapabilities.functions.HasInstagramFunction;
import com.freshplanet.ane.AirCapabilities.functions.HasPackageInstalledFunction;
import com.freshplanet.ane.AirCapabilities.functions.HasSMSFunction;
import com.freshplanet.ane.AirCapabilities.functions.HasTwitterFunction;
import com.freshplanet.ane.AirCapabilities.functions.LogFunction;
Expand Down Expand Up @@ -92,6 +93,7 @@ public Map<String, FREFunction> getFunctions()
functionMap.put("postPictureOnInstagram", new PostPictureOnInstagramFunction());
functionMap.put("getCurrentMem", new GetCurrentMemFunction());
functionMap.put("openAdSettings", new OpenAdSettingsFunction());
functionMap.put("hasPackageInstalled", new HasPackageInstalledFunction());

return functionMap;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2017 FreshPlanet
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.freshplanet.ane.AirCapabilities.functions;

import android.content.pm.PackageManager;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;

public class HasPackageInstalledFunction implements FREFunction
{
@Override
public FREObject call(FREContext context, FREObject[] args)
{
FREObject result = null;

try
{
String packageName = args[0].getAsString();
try {
context.getActivity().getPackageManager().getPackageGids(packageName);
result = FREObject.newObject(true);
} catch (PackageManager.NameNotFoundException e) {
result = FREObject.newObject(false);
}
}
catch (Exception e)
{
e.printStackTrace();
}

return result;
}
}

0 comments on commit 0afb2d3

Please sign in to comment.