mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 15:12:51 +08:00
CB-12835: add a Context getter in CordovaInterface
A custom engine may live outside of the Activity's lifecycle and the Activity instance may not always be available. This getter allows Context accesses in all cases.
This commit is contained in:
parent
3a6e898b12
commit
17906735df
@ -19,6 +19,7 @@
|
||||
package org.apache.cordova;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import org.apache.cordova.CordovaPlugin;
|
||||
@ -51,10 +52,18 @@ public interface CordovaInterface {
|
||||
/**
|
||||
* Get the Android activity.
|
||||
*
|
||||
* If a custom engine lives outside of the Activity's lifecycle the return value may be null.
|
||||
*
|
||||
* @return the Activity
|
||||
*/
|
||||
public abstract Activity getActivity();
|
||||
|
||||
|
||||
/**
|
||||
* Get the Android context.
|
||||
*
|
||||
* @return the Context
|
||||
*/
|
||||
public Context getContext();
|
||||
|
||||
/**
|
||||
* Called when a message is sent to plugin.
|
||||
|
@ -20,6 +20,7 @@
|
||||
package org.apache.cordova;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
@ -84,6 +85,11 @@ public class CordovaInterfaceImpl implements CordovaInterface {
|
||||
return activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context getContext() {
|
||||
return activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object onMessage(String id, Object data) {
|
||||
if ("exit".equals(id)) {
|
||||
|
Loading…
Reference in New Issue
Block a user