0

我正在制作一个显示已安装应用程序列表的应用程序,并在项目上单击显示权限。此外,它在后台运行并在设备启动时启动。它在 Motorola Milestone(Android 2.1)上完美运行,但在 Sony Xperia(ICS) 上进行测试时,不会单击列表,因此不会显示显示权限的活动。

LogCat 在错误模式下不显示任何内容。

主要活动

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>

请帮忙

4

2 回答 2

1

你还有这个问题吗?如果是这样,您是否尝试在其他 Android 4.X+ 设备上运行以查看它是否有效?如果这是 Xperia 特有的问题,请告诉我,我可以帮助进一步深入研究。此外,如果它是 Xperia 特定的,您正在测试哪种设备型号?

于 2013-07-09T22:14:24.757 回答
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;
...
于 2013-04-20T11:27:34.553 回答