i'm trying started creating android plugins tasker app. i've started downloading 'toast' example , read documentation. i'm still playing wit example, when comment out toast action , replace code create alert dialog (which i've done in numerous other apps), tasker plugin crashes when try in tasker. i'm using android studio.
does know why? code below:
public class firereceiver extends broadcastreceiver { /** * @param context {@inheritdoc}. * @param intent incoming {@link com.twofortyfouram.locale.intent#action_fire_setting} intent. * should contain {@link com.twofortyfouram.locale.intent#extra_bundle} saved * {@link editactivity} , later broadcast locale. */ @override public void onreceive(final context context, final intent intent) { /* * strict on input parameters! malicious third-party app send malformed intent. */ if (!com.twofortyfouram.locale.intent.action_fire_setting.equals(intent.getaction())) { if (constants.is_loggable) { log.e(constants.log_tag, string.format(locale.us, "received unexpected intent action %s", intent.getaction())); //$non-nls-1$ } return; } bundlescrubber.scrub(intent); final bundle bundle = intent.getbundleextra(com.twofortyfouram.locale.intent.extra_bundle); bundlescrubber.scrub(bundle); if (pluginbundlemanager.isbundlevalid(bundle)) { final string message = bundle.getstring(pluginbundlemanager.bundle_extra_string_message); //toast.maketext(context, message, toast.length_long).show(); alertdialog.builder builder = new alertdialog.builder(context); builder.setmessage("yes, worked!") .seticon(r.drawable.ic_launcher) .settitle(r.string.dialog_title); builder.setpositivebutton(r.string.dialog_yes, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { // user clicked ok button //toast.maketext(context, "you clicked yes", toast.length_long).show(); } }); builder.setnegativebutton(r.string.dialog_no, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { // user cancelled dialog //toast.maketext(getapplicationcontext(), "you clicked no", toast.length_long).show(); } }); alertdialog dialog = builder.create(); dialog.show(); } }
for might come across this, solved issue in end. firereceiver isn't capable of displaying things alerts etc. , have use firereceiver open activity instead handles alert or whatever else want display.
this works me (i've changed package name gist). newactiviy whatever activity called want firereciever open. shows code passing variables along it, pretty standard:
intent opennext = new intent(); opennext.setclassname("com.yourcompany.yoursetting", "com.yourcompany.blahblah.receiver.newactivity"); opennext.putextra("alerttitle", message); opennext.putextra("alertcontentsstring", alertcontents); opennext.putextra("backcolour", backgroundc); opennext.putextra("textcolour", titlec); opennext.putstringarraylistextra("showarray", arr); opennext.setflags(intent.flag_activity_new_task); context.startactivity(opennext);
Comments
Post a Comment