我有一个问题..我的包名是com.dd.batterystats
但是当我编译应用程序并安装它时,包名称更改为com.dd.batterystats-1
..这对我来说是一个问题,因为我有一个服务在启动时启动通知。当然现在我收到一个错误:
Didn't find class "com.dd.batterystats.MyScheduleReceiver" on path: /data/app/com.dd.batterystats-1
为什么在安装过程中包名更改?
编辑:
这是清单的一部分: 当然首先:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED">
然后
<receiver android:name="MyScheduleReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="service" >
</service>
这里是service.java
public class service extends Service {
NotificationManager mNotificationManager;
@Override public IBinder onBind(Intent intent) {
// Not used
return null;
}
@Override public void onCreate() {
super.onCreate();
mNotificationManager= (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
checkPref();
}
@Override
public void onDestroy() {
super.onDestroy();
}
private void checkPref(){
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
service.this);
notificationBuilder.setContentTitle("Title");
notificationBuilder.setContentText("Context");
notificationBuilder.setTicker("TickerText");
notificationBuilder.setWhen(System.currentTimeMillis());
notificationBuilder.setSmallIcon(R.drawable.ic_stat_icon);
Intent notificationIntent = new Intent(this, service.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
notificationBuilder.setContentIntent(contentIntent);
notificationBuilder.setDefaults(Notification.DEFAULT_SOUND
| Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);
mNotificationManager.notify(1,
notificationBuilder.build());
} }
这里是MyScheduleReceiver.java
public class MyScheduleReceiver extends BroadcastReceiver {
// Restart service every 30 min
private static final long REPEAT_TIME = 30*1000*4;//1800000 ;
@Override
public void onReceive(Context context, Intent intent) {
Intent service = new Intent(context, service.class);
context.startService(service);
}}
答案 0 :(得分:0)
回答第一个问题:
Android只更改了apk名称,而不是包名称
第二个问题:
更改IDE中的java包,确保MyScheduleReceiver位于正确的包中。你应该添加一个。在名称前面,这将使包名称添加到接收者名称,如:
<receiver android:name=".MyScheduleReceiver" >