私はゆっくりとAndroid Studio
でいくつかの簡単な作業をしようとしています。以下のアプリはエミュレータ上では何のエラーもなくインストールされています。しかし、実際のデバイスであるRedmi 3Sにインストールしようとすると、このエラーが発生しました。
Unknown failure (Failure - not installed for 0)
Error while Installing APKs
このサイトでも似たような質問がありましたが、これらのケースでは、デバッグを有効にしていないか、アプリのインストールを許可していないことがエラーの原因でした。しかし、私はデバッグを許可し、スタジオで他のアプリをインストールしようとしましたが、正常に動作しました。
ですから、おそらく質問は、コードのどこが間違っているのかということです。
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のコード。 xmlコード: >Activity_main.xml <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"。 xmlns:tools="http://schemas.android.com/tools"。 android:layout_width="match_parent" android:layout_height="match_parent" tools:context="tlacitko.button.MainActivity">
<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>
以下の手順で問題を解決してください。
1.システムに接続されているすべてのデバイスを切断し、システム上で動作しているすべてのエミュレーターを終了します。 2.設定からInstant Run機能をオフにします。 3.クリーンビルドを行う。 4.設定からInstant Run機能をオンにする。 5.クリーン・ビルドを行う。 6.デバイスを接続し、エミュレータを起動し、オンラインであることを確認します。 7.デバイス/エミュレータを選択してプロジェクトを実行します。
注:。
システム上でAndroid Debug Bridge(adb)が複数起動していてはいけません。
Genymotionを使用している場合は、Genymotionの設定に記載されているカスタムsdkのパスをAndroid Studioの設定に記載されているものを使用するようにしてください。
以上の手順で問題は解決すると思われますが、アンドロイドのバージョンによっては問題が発生する場合があります。