本文整理匯總了Java中org.apache.cordova.CordovaActivity類的典型用法代碼示例。如果您正苦於以下問題:Java CordovaActivity類的具體用法?Java CordovaActivity怎麽用?Java CordovaActivity使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CordovaActivity類屬於org.apache.cordova包,在下文中一共展示了CordovaActivity類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: startActivity
import org.apache.cordova.CordovaActivity; //導入依賴的package包/類
private void startActivity(String action, Uri uri, String type, Map<String, String> extras, boolean bExpectResult, int requestCode, CallbackContext callbackContext) {
// Credit: https://github.com/chrisekelley/cordova-webintent
Intent i = (uri != null ? new Intent(action, uri) : new Intent(action));
if (type != null && uri != null) {
i.setDataAndType(uri, type); //Fix the crash problem with android 2.3.6
} else {
if (type != null) {
i.setType(type);
}
if (uri != null)
{
i.setData(uri);
}
}
for (String key : extras.keySet()) {
String value = extras.get(key);
// If type is text html, the extra text must sent as HTML
if (key.equals(Intent.EXTRA_TEXT) && type.equals("text/html")) {
i.putExtra(key, Html.fromHtml(value));
} else if (key.equals(Intent.EXTRA_STREAM)) {
// allowes sharing of images as attachments.
// value in this case should be a URI of a file
final CordovaResourceApi resourceApi = webView.getResourceApi();
i.putExtra(key, resourceApi.remapUri(Uri.parse(value)));
} else if (key.equals(Intent.EXTRA_EMAIL)) {
// allows to add the email address of the receiver
i.putExtra(Intent.EXTRA_EMAIL, new String[] { value });
} else {
i.putExtra(key, value);
}
}
i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (i.resolveActivityInfo(this.cordova.getActivity().getPackageManager(), 0) != null)
{
if (bExpectResult)
{
cordova.setActivityResultCallback(this);
((CordovaActivity) this.cordova.getActivity()).startActivityForResult(i, requestCode);
}
else
{
((CordovaActivity)this.cordova.getActivity()).startActivity(i);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
}
}
else
{
// Return an error as there is no app to handle this intent
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
}
}
示例2: saveConfigOptions
import org.apache.cordova.CordovaActivity; //導入依賴的package包/類
/**
* Reads "shownotificationmessage" & "defaultnotificationmessage" config options
* If this is first-time it saves them to sharedPreferences so they can be read
* when app is forced-stop or killed
*/
public static void saveConfigOptions(Context context) {
if (context != null && TextUtils.isEmpty(defaultOfflineMessage)) {
// read config options from config.xml
shouldShowOfflineMessage = ((CordovaActivity) context)
.getBooleanProperty(SHOW_MESSAGE_PREF, false);
defaultOfflineMessage = ((CordovaActivity) context)
.getStringProperty(DEFAULT_MESSAGE_PREF, null);
// save them to sharedPreferences if necessary
SharedPreferences config = context.getApplicationContext().getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = config.edit();
editor.putBoolean(SHOW_MESSAGE_PREF, shouldShowOfflineMessage);
editor.putString(DEFAULT_MESSAGE_PREF, defaultOfflineMessage);
// save prefs to disk
editor.commit();
}
}
示例3: initialize
import org.apache.cordova.CordovaActivity; //導入依賴的package包/類
public void initialize(CordovaInterface _cordova, CordovaWebView webView) {
CordovaActivity Activity = (CordovaActivity) _cordova.getActivity();
final String invokeString = Activity.getIntent().getDataString();
if(invokeString != "" && invokeString != null)
{
lastRedirect = invokeString;
System.out.println("Preparing Redirect to "+lastRedirect);
}
super.initialize(_cordova, webView);
cordova = _cordova;
Bundle b = new Bundle();
b.putString("CDVCapptainVersion",pluginVersion);
CapptainAgent.getInstance(cordova.getActivity()).sendAppInfo( b);
}
示例4: onCreate
import org.apache.cordova.CordovaActivity; //導入依賴的package包/類
public static void onCreate(CordovaActivity activity) {
Bundle extras = activity.getIntent().getExtras();
if (extras != null) {
if (extras.containsKey(SHOW_OPTION)) {
ShowOption option = ShowOption.parse(extras.getString(SHOW_OPTION));
if (option == ShowOption.WakeScreen)
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
if (option == ShowOption.ShowOverLockScreen)
activity.getWindow().addFlags( WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}
}
}
示例5: getActivityExtras
import org.apache.cordova.CordovaActivity; //導入依賴的package包/類
private PluginResult getActivityExtras(Context context) {
PluginResult result = null;
JSONObject data = new JSONObject();
try {
CordovaActivity activity = (CordovaActivity)context;
Bundle extras = activity.getIntent().getExtras();
if (extras != null) {
Set<String> keys = extras.keySet();
Iterator<String> it = keys.iterator();
while (it.hasNext()) {
String key = it.next();
Object value = extras.get(key);
data.put(key, value);
}
}
} catch (Exception ex) {
Log.d(TAG, "Error while trying to get extra data", ex);
}
result = new PluginResult(Status.OK, data);
return result;
}
示例6: sendBroadcast
import org.apache.cordova.CordovaActivity; //導入依賴的package包/類
private void sendBroadcast(String action, Map<String, String> extras) {
// Credit: https://github.com/chrisekelley/cordova-webintent
Intent intent = new Intent();
intent.setAction(action);
for (String key : extras.keySet()) {
String value = extras.get(key);
intent.putExtra(key, value);
}
((CordovaActivity)this.cordova.getActivity()).sendBroadcast(intent);
}
示例7: initialize
import org.apache.cordova.CordovaActivity; //導入依賴的package包/類
/**
* Sets the context of the Command. This can then be used to do things like get file paths associated with the
* Activity.
*
* @param cordova
* The context of the main Activity.
* @param webView
* The associated CordovaWebView.
*/
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
// Initialize only for Amazon devices 2nd Generation and later
if (this.isAmazonDevice() && !isFirstGenKindleFireDevice()) {
adm = new ADM(cordova.getActivity());
activity = (CordovaActivity) cordova.getActivity();
webview = this.webView;
isForeground = true;
ADMMessageHandler.saveConfigOptions(activity);
} else {
LOG.e(TAG, NON_AMAZON_DEVICE_ERROR);
}
}
示例8: onNewIntent
import org.apache.cordova.CordovaActivity; //導入依賴的package包/類
@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
((CordovaActivity)this.cordova.getActivity()).setIntent(intent);
if (this.onNewIntentCallbackContext != null) {
PluginResult result = new PluginResult(PluginResult.Status.OK, intent.getDataString());
result.setKeepCallback(true);
this.onNewIntentCallbackContext.sendPluginResult(result);
}
}
示例9: startActivity
import org.apache.cordova.CordovaActivity; //導入依賴的package包/類
void startActivity(String action, Uri uri, String type, Map<String, String> extras) {
Intent i = (uri != null ? new Intent(action, uri) : new Intent(action));
if (type != null && uri != null) {
i.setDataAndType(uri, type); //Fix the crash problem with android 2.3.6
} else {
if (type != null) {
i.setType(type);
}
}
for (String key : extras.keySet()) {
String value = extras.get(key);
// If type is text html, the extra text must sent as HTML
if (key.equals(Intent.EXTRA_TEXT) && type.equals("text/html")) {
i.putExtra(key, Html.fromHtml(value));
} else if (key.equals(Intent.EXTRA_STREAM)) {
// allowes sharing of images as attachments.
// value in this case should be a URI of a file
final CordovaResourceApi resourceApi = webView.getResourceApi();
i.putExtra(key, resourceApi.remapUri(Uri.parse(value)));
} else if (key.equals(Intent.EXTRA_EMAIL)) {
// allows to add the email address of the receiver
i.putExtra(Intent.EXTRA_EMAIL, new String[] { value });
} else {
i.putExtra(key, value);
}
}
((CordovaActivity)this.cordova.getActivity()).startActivity(i);
}
示例10: sendBroadcast
import org.apache.cordova.CordovaActivity; //導入依賴的package包/類
void sendBroadcast(String action, Map<String, String> extras) {
Intent intent = new Intent();
intent.setAction(action);
for (String key : extras.keySet()) {
String value = extras.get(key);
intent.putExtra(key, value);
}
((CordovaActivity)this.cordova.getActivity()).sendBroadcast(intent);
}
示例11: activate
import org.apache.cordova.CordovaActivity; //導入依賴的package包/類
private void activate() {
CordovaActivity act = (CordovaActivity) this.webView.getContext();
Log.i(TAG, "active mdm by =" + act.getClass().getName());
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, MdmExecutor.getInstance().getAdminName());
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "press button to active mdm");
act.startActivityForResult(PluginMdm.this, intent, REQUEST_CODE_MDM);
}
示例12: inactivate
import org.apache.cordova.CordovaActivity; //導入依賴的package包/類
private void inactivate() {
CordovaActivity act = (CordovaActivity) this.webView.getContext();
ComponentName devAdminReceiver = MdmExecutor.getInstance().getAdminName();
DevicePolicyManager dpm = (DevicePolicyManager) act.getSystemService(Context.DEVICE_POLICY_SERVICE);
dpm.removeActiveAdmin(devAdminReceiver);
}