Last active
April 25, 2019 21:36
-
-
Save ayyagary/f3110ef611fbe8d198f74ab1146afebb to your computer and use it in GitHub Desktop.
Appcelerator app code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Activity = require('android.app.Activity'); | |
var PackageManager = require('android.content.pm.PackageManager'); | |
function doClick(e) { | |
alert(checkInstalled("com.bluetooth.app") ); | |
if(checkInstalled("com.bluetooth.app")){ | |
try{ | |
var intent = Ti.Android.createIntent({ | |
action: Ti.Android.ACTION_MAIN, | |
className: "com.bluetooth.app.MainActivity", | |
packageName: "com.bluetooth.app", | |
}); | |
intent.addCategory(Ti.Android.CATEGORY_LAUNCHER); | |
intent.setFlags(Ti.Android.FLAG_ACTIVITY_NEW_TASK); | |
intent.putExtra("fn","test_fn"); | |
intent.putExtra("ln","test_ln"); | |
Ti.Android.currentActivity.startActivity(intent); | |
} | |
catch(e){ | |
} | |
} else { | |
alert("Please install the buddy app from app store"); | |
} | |
} | |
function checkInstalled(packageName) { | |
var activity = new Activity(Ti.Android.currentActivity); | |
var pm = activity.getPackageManager(); | |
try { | |
//Throws NameNotFoundException if app is not installed | |
pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); | |
return true; | |
} catch (error) { | |
console.log('App ' + packageName + ' is not installed'); | |
} | |
return false; | |
} | |
$.index.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment