2011-06-04 19 views
14

मैं एक ऐसे एप्लिकेशन पर काम कर रहा हूं जहां मैं पैकेज मैनेजर के साथ स्थापित अनुप्रयोगों को सूचीबद्ध करता हूं। मैं क्लिक किए गए आइटम का पैकेज नाम प्राप्त कर सकता हूं, लेकिन फिर मैं पैकेज के आधार पर विवरण स्क्रीन लॉन्च करना चाहता हूं। तो उदाहरण के लिए यदि सूची में डॉल्फिन ब्राउज़र का चयन किया गया था, तो आप निम्न छवि देखेंगे। मैं यह कैसे कर सकता हूँ?एंड्रॉइड लॉन्च एप्लिकेशन विवरण पृष्ठ

enter image description here

अंतिम समाधान Gingerbread एपीआई स्तर 9 के रूप में अपने लक्ष्य रखा और एपीआई स्तर के रूप में अपने न्यूनतम सेट 7

final int apiLevel = Build.VERSION.SDK_INT; 
Intent intent = new Intent(); 
if (apiLevel >= 9) { 
    //TODO get working on gb 
    //Toast.makeText(SDMove.this, "Gingerbread Not Currently Supported", Toast.LENGTH_LONG).show(); 
    startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, 
          Uri.parse("package:" + pli.pkg.packageName))); 
} else { 
    final String appPkgName = (apiLevel == 8 ? "pkg" : "com.android.settings.ApplicationPkgName"); 
    intent.setAction(Intent.ACTION_VIEW); 
    intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails"); 
    intent.putExtra(appPkgName, pli.pkg.packageName); 
    startActivity(intent); 
} 

उत्तर

10

यहां ListActivity के साथ एक पूरी तरह से काम कर रहा ऐप है जो सभी स्थापित ऐप्स सूचीबद्ध करता है। जब आप किसी पैकेज नाम पर क्लिक करते हैं, तो यह ऐप विवरण खोलता है।

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ListView 
     android:id="@android:id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"/> 
    <TextView android:id="@android:id/empty" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="No apps installed"/> 
</LinearLayout> 

और simple.xml:

<?xml version="1.0" encoding="utf-8"?> 
<TextView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
</TextView> 
अपने लेआउट फ़ोल्डर में

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    // Intent for getting installed apps. 
    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); 
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); 

    // Get installed apps 
    List<ResolveInfo> appList = this.getPackageManager().queryIntentActivities(mainIntent, 0); 

    // Make new list for package names and fill the list. 
    List<String> packageNameList = new ArrayList<String>(); 
    for (ResolveInfo resolveInfo : appList) { 
     packageNameList.add(resolveInfo.activityInfo.packageName); 
    } 

    // Set the list adapter. 
    setListAdapter(new ArrayAdapter<String>(this, R.layout.simple, packageNameList)); 
} 

public void onListItemClick(ListView l, View v, int position, long id) 
{ 
    // Get the TextView that was clicked. 
    TextView view = (TextView)v; 

    // Get the text from the TextView. 
    String packageName = (String)view.getText(); 

    // Open AppDetails for the selected package. 
    showInstalledAppDetails(packageName); 
} 

public void showInstalledAppDetails(String packageName) { 
    final int apiLevel = Build.VERSION.SDK_INT; 
    Intent intent = new Intent(); 

    if (apiLevel >= 9) { 
     intent.setAction(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS); 
     intent.setData(Uri.parse("package:" + packageName)); 
    } else { 
     final String appPkgName = (apiLevel == 8 ? "pkg" : "com.android.settings.ApplicationPkgName"); 

     intent.setAction(Intent.ACTION_VIEW); 
     intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails"); 
     intent.putExtra(appPkgName, packageName); 
    } 

    // Start Activity 
    startActivity(intent); 
} 

main.xml है याद रखें। उम्मीद है कि यह काम करता है :)

+0

के लिए काम नहीं करता है क्या इसके लिए कोई स्पष्ट अनुमति या कुछ है? मैं कुछ भी कोशिश करने के साथ बल बंद कर रहा हूं, मैंने कोशिश की है कि मैंने बस अपनी विधि को डेस्कक्लॉक जैसे कुछ सरल सेट करने की कोशिश की है। मैंने अपनी विधि को तब दिखाया ShowInstalledAppDetails ("com.android.deskclock"); लेकिन इससे कोई फर्क नहीं पड़ता कि मैं इसे बल देने की कोशिश करता हूं, मैं रूट डी 1 पर प्रोजेक्ट एलिट जीबी चला रहा हूं लेकिन ऐप मैंने अपने मिनी एसडीके के रूप में 2.2 पर सेट किया है, लेकिन मुझे नहीं पता कि मैं हर बार – GFlam

+0

पर क्यों मजबूर करता हूं, मुझे इसे अपने 2.2 एमुलेटर पर चलाने के लिए मिला , लेकिन जब मैंने "com.android.deskclock" की कोशिश की तो मुझे "पैकेज पुनर्प्राप्त करते समय अपवाद": com.android.deskclock "मिला। एक और ऐप आज़माएं, जैसे "com.android.settings", जो एम्यूलेटर में काम करता है। यह बहुत महत्वपूर्ण है कि पैकेज का नाम सही है :) यदि आप इसे काम नहीं करते हैं, तो आप लॉगकैट से स्टैकट्रैक पोस्ट कर सकते हैं। – khellang

+0

हाँ ने इस विधि बल को बंद करने के लक्ष्य के साथ 2.3 के साथ एक नई परियोजना बनाई है लेकिन नीचे दिया गया कोड 2.3 के साथ काम करता है जैसा कि आपने कहा था, लेकिन मुझे 2.2 पर इसकी आवश्यकता है क्योंकि मैं 2.2 एप के लिए इस ऐप को लिख रहा हूं। वैसे भी एक सेकंड में logcat पोस्टिंग वास्तव में वहाँ में कुछ भी नहीं देखा लेकिन हो सकता है आप – GFlam

9

इस प्रयास करें:

startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:your.package.here"))); 

और की जगह "पैकेज : your.package.here "असली पैकेज के साथ आप देखना चाहते हैं ...

+0

यह केवल 2.3 है ... – khellang

+0

इसके लिए 2.2 ऐप पर कुछ भी काम कर रहा है? – GFlam

+0

यह उत्तर बहुत बेहतर है :) –

संबंधित मुद्दे