2015-09-10 6 views
5

का उपयोग करते समय ईपीआईपीई (टूटा हुआ पाइप) हैलो मैंने प्रक्रिया के माध्यम से अपने ऐप के अंदर ऐप इंस्टॉल करने का प्रयास किया। उस समारोह के लिए मैंने इस विधि को बनाया है।एंड्रॉइड। लिखने में असफल रहा: प्रक्रिया

private void loadAndInstallApk(String string) { 
    if(!isRooted()){ 
     return; 
    } 
    Uri uri = loadApk(string); 
    if(uri == null){ 
     return; 
    } 
    Process p = null; 
    DataOutputStream outs = null; 
    try 
    { 

     p = Runtime.getRuntime().exec(new String[]{"su", "-c", "system/bin/sh"}); 
     outs=new DataOutputStream(p.getOutputStream()); 

     String cmd="pm install -r " + uri.getPath(); 
     Log.d(TAG, "DATA = cmd = " + cmd); 
     outs.writeBytes(cmd + "\n"); 

     // Close the terminal 
     outs.writeBytes("exit\n"); 
     outs.flush(); 
      p.waitFor(); 
      if (p.exitValue() != 255) { 
       Log.d(TAG, "DATA succerss " + p.exitValue()); 
       // Sucess 
      } 
      else { 
       Log.d(TAG, "DATA Fail " + p.exitValue()); 
       // Fail 
      } 
     } 
    catch (IOException e){ 
     Log.e("Error", e.toString(), e); 
    } catch (InterruptedException e) { 
     Log.e("Error", e.toString(), e); 
    } finally { 
     if(outs != null) { 
      try { 
       outs.close(); 
      } catch (IOException e) { 
       Log.d(TAG, e.toString(), e); 
      } 
     } 
     try { 
      File f = new File(uri.getPath()); 
      f.delete(); 
     }catch (NullPointerException e) { 

      Log.e(TAG, "DATA = finally delete " + e.toString(), e); 
     } 
    } 
} 

लेकिन यह विफल रहता है, जब यह कहता है

 outs.writeBytes(cmd + "\n"); 

त्रुटि संदेश:

E/Error﹕ java.io.IOException: write failed: EPIPE (Broken pipe) 
java.io.IOException: write failed: EPIPE (Broken pipe) 
     at libcore.io.IoBridge.write(IoBridge.java:455) 
     at java.io.FileOutputStream.write(FileOutputStream.java:187) 
     at java.io.OutputStream.write(OutputStream.java:82) 
     at java.io.DataOutputStream.writeBytes(DataOutputStream.java:156) 
... 
Caused by: libcore.io.ErrnoException: write failed: EPIPE (Broken pipe) 
     at libcore.io.Posix.writeBytes(Native Method) 
     at libcore.io.Posix.write(Posix.java:202) 
     at libcore.io.BlockGuardOs.write(BlockGuardOs.java:197) 
     at libcore.io.IoBridge.write(IoBridge.java:450) 
     at java.io.FileOutputStream.write(FileOutputStream.java:187) 
     at java.io.OutputStream.write(OutputStream.java:82) 
     at java.io.DataOutputStream.writeBytes(DataOutputStream.java:156) 

बजाय

Runtime.getRuntime().exec(new String[]{"su", "-c", "system/bin/sh"}); 

मैंने कोशिश की:

012,351,
Runtime.getRuntime().exec("su"); 

इससे मदद नहीं मिली।

यह कोड मेरे रूट टैबलेट के लिए भी काम करता है लेकिन यह मेरे टीवी बॉक्स के लिए काम नहीं करता है।

मैं विधियों के माध्यम से जड़ पर डिवाइस की जांच:

private static boolean isRooted() { 
    return findBinary("su"); 
} 

public static boolean findBinary(String binaryName) { 
    boolean found = false; 
    if (!found) { 
     String[] places = {"/sbin/", "/system/bin/", "/system/xbin/", "/data/local/xbin/", 
       "/data/local/bin/", "/system/sd/xbin/", "/system/bin/failsafe/", "/data/local/"}; 
     for (String where : places) { 
      Log.d(TAG, "DATA where = " + where); 
      if (new File(where + binaryName).exists()) { 
       found = true; 
       break; 
      } 
     } 
    } 
    return found; 
} 

यह सच लौट आते हैं।

उत्तर

-5

मुझे एक समाधान मिला। समस्या यह थी कि मेरे डिवाइस में "su" कमांड

+0

वास्तव में एक और आदेश है? यह आपके सवालों का जवाब है? क्या आप अधिक विशिष्ट हो सकते हैं? –

+0

@ उपयोगकर्ता 951793 हां, यह कोशिश करें। मैं निर्माता से जुड़ा हूं (जैसा कि मैंने बिल्कुल डिवाइस के लिए ऐप बनाया है, इसलिए मैं उनके संपर्क में रह सकता हूं) और जैसा कि यह निकला कि "सु" के बजाय एक और कमांड था (क्षमा करें, मैं यह आदेश यहां नहीं लिख सकता, क्योंकि मैं नहीं कर सकता इस डेटा की व्याख्या) – Dima

+0

क्या आप निर्माता का उल्लेख कर सकते हैं – iSandeep

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