Check if google app is installed in LauncherActivity
This commit is contained in:
parent
a08269c7a5
commit
287c647073
|
@ -1,6 +1,8 @@
|
|||
package com.example.yink.amadeus;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.AnimationDrawable;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Bundle;
|
||||
|
@ -28,13 +30,17 @@ public class LaunchActivity extends AppCompatActivity {
|
|||
logo = (AnimationDrawable) imageViewLogo.getDrawable();
|
||||
logo.start();
|
||||
|
||||
if (!isAppInstalled(LaunchActivity.this, "com.google.android.googlequicksearchbox")) {
|
||||
status.setText(R.string.google_app_error);
|
||||
}
|
||||
|
||||
connect.setImageResource(R.drawable.connect_unselect);
|
||||
cancel.setImageResource(R.drawable.cancel_unselect);
|
||||
|
||||
connect.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (!isPressed) {
|
||||
if (!isPressed && isAppInstalled(LaunchActivity.this, "com.google.android.googlequicksearchbox")) {
|
||||
try {
|
||||
isPressed = true;
|
||||
MediaPlayer m = MediaPlayer.create(getApplicationContext(), R.raw.tone);
|
||||
|
@ -89,6 +95,8 @@ public class LaunchActivity extends AppCompatActivity {
|
|||
protected void onResume() {
|
||||
if (isPressed) {
|
||||
status.setText(R.string.disconnected);
|
||||
} else if (!isAppInstalled(LaunchActivity.this, "com.google.android.googlequicksearchbox")) {
|
||||
status.setText(R.string.google_app_error);
|
||||
} else {
|
||||
status.setText(R.string.call);
|
||||
}
|
||||
|
@ -97,4 +105,14 @@ public class LaunchActivity extends AppCompatActivity {
|
|||
cancel.setImageResource(R.drawable.cancel_unselect);
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
private static boolean isAppInstalled(Context context, String packageName) {
|
||||
try {
|
||||
context.getPackageManager().getApplicationInfo(packageName, 0);
|
||||
return true;
|
||||
}
|
||||
catch (PackageManager.NameNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<string name="call">Connect to Kurisu?</string>
|
||||
<string name="connecting">Connecting…</string>
|
||||
<string name="disconnected">Disconnected.</string>
|
||||
<string name="google_app_error">Google App wasn\'t detected.</string>
|
||||
<integer name="duration">40</integer>
|
||||
|
||||
<string name="line_hello">Hello.</string>
|
||||
|
|
Loading…
Reference in New Issue