1

我有一个问题..我的包名是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);
}}
4

1 回答 1

0

回答第一个问题:

Android 只是更改 apk 名称,而不是包名称

第二个问题:

更改 IDE 中的 java 包,确保 MyScheduleReceiver 位于正确的包中。你应该添加一个 . 在名称前面,这将使其将包名称添加到接收者名称中,例如:

<receiver android:name=".MyScheduleReceiver" >
于 2013-07-17T09:44:52.893 回答