Hi Nicolay,
I think this was already done.
please see shortened sources below.
also, the Service has this line in its manifest:
<service android:name=".RemoteService" android:process=":remote">
maybe you can spot something?
thanks!
package com.example.remoteservice;
public class RemoteService extends Service {
final Messenger myMessenger = new Messenger(new IncomingHandler());
@Override
public IBinder onBind(Intent intent) {
return myMessenger.getBinder();
}
class IncomingHandler extends Handler {
@Override
public void handleMessage(Message msg) {
Bundle data = msg.getData();
String dataString = data.getString("MyString");
dataString += isCallingClientHasPermissions()? "\nAuthorized" :
"\nNot authorized";
Toast.makeText(getApplicationContext(), dataString,
Toast.LENGTH_LONG).show();
}
}
}
package com.example.remoteclient;
public class RemoteClient extends Activity {
Messenger myService = null;
boolean isBound;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_remote_bound);
Intent intent = new
Intent("com.example.remoteservice.RemoteService");
bindService(intent, myConnection, Context.BIND_AUTO_CREATE);
}
private ServiceConnection myConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder
service) {
myService = new Messenger(service);
isBound = true;
}
public void onServiceDisconnected(ComponentName className) {
myService = null;
isBound = false;
}
};
public void sendMessage(View view)
{
if (!isBound) return;
Message msg = Message.obtain();
Bundle bundle = new Bundle();
bundle.putString("MyString", "Message from
RemoteClient");
msg.setData(bundle);
try {
myService.send(msg);
} catch (RemoteException e) {e.printStackTrace();}
}
}
On Thursday, March 6, 2014 7:19:16 AM UTC+2, Nikolay Elenkov wrote:
>
> On Thu, Mar 6, 2014 at 2:08 PM, smoogli <[email protected] <javascript:>>
> wrote:
> >
> > (I can only assume there is some configuration that needs to be set, or
> > something that I am missing here)
> >
>
> You need a bound service for this to work and you will only get the UID of
> the activity on binder calls.
>
> http://developer.android.com/guide/components/bound-services.html
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.