java - Passing parameters in Intentw using URI from "App A" to "App B"-Android -


i cant solve problem soo need :)

i have 2 apps "app a" , "app b". in "app a" im entry 2 numerbs(in 2 diffrent edittext) after click button "sendwithdata"(here im passing parameters edittext using uri). "app 2" catch parameters "app a", adds 2 numbers , displays result. thik wrong geting parameters uri.

app a

public class wprowadzanieliczbactivity extends actionbaractivity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_wprowadzanie_liczb);  }   @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.menu_wprowadzanie_liczb, menu);     return true; }  @override public boolean onoptionsitemselected(menuitem item) {     // handle action bar item clicks here. action bar     // automatically handle clicks on home/up button, long     // specify parent activity in androidmanifest.xml.     int id = item.getitemid();      //noinspection simplifiableifstatement     if (id == r.id.action_settings) {         return true;     }      return super.onoptionsitemselected(item); }  public void sendwithdata(view view) {     string adres2 = adresurisumy();     uri uri = uri.parse(adres2);     intent intent = new intent(intent.action_view, uri);     startactivity(intent); }  private string adresurisumy() {     edittext liczbaainput = (edittext) findviewbyid(r.id.a);     editable liczbaa = liczbaainput.gettext();     string liczbaaparam = string.format("liczbaa=%s", liczbaa);      edittext liczbabinput = (edittext) findviewbyid(r.id.b);     editable liczbab = liczbabinput.gettext();     string liczbabparam = string.format("liczbaa=%s", liczbab);      string podstawowyadres = "calculator://wwsis.com.pl/suma";      string adres2 = string.format("%s?%s%s", podstawowyadres, liczbaaparam, liczbabparam);      return (adres2); }} 

app b

public class wyswietlanieactivity extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_wyswietlanie);     wezdanezuri();  }   @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.menu_wyswietlanie, menu);     return true; }  @override public boolean onoptionsitemselected(menuitem item) {     // handle action bar item clicks here. action bar     // automatically handle clicks on home/up button, long     // specify parent activity in androidmanifest.xml.     int id = item.getitemid();      //noinspection simplifiableifstatement     if (id == r.id.action_settings) {         return true;     }      return super.onoptionsitemselected(item); }   private void wezdanezuri() {     uri uri = getintent().getdata();     if (uri != null) {         double liczbaa = getdoubleparam(uri, "liczbaa");         double liczbab = getdoubleparam(uri, "liczbab");          double suma = liczbaa + liczbab;          textview textview = (textview) findviewbyid(r.id.wyswietlacz);           textview.settext(liczbaa + liczbab + double.tostring(suma));      }   }  private double getdoubleparam(uri uri, string queryparamname) {     string wzorzmiennej = uri.getqueryparameter(queryparamname);     double value = 0.0;     try {         value = double.parsedouble(wzorzmiennej);     } catch (exception e) {     } // numberformatexception or nullpointerexception     return (value); }} 

app b manifest

<?xml version="1.0" encoding="utf-8"?> 

<application     android:allowbackup="true"     android:icon="@mipmap/ic_launcher"     android:label="@string/app_name"     android:theme="@style/apptheme" >     <activity         android:name=".wyswietlanieactivity"         android:label="@string/app_name" >         <intent-filter>             <action android:name="android.intent.action.main" />              <category android:name="android.intent.category.launcher" />         </intent-filter>         <intent-filter>             <action android:name="android.intent.action.view"/>             <category android:name="android.intent.category.default"/>             <data android:scheme="calculator" android:host="wwsis.com.pl" android:path="/suma"/>         </intent-filter>     </activity> </application> 

i ran code , figured out problems were.

the main problem missing & between parameters, made first parameter contain after liczbaa, , second parameter blank.

you accidentally used liczbaa twice in adresurisumy() method.

i switched explicitly use strings edittext values, work have well, since implicitly call tostring() on each editable when use in string.format().

the last issue formatting result in app b.

first, here fixes app made work:

private string adresurisumy() {     //use strings edittext fields:     edittext liczbaainput = (edittext) findviewbyid(r.id.a);     string liczbaa = liczbaainput.gettext().tostring();     string liczbaaparam = string.format("liczbaa=%s", liczbaa);      //use liczbab below:     edittext liczbabinput = (edittext) findviewbyid(r.id.b);     string liczbab = liczbabinput.gettext().tostring();     string liczbabparam = string.format("liczbab=%s", liczbab);//modified      string podstawowyadres = "calculator://wwsis.com.pl/suma";      //notice & below     string adres2 = string.format("%s?%s&%s", podstawowyadres, liczbaaparam, liczbabparam);      return (adres2); } 

here fix made in app b:

private void wezdanezuri() {     uri uri = getintent().getdata();      if (uri != null) {          double liczbaa = getdoubleparam(uri, "liczbaa");         double liczbab = getdoubleparam(uri, "liczbab");          double suma = liczbaa + liczbab;          textview textview = (textview) findviewbyid(r.id.wyswietlacz);          //modified:         textview.settext(double.tostring(liczbaa) + " + " + double.tostring(liczbab) + " = " + double.tostring(suma));      } } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -