【发布时间】:2017-08-04 13:11:11
【问题描述】:
我正在慢慢尝试在Android Studio 中做一些简单的任务。以下应用程序安装在模拟器上,没有任何错误。但是当我尝试在真机 Redmi 3S 上安装它时,出现了这个错误:
Unknown failure (Failure - not installed for 0)
Error while Installing APKs
我在这里遇到了类似的问题,但在这些情况下,错误是由于未启用调试或不接受应用安装引起的。但是,我允许调试,并且我还尝试在 Studio 中安装 其他一些应用程序,它运行良好。
所以问题可能是,代码有什么问题。
MainActivity.java
package tlacitko.button;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void sendMessage(View view) {
new Thread(new Runnable() {
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
try{
URL url = new URL("http://147.32.186.51:8080");
// HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
InputStream is = url.openStream();
BufferedReader br = new BufferedReader(new
InputStreamReader(is));
String s = "";
}catch(MalformedURLException ex){
}catch(IOException e){
}
}
});
}
}).start();
}
}
还有xml代码:
activity_main.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Try to connect the server."
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="7dp"
android:layout_marginTop="16dp"
android:onClick="sendMessage"
android:text="Conncect"
app:layout_constraintLeft_toRightOf="@+id/editText"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
【问题讨论】:
-
请检查是否存在同名应用程序,如果有请卸载重试。
-
重建并运行
-
@ShantoGeorge 没有同名的应用。
-
我没有看到上面的代码有任何明显错误,请确认您的应用程序 manifest.xml 文件不是导致应用程序无法安装的原因,确保所有最低版本都设置为您的设备,并且该设备允许安装未知的 apk 文件。
-
@diegeelvis_SA 已解决。谢谢你。允许的 xml 和未知 apk 没有任何问题。
标签: java android android-studio failed-installation