[英]Cannot build Flutter app on iOS emulator or physical device - works fine on Android though
[英]Android App gets stuck on splashscreen when launched on physical device but works fine when on an emulator
當我在物理設備(huawei.Android版本4.4.2)上運行該應用程序時,它運行良好,但掛在初始屏幕上。當我使用模擬器(Nexus 5 API 24)時,它將啟動初始屏幕,然后轉到登錄活動屏幕。可能是什么問題?
我的飛濺活動
public class SplashActivity extends AppCompatActivity {
GPSTracker gpsTracker;
protected static final int REQUEST_CHECK_SETTINGS = 0x1;
boolean permission=false;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
getDeviceToken();
getpermission();
gpsTracker = new GPSTracker(this, this);
permission= SharedPreferenceWriter.getInstance(this).getBoolean(SharedPreferenceKey.permission_granted_location,false);
LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
boolean statusOfGPS = manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (statusOfGPS) {
if (permission) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (SharedPreferenceWriter.getInstance(SplashActivity.this).getBoolean(SharedPreferenceKey.currentLogin, false)) {
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
} else {
startActivity(new Intent(SplashActivity.this, Login.class));
finish();
}
}
}, 2000);
} //else
//Toast.makeText(SplashActivity.this,"permission not granted",Toast.LENGTH_LONG).show();
}else
new StartLocationAlert(SplashActivity.this);
}
private void getpermission() {
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
requestPermissionforApp();
}
}
private void requestPermissionforApp() {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, android.Manifest.permission.ACCESS_FINE_LOCATION)) {
Toast.makeText(this, "Current Location needed. Please allow in App Settings for additional functionality.", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", getPackageName(), null));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, 123);
}
}
private void getDeviceToken() {
final Thread thread = new Thread() {
@Override
public void run() {
Log.e(">>>>>>>>>>>>>>", "thred IS running");
SharedPreferenceWriter mPreference = SharedPreferenceWriter.getInstance(getApplicationContext());
try {
if (mPreference.getString(SharedPreferenceKey.device_token).isEmpty()) {
String token = FirebaseInstanceId.getInstance().getToken();
// String token = android.provider.Settings.Secure.getString(getApplicationContext().getContentResolver(),
// android.provider.Settings.Secure.ANDROID_ID);
Log.e("Generated Device Token", "-->" + token);
if (token == null) {
getDeviceToken();
} else {
mPreference.writeStringValue(SharedPreferenceKey.device_token, token);
}
}
} catch (Exception e1) {
e1.printStackTrace();
}
super.run();
}
};
thread.start();
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
try {
if (requestCode == 123) {
int lenght = grantResults.length;
for (int grantlength = 0; grantlength < grantResults.length; grantlength++) {
if (grantResults[grantlength] == PackageManager.PERMISSION_GRANTED) {
getDeviceToken();
SharedPreferenceWriter.getInstance(this).writeBooleanValue(SharedPreferenceKey.permission_granted_location, true);
gpsTracker = new GPSTracker(this, SplashActivity.this);
startActivity(new Intent(SplashActivity.this, Login.class));
finish();
} else if (grantResults[grantlength] == PackageManager.PERMISSION_DENIED) {
boolean b = ActivityCompat.shouldShowRequestPermissionRationale(this, permissions[grantlength]);
if (!b) {
requestPermissionforApp();
} else {
requestPermissionforApp();
}
} else {
requestPermissionforApp();
}
}
} else {
requestPermissionforApp();
}
} catch (ArrayIndexOutOfBoundsException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
final LocationSettingsStates states = LocationSettingsStates.fromIntent(data);
switch (requestCode) {
case REQUEST_CHECK_SETTINGS:
switch (resultCode) {
case Activity.RESULT_OK: {
// showDialog();
//new SplashActivity();
//gpsTracker = new GPSTracker(this, SplashActivity.this);
if (SharedPreferenceWriter.getInstance(SplashActivity.this).getBoolean(SharedPreferenceKey.currentLogin,false))
{
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}else {
startActivity(new Intent(SplashActivity.this, Login.class));
finish();
}
// All required changes were successfully made
break;
}
case Activity.RESULT_CANCELED: {
new StartLocationAlert(SplashActivity.this);
// The user was asked to change settings, but chose not to
break;
}
default: {
break;
}
}
break;
}
}
}
我的清單文件:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
<uses-feature
android:name="android.hardware.camera"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/app_logo"
android:label="@string/app_name"
android:largeHeap="true"
android:roundIcon="@drawable/app_logo"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name="android.support.multidex.MultiDexApplication"
>
<activity
android:name="com.sats.quickeats.activities.SplashActivity"
android:theme="@style/TranparentToolbar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="com.sats.quickeats.activities.SignUp"
android:theme="@style/TranparentToolbar"
android:windowSoftInputMode="stateVisible|adjustResize"/>
<activity
android:name="com.sats.quickeats.activities.Otp"
android:theme="@style/TranparentToolbar"/>
<activity
android:name="com.sats.quickeats.activities.MainActivity"
android:windowSoftInputMode="adjustPan"/>
<activity android:name="com.sats.quickeats.activities.MapDrawerActivity"/>
<activity android:name="com.sats.quickeats.activities.Description"/>
<activity android:name="com.sats.quickeats.activities.FoodMenu"/>
<activity android:name="com.sats.quickeats.activities.MyKart"/>
<activity android:name="com.sats.quickeats.activities.UserAddress"/>
<activity android:name="com.sats.quickeats.activities.PaymentMode"/>
<activity android:name="com.sats.quickeats.activities.FacebookLogin"/>
<activity android:name="com.sats.quickeats.activities.GoogleLogin"/>
<activity android:name="com.sats.quickeats.activities.MapForPayment"/>
<activity android:name="com.sats.quickeats.activities.Login"/>
<activity android:name="com.sats.quickeats.activities.CreditCard"/>
<activity
android:name="com.sats.quickeats.activities.PaymentBackground"
android:theme="@style/TranparentToolbar"
android:windowSoftInputMode="stateVisible|adjustResize"/>
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/app_id"/>
<!-- <meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/release_key" />-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/release_key"/>
<activity
android:name="com.sats.quickeats.activities.SearchMap"
android:label="@string/title_activity_search_map"/>
<activity android:name="com.sats.quickeats.activities.Settings"/>
<activity android:name="com.sats.quickeats.activities.WebviewActivity"/>
<activity android:name="com.sats.quickeats.activities.ChangePassword"/>
<activity android:name="com.sats.quickeats.activities.ContactUs"/>
<activity android:name="com.sats.quickeats.activities.Notification"/>
<activity android:name="com.sats.quickeats.activities.MyFav"/>
<activity android:name="com.sats.quickeats.activities.MapForOrderDispatch"/>
<activity android:name="com.sats.quickeats.activities.MapRouteAct"/>
<activity android:name="com.sats.quickeats.activities.TakeImage"/>
<activity
android:name="com.sats.quickeats.util.TakePhoto"
android:hardwareAccelerated="false"/>
<activity
android:name="com.sats.quickeats.activities.ForgotPass"
android:theme="@style/TranparentToolbar"/>
<activity android:name="com.sats.quickeats.activities.SearchFilter"/>
<activity
android:name="com.sats.quickeats.activities.ResetPass"
android:theme="@style/TranparentToolbar"/>
<service android:name="com.sats.quickeats.fcm.MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<service android:name="com.sats.quickeats.fcm.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<meta-data
android:name="io.fabric.ApiKey"
android:value="44b5915daf7330d0de425de1d6bc82af9e2d242a"/>
<receiver
android:name="com.sats.quickeats.activities.DeliveryBoytStatus"
android:process=":remote"/>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.sats.quickeats.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
</provider>
<!--<provider-->
<!--android:name="android.support.v4.content.FileProvider"-->
<!--android:authorities="com.mobulous.restaurantapp.fileprovider"-->
<!--android:exported="false"-->
<!--android:grantUriPermissions="true"-->
<!--tools:replace="android:authorities">-->
<!--<meta-data-->
<!--android:name="android.support.FILE_PROVIDER_PATHS"-->
<!--android:resource="@xml/file_paths"-->
<!--tools:replace="android:resource"/>-->
<!--</provider>-->
<!--android:name="com.sats.quickeats.util.RestroApplication"-->
</application>
</manifest>
謝謝你的幫助。
您尚未在設置中啟用GPS,
boolean statusOfGPS = manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
如果未開啟gps,這將返回false
,並且由於if(statusOfGPS)
,您將陷入初始屏幕活動中。 打開設備上的GPS,一切正常。 使您在manifest
文件中具有必需的權限。
您還可以使用manager.isLocationEnabled()
來檢查位置的當前狀態。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.