Mehdi
Mehdi

Reputation: 540

Show native android activity using phonegap plugin


I am new in android, searching for a way to start a native android activity using phonegap plugin, but I failed to get any. There are several but not matches my requirements. already I have build a plugin to communicate with phonegap and native android (http://www.adobe.com/devnet/html5/articles/extending-phonegap-with-native-plugins-for-android.html), but just showing messages.

I have tried 'intent' to show a new activity, but it not works. Below is successful code to start 'SEARCH CONTACT'. But what I want to start an activity - that created by me, like 'TestActivity'. Like, I will click a button from my html page, then it will take me to a new activity.

Is it possible?

Can anyone plz help me!

@Override
public PluginResult execute(String action, JSONArray data, String callbackId) {
    Log.d("HelloPlugin", "Hello, this is a native function called from PhoneGap/Cordova!"); 
    //only perform the action if it is the one that should be invoked 
    startContactActivity();
    PluginResult mPlugin = new PluginResult(PluginResult.Status.NO_RESULT);
    mPlugin.setKeepCallback(true);
    return mPlugin;
}

public void startContactActivity() {
    Intent intent = new Intent(Intent.ACTION_PICK);
    intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
    this.ctx.startActivityForResult((Plugin) this, intent, PICK_CONTACT);
}

Upvotes: 2

Views: 3250

Answers (1)

Mehdi
Mehdi

Reputation: 540

Finally I solved the problem.

@Override
    public PluginResult execute(String action, JSONArray data, String callbackId) {
        startPhotoEditActivity();
        PluginResult mPlugin = new PluginResult(PluginResult.Status.NO_RESULT);
        return mPlugin;
    }

    public void startPhotoEditActivity() {
        Intent myIntent = new Intent(ctx.getContext(), PreviewToAddEffect.class);       
        myIntent.putExtra("picUri", resultType);
        myIntent.putExtra("source", "gallery");
                ctx.startActivity(myIntent);
    }

Upvotes: 1

Related Questions