android - startActivityForResult is not recognized as function in AsyncTask -
I am creating a phonegap project. I have created an original plugin for this in Android. In it, the Ascend Task is also being called. In this, I have the Then I tried, But at the time of My code is as follows - Thanax Advance What error If so, this is because you are changing with the application context, which is the result of a If you change, then it works: : ? There is an explanation about different types of references, and when each is used. context.startActivity (intent) function. I want to do one thing after this activity is completed. I found a solution to use
context.startActivityForResult (intent, i) instead, but this function is not recognizable.
(activity) reference) .startActivityForResult (intent, 1); According to
startActivityForResult , I found the file installation error.
Public category reaches MyPlugin CordovaPlugin {reference reference; Callback callback callback; @ Override Public Zero Start (Cordova Interface Cordova, Cordova web web view) {Super Interlise (Cordova, webview); } Override Public Boolean Execution (String Action, JSNARRA RGR, CallbackConnecte CallbackContacts) throws JSONException {reference = this.cordova.getActivity (). GetApplicationContext (); Callback = callbackContext; If (action.equals ("plugin1")) {System.out.println ("Plugin Inside 1"); Letter myurl = args.getString (0); If (the Network Connection () == True) {System.out.println ("Network Connected"); New DownloadManager () Executed (myurl); Back true; } Else {System.out.println ("Network is not connected"); CallbackContext.error ("Internet connection is not available."); return false; }} CallbackContext.error ("Something has happened, please try later."); return false; } Public Class DownloadManager uses AsyncTask & lt; String, string, string & gt; {@Override public string doInBackground (string ... arg0) {try {// IMEI number telephony manager mngr = (telephony manager) context.getSystemService (context.TELEPHONY_SERVICE); String imei_device = mngr.getDeviceId (); // Download the app to download and install (arg0 [0]); Installapk (); Plugin result result = new plugin product (plugin results. Status ok, "success"); Result.setKeepCallback (true); Callback.success ("Operation Completed !!"); Return tap; } Hold (exception e) {callback.error ("something went wrong. Try again later"); Return tap; }}} Public Zero installapk () {{intent = new intent (Intent.ACTION_VIEW); Intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK); Intent.setDataAndType (Uri.fromFile (new file (Environment.getExternalStorageDirectory () + "/" + fileName), "app / vnd.android.package-archive"); (Activity) reference). Preliminary Results (Intent, 1); } Hold (exception e) {Log.e ("file installation error", egetmessage ()); Println (e.getMessage ()); Callback.error ("installation failed. Please try later"); }} On the @Override, public zero active features (int requestcode, integer result code, intent data) {if (requestcode == 1) // check whether the request code is sent to you {if (resultCode == activity. RESULT_OK) { System.out.println ("The result is OK"); } Else {System.out.println ("Result is not OK"); }} Super.onActivityResult (requestCode, ResultsCode, Data); }
ClassCastException ?
,
activity (which is
context ) Context is but no one can not be cast to achieve the
activity , and thus the
startActivityForResult method.
context = this.cordova.getActivity (). GetApplicationContext (); With
context = this.cordova.getActivity ();
Comments
Post a Comment