2013-04-20 17 views
0

我正在製作顯示已安裝應用程序列表的應用程序,並在項目點擊顯示權限。此外,它在後臺運行並在設備啓動時啓動。它在摩托羅拉Milestone(Android 2.1)上完美運行,但是在Sony Xperia(ICS)上測試時,該列表不會顯示點擊,因此顯示權限的活動不會顯示。活動無法在ICS中啓動,應用程序在摩托羅拉Milestone(2.1)上完美運行

LogCat在錯誤模式下不顯示任何內容。

MainActivity

package com.example.appslist; 

import java.util.List; 
import com.example.appslist.adapter.ApkAdapter; 
import com.example.appslist.app.AppData; 
import android.os.Bundle; 
import android.app.Activity; 
import android.content.Intent; 
import android.content.pm.PackageInfo; 
import android.content.pm.PackageManager; 
import android.view.View; 
import android.widget.AdapterView; 
import android.widget.AdapterView.OnItemClickListener; 
import android.widget.ListView; 
import com.example.backgroundapp.BackgroundService; 






public class ApkListActivity extends Activity implements OnItemClickListener { 

    PackageManager packageManager; 
    public static boolean isService = false; 





    @Override 
    public void onCreate(Bundle savedInstanceState) { 


     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     startService(new Intent(ApkListActivity.this,BackgroundService.class)); 
     Intent startMain = new Intent(Intent.ACTION_MAIN); 
     startMain.addCategory(Intent.CATEGORY_HOME); 
     startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     startActivity(startMain); 
     isService = true; 


     packageManager = getPackageManager(); 
     List<PackageInfo> packageList = packageManager 
       .getInstalledPackages(PackageManager.GET_PERMISSIONS); 

     ListView mylistview= (ListView) findViewById(android.R.id.list); 
     mylistview.setAdapter(new ApkAdapter(this, packageList, packageManager)); 
     mylistview.setOnItemClickListener(this); 
     } 





    @Override 
    public void onItemClick(AdapterView<?> parent, View view, int position, 
      long row) { 
     super.onResume(); 
     stopService(new Intent(ApkListActivity.this, 
       BackgroundService.class)); 

     PackageInfo packageInfo = (PackageInfo) parent 
       .getItemAtPosition(position); 
     AppData appData = (AppData) getApplication(); 
     appData.setPackageInfo(packageInfo); 

     Intent appInfo = new Intent(ApkListActivity.this, ApkInfo.class); 
     startActivity(appInfo); 
    } 
} 

清單

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.appslist" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="17" /> 

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 



    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" 
    android:name=".app.AppData"> 

     <activity 
      android:name="com.example.appslist.ApkListActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name=".ApkInfo" 
      android:label="@string/title_activity_apk_info" > 
     </activity> 

     <service android:enabled="true" android:name=".BackgroundService" /> 

     <receiver 
      android:enabled="true" 
      android:name="com.example.appslist.BootUpReceiver" 
     > 

     <intent-filter> 
       <action android:name="android.intent.action.BOOT_COMPLETED" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
``</receiver> 







</application> 


    </manifest> 

請幫助

回答

0

PackageInfo實現Parcelable爲什麼不把它作爲一個意向額外給你ApkInfo活動,而不是奇實現擴展Application類的來存儲這些數據。

此外,我不明白你與啓動服務,並在您onCreate主要活動,然後點擊停止服務在這裏做什麼:

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    startService(new Intent(ApkListActivity.this,BackgroundService.class)); 
    Intent startMain = new Intent(Intent.ACTION_MAIN); 
    startMain.addCategory(Intent.CATEGORY_HOME); 
    startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    startActivity(startMain); 
    isService = true; 
... 
+0

該服務用於在後臺運行應用程序。我的AppData類用於獲取權限。我不明白爲什麼它不能按照ICS的要求工作,你能提出改變建議嗎? – Prax 2013-04-20 13:22:22

+0

@Prax我不知道你的意思是「在後臺運行應用程序」,或者你爲什麼要在另一項活動的「onCreate」中開始一項活動。嘗試我上面所說的,刪除oncreate中的服務和活動的開始,並將'PackageInfo'作爲額外的意向發送,然後將編輯後的代碼發佈到您正在獲取的錯誤中。 – 2013-04-20 13:31:06

1

你仍然有這個問題?如果是這樣,你有沒有試過在其他Android 4.X +設備上運行,看它是否有效?如果這是Xperia特定的問題,請告訴我,我可以幫助進一步深入研究。另外,如果是Xperia特定哪種設備型號,您正在測試?

相關問題