2013-07-17 50 views
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); 
}} 
+0

Android只是更改apk名稱,而不是包名稱。 您的問題在您的應用程序內,請提供更多信息 –

+0

編輯該問題。 –

+0

更改IDE中的Java包,確保MyScheduleReceiver位於正確的包中。你應該添加一個。在名稱前面,這將使它將包名稱添加到接收者名稱中,如:

回答

0

回答第一個問題:

的Android只是改變了APK名稱,而不是包名

第二個問題:

更改您的IDE中的Java包,確保MyScheduleReceiver位於正確的包中。你應該添加一個。在名稱前面,這將使它將包名稱添加到接收者名稱中,例如:

<receiver android:name=".MyScheduleReceiver" > 
相關問題