android调用另一app的xml,关于一个APP调用另一个APP的service

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

我在一个APP中调用另一个APP的service,出现这个异常:java.lang.SecurityException: Not allowed to start service Intent { cmp=com.example.startservicefromanotherapp/.AppService } without permission not exported from uid 10047

请问各位大神如何解决

代码如下:

被调用的App

package="com.example.startservicefromanotherapp"

android:versionCode="1"

android:versionName="1.0"

>

android:minSdkVersion="8"

android:targetSdkVersion="18" />

android:allowBackup="true"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

android:name="com.example.startservicefromanotherapp.MainActivity"

android:label="@string/app_name" >

package com.example.startservicefromanotherapp;

import android.app.Service;

import android.content.Intent;

import android.os.IBinder;

public class AppService extends Service{

@Override

public IBinder onBind(Intent arg0) {

// TODO Auto-generated method stub

return null;

}

public void onCreate(){

super.onCreate();

System.out.println("创建一个service");

}

public void onDestroy(){

super.onDestroy();

System.out.println("毁灭一个service");

}

}

调用的APP

package com.example.anotherapp;

import android.os.Bundle;

import android.app.Activity;

import android.content.ComponentName;

import android.content.Intent;

import android.view.Menu;

import android.view.View;

import android.view.View.OnClickListener;

public class MainActivity extends Activity implements OnClickListener{

Intent ServiceIntent=new Intent();

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

findViewById(R.id.btn_StartService).setOnClickListener(this);

findViewById(R.id.btn_StopService).setOnClickListener(this);

ServiceIntent.setComponent(new ComponentName("com.example.startservicefromanotherapp","com.example.startservicefromanotherapp.AppService"));

}

@Override

public void onClick(View v) {

switch(v.getId()){

case R.id.btn_StartService:

startService(ServiceIntent);

break;

case R.id.btn_StopService:

stopService(ServiceIntent);

break;

}

}

}

7afbc189150d638f27d599d95f49d920.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值