【问题标题】:Why my package name change when i install the application?为什么我安装应用程序时我的包名称会更改?
【发布时间】:2013-07-15 16:52:44
【问题描述】:

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

【问题讨论】:

  • Android 只是更改 apk 名称,而不是包名称。您的问题在您的申请中,请提供更多信息
  • 更改 IDE 中的 java 包,确保 MyScheduleReceiver 位于正确的包中。你应该添加一个 .在名称前面,这将使其将包名称添加到接收者名称中,例如:
  • 好的,现在我没有错误或崩溃,但通知没有启动。
  • 你能显示广播接收器代码吗?
  • 已添加。我认为这一切都是正确的,但什么也没发生。。也许通知代码不正确?

标签: android broadcastreceiver package android-notifications


【解决方案1】:

回答第一个问题:

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

第二个问题:

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

<receiver android:name=".MyScheduleReceiver" >

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-17
    • 1970-01-01
    • 2020-01-29
    • 1970-01-01
    • 1970-01-01
    • 2015-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多