2013-06-30 13 views
7

मैं ऐप की एपीके फ़ाइल को किसी अन्य डिवाइस पर भेजने के लिए इस कोड का उपयोग करता हूं। यह एंड्रॉइड 2.3.3 पर काम करता है, लेकिन एंड्रॉइड 4+ पर काम नहीं कर रहा है।एपीके फ़ाइल भेजना एंड्रॉइड

समस्या कहां है?

मैंने getpackageCodePath() लॉग किया है और यह एंड्रॉइड 4+ पर एपीके फ़ाइल देता है, लेकिन पूरा कोड काम नहीं कर रहा है, और जब ब्लूटूथ शुरू होता है, तो यह कुछ भी नहीं भेजता है। लाइन

ArrayList<Uri> uris = new ArrayList<Uri>(); 
Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE); 
sendIntent.setType("application/vnd.android.package-archive"); 
uris.add(Uri.parse(getApplication().getPackageCodePath())); 
sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); 
startActivity(Intent.createChooser(sendIntent, null)); 
+0

आप सुनिश्चित करें कि आपके Android 4.0 उपकरण को संभालने के लिए सुसज्जित है कर रहे हैं ब्लूटूथ स्थानान्तरण? क्या आपने ओआई फ़ाइल मैनेजर या कुछ का उपयोग कर ब्लूटूथ पर एक फाइल भेजने की कोशिश की है? –

+0

हां, और मैं अपने फोन के माध्यम से फ़ाइल प्रबंधक के साथ फाइल भेज सकता हूं – Ata

+0

@Ata क्या आपको कोई जवाब मिला? –

उत्तर

1

बदलें:

uris.add(Uri.parse(getApplication().getPackageCodePath())); 

uris.add(Uri.fromFile(new File(getApplicationInfo().publicSourceDir))); 

करने और यह सब 4.x उपकरणों में काम करना चाहिए। वैकल्पिक रूप से आप इस तरह कुछ भी कर सकते हैं:

ApplicationInfo app=getPackageManager().getApplicationInfo("packageName", 0);      
uris.add(Uri.fromFile(new File(app.publicSourceDir))); 

उपर्युक्त दोनों तरीके मेरे लिए काम करते हैं।

0

आप getApplication().getPackageCodePath() के बजाय getApplicationInfo().publicSourceDir उपयोग कर सकते हैं अपने ऐप के APK के लिए पथ प्राप्त करने के लिए, तो वह एक ACTION_SENDIntent में ब्लूटूथ के माध्यम से फाइल भेजने का उपयोग करें।

एक उदाहरण के लिए यहाँ देखें: Bluetooth File transfer on Android(even restricted types)

12

मैं भेजने apk के लिए नीचे दिए गए कोड का उपयोग करें। और यह काम करता

try{ 
    ArrayList<Uri> uris = new ArrayList<Uri>(); 
    Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE); 
    sendIntent.setType("application/*"); 
    uris.add(Uri.fromFile(new File(getApplicationInfo().publicSourceDir))); 
    sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); 
    startActivity(Intent.createChooser(sendIntent, null)); 

}catch(Exception e){} 
+1

+1 मैंने इस कोड को आजमाया, यह सैमसंग उपकरणों में काम कर रहा है लेकिन मोटो जी 2 पर काम नहीं कर रहा है। कृपया मुझे बताएं कि इस मुद्दे को कैसे हल किया जाए –

0
InputStream in = null; 
      OutputStream out = null; 
      File apkPublicFilePath = new File(
        Environment 
          .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), 
        "myapk.apk"); 
      try { 

       in = getResources().openRawResource(R.raw.myapk); 
       out = new FileOutputStream(apkPublicFilePath); 
       byte[] buffer = new byte[1024]; 
       int length; 
       while ((length = in.read(buffer)) > 0) { 
        out.write(buffer, 0, length); 
       } 

       // Close the streams 
       out.flush(); 
       out.close(); 
       in.close(); 
      } catch (IOException e) { 
       Log.d(TAG, "Error in copy files"); 
      } 

      Intent sendIntent = new Intent(); 
      sendIntent.setAction(Intent.ACTION_SEND); 
      sendIntent.putExtra(Intent.EXTRA_STREAM, 

      Uri.fromFile(apkPublicFilePath.getAbsoluteFile())); 
      try { 
       sendIntent.setType("application/vnd.android.package-archive"); 
       startActivity(Intent.createChooser(
         sendIntent, 
         PersianReshape.reshape(getResources().getString(
           R.string.msg_send)))); 
      } catch (Exception e) { 
       sendIntent.setType("*/*"); 
       startActivity(Intent.createChooser(
         sendIntent, 
         PersianReshape.reshape(getResources().getString(
           R.string.msg_send)))); 
      } 
0

मैं यह काम आशा:

// Get current ApplicationInfo to find .apk path 
ApplicationInfo app = getApplicationContext().getApplicationInfo(); 
String filePath = app.sourceDir; 

Intent intent = new Intent(Intent.ACTION_SEND); 

// MIME of .apk is "application/vnd.android.package-archive". 
// but Bluetooth does not accept this. Let's use "*/*" instead. 
intent.setType("*/*"); 

// Only use Bluetooth to send .apk 
intent.setPackage("com.android.bluetooth"); 

// Append file and send Intent 
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filePath))); 
startActivity(Intent.createChooser(intent, "Share app")); 
0
ArrayList<Uri> uris = new ArrayList<Uri>(); 
    Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE); 
sendIntent.setType("*/*"); 
uris.add(Uri.fromFile(new File(getApplicationInfo().publicSourceDir))); 
sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); 
startActivity(Intent.createChooser(sendIntent, null)); 

उपयोग / यह मेरे लिए काम किया

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