2013-04-22 8 views
5

मैं एक apk जो नीचे कोड के साथ /data/data/package_name/files निर्देशिका में बचा लिया गया था स्थापित स्थापित करने के लिए 'startActivity' का उपयोग करें:मैं कैसे एक resultcode प्राप्त कर सकते हैं जब मैं एक apk

Uri uri = Uri.fromFile(new File(apkSavingPath)); 
Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(uri,"application/vnd.android.package-archive"); 
mContext.startActivity(intent); 

मैं इसे एक resultcode वापस जाने के लिए बताना चाहता हूँ मुझे पता है कि एपीके सफलतापूर्वक स्थापित है या नहीं, और मैंने startActivityForResult की विधि की कोशिश की है, लेकिन यह काम नहीं किया।

onActivityResult की विधि पर, परिणाम परिणाम हमेशा 0(zero) है कि एपीके सफलतापूर्वक स्थापित है या नहीं। क्या मुझे ऐसा परिणाम कोड मिल सकता है?

+0

सरल जवाब है, "आप नहीं कर सकते"। इंस्टॉलर गतिविधि कोई परिणाम नहीं लौटाती है। –

+0

संभावित डुप्लिकेट [एंड्रॉइड पर प्रोग्रामिक रूप से एपीके इंस्टॉल करें] (http://stackoverflow.com/questions/6362479/install-apk-programmatically-on-android) –

उत्तर

5

इसे आजमाएं।

Intent intent = new Intent(Intent.ACTION_VIEW);   
intent.setDataAndType("ApkFilePath...","application/vnd.android.package-archive"); 
activity.startActivityForResult(intent,5000); 

AndroidManifest.xml

<receiver android:name=".PackageReceiver" android:enabled="true" android:exported="true"> 
    <intent-filter> 
     <action android:name="android.intent.action.PACKAGE_ADDED" /> 
     <action android:name="android.intent.action.PACKAGE_CHANGED" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
     <data android:scheme="package" /> 
    </intent-filter> 
</receiver> 

पर अपने रिसीवर जोड़े जब एक नए पैकेज स्थापित किया गया है इस वर्ग तो कहा जाता हो जाता है:

public class PackageReceiver extends BroadcastReceiver { 

    @Override 
    public void onReceive(Context context, Intent intent) { 
    // handle install event here 
    } 
} 
+1

धन्यवाद! इसने काम कर दिया। लेकिन 'एंड्रॉइड जोड़ने के बाद: सक्षम = "सत्य" एंड्रॉइड: निर्यात किया गया = "सत्य" '। मैंने आपका जवाब संपादित किया। – breceivemail

+0

यह अच्छा है। कृपया जवाब स्वीकार करें। –

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