该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
我在一个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;
}
}
}