davidgyoung / android-beacon-library-reference-kotlin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lauching app is no working ? :(

wirteEable opened this issue · comments

commented

by useing code
...
public class AndroidProximityReferenceApplication extends Application implements MonitorNotifier {
private static final String TAG = "AndroidProximityReferenceApplication";

public void onCreate() {
    super.onCreate();
    Region region = new Region("com.example.backgroundRegion",
            Identifier.parse("2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6"), null, null);
    BeaconManager.getInstanceForApplication(this).startMonitoring(region);
    BeaconManager.addMonitorNotifier(this);
}

@Override
public void didEnterRegion(Region arg0) {
    Log.d(TAG, "did enter region.");
    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    // Important:  make sure to add android:launchMode="singleInstance" in the manifest
    // to keep multiple copies of this activity from getting created if the user has
    // already manually launched the app.
    this.startActivity(intent);
}

...
}

@wirteEable I think you may have added this issue agains the wrong Github repo.

The code you reference is not part of this Github repository. This is the Kotlin reference app for Android. The code you reference isn't even Kotlin -- it's Java, so perhaps you started with that reference app here, although even that repo does not have any sample code that show launching an activity on didEnterRegion.

I do see that you are trying to call startActivity on beacon detection. Please note that this is disallowed from the background as of Android 10 -- so this is no longer possible.

The Java reference app used to have a sample that showed how to do it, but I removed it awhile ago since it no longer works. If you see that sample still posted somewhere today, please let me know.

I recommend you start out with a clean copy of the java reference app at the link above which doesn't have such code to launch an activity from the background. if you find an problem with that reference app as-is, you can open an issue in that repo.