Good day, I followed the code on github and had trouble changing the page to ListNearablesActivity.java
How change it to when start application, the 1st page is ListNearablesActivity. Currently, the starting page is AllDemosActivity.java. I tried removing the file for AllDemosActivity.java but it didn’t work for me. By the way I dont’t want the page on AllDemosActivity.java. When I make edits to the manifest, it kept giving me problems, when I click on the nearables(stickers) on the ListNearablesActivity.java page, it kept stopping.
My current codes:
AndroidManifest.xml
<application
android:label="Estimote Demos - Detect Motion and Temperature"
android:theme="@style/EstimoteTheme">
<activity
android:name=".AllDemosActivity"
android:label="Select Beacon"
android:screenOrientation="landscape"/>
<activity
android:name=".ListNearablesActivity"
android:label="Select Beacon"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".NearablesDemoActivity"
android:label="Nearables Demo"
android:screenOrientation="landscape"/>
</application>
</manifest>
AllDemosActivity.java:
public class AllDemosActivity extends AppCompatActivity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.all_demos);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle(getTitle());
findViewById(R.id.nearables_demo_button).setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
Intent intent = new Intent(AllDemosActivity.this, ListNearablesActivity.class);
intent.putExtra(ListNearablesActivity.EXTRAS_TARGET_ACTIVITY, NearablesDemoActivity.class.getName());
startActivity(intent);
}
});
}
}
ListNearables.java:
public class ListNearablesActivity extends BaseActivity {
private static final String TAG = ListNearablesActivity.class.getSimpleName();
public static final String EXTRAS_TARGET_ACTIVITY = "extrasTargetActivity";
public static final String EXTRAS_NEARABLE = "extrasNearable";
private static final int REQUEST_ENABLE_BT = 1234;
private BeaconManager beaconManager;
private NearableListAdapter adapter;
private String scanId;
@Override
protected int getLayoutResId() {
return R.layout.main;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Configure device list.
adapter = new NearableListAdapter(this);
ListView list = (ListView) findViewById(R.id.device_list);
list.setAdapter(adapter);
list.setOnItemClickListener(createOnItemClickListener());
//Initialize Beacon Manager
beaconManager = new BeaconManager(this);
}
@Override
protected void onDestroy() {
beaconManager.disconnect();
super.onDestroy();
}
@Override
protected void onStart() {
super.onStart();
// Check if device supports Bluetooth Low Energy.
if (!beaconManager.hasBluetooth()) {
Toast.makeText(this, "Device does not have Bluetooth Low Energy", Toast.LENGTH_LONG).show();
return;
}
// If Bluetooth is not enabled, let user enable it.
if (!beaconManager.isBluetoothEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
} else {
connectToService();
}
}
@Override
protected void onStop() {
beaconManager.disconnect();
super.onStop();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_ENABLE_BT) {
if (resultCode == Activity.RESULT_OK) {
connectToService();
} else {
Toast.makeText(this, "Bluetooth not enabled", Toast.LENGTH_LONG).show();
toolbar.setSubtitle("Bluetooth not enabled");
}
}
super.onActivityResult(requestCode, resultCode, data);
}
private void connectToService() {
toolbar.setSubtitle("Scanning...");
adapter.replaceWith(Collections.<Nearable>emptyList());
beaconManager.setNearableListener(new BeaconManager.NearableListener() {
@Override
public void onNearablesDiscovered(List<Nearable> nearables) {
toolbar.setSubtitle("Found nearables: " + nearables.size());
adapter.replaceWith(nearables);
for (Nearable nearable : nearables) {
if (nearable.isMoving) {
try {
Class<?> clazz = Class.forName(getIntent().getStringExtra(EXTRAS_TARGET_ACTIVITY));
Intent intent = new Intent(ListNearablesActivity.this, clazz);
intent.putExtra(EXTRAS_NEARABLE, adapter.getItem(nearables.indexOf(nearable)));
startActivity(intent);
} //close for try
catch (ClassNotFoundException e) {
Log.e(TAG, "Finding class by name failed", e);
} //close for catch (ClassNotFoundException e)
}
}
} //for override
}); //for beaconManager.setNearable
beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
@Override
public void onServiceReady() {
scanId = beaconManager.startNearableDiscovery();
} //for onServiceReady
}); //for .connect
} //for private void connectToService
private AdapterView.OnItemClickListener createOnItemClickListener() {
return new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
if (getIntent().getStringExtra(EXTRAS_TARGET_ACTIVITY) != null){
try {
Class<?> clazz = Class.forName(getIntent().getStringExtra(EXTRAS_TARGET_ACTIVITY));
Intent intent = new Intent(ListNearablesActivity.this, clazz);
intent.putExtra(EXTRAS_NEARABLE, adapter.getItem(position));
startActivity(intent);
} //close for try
catch (ClassNotFoundException e) {
Log.e(TAG, "Finding class by name failed", e);
} //close for catch (ClassNotFoundException e)
} //close for getintent.getStringExtra()
} //close for public void onitemclick
}; //close for return new adapterview
} //close for private adapter
}