Is Android WifiP2pManager.discoverServices able to discover NsdServiceInfo (by NsdManager.registerService)?
step 1:
nsdManager.registerService(serviceInfo, NsdManager.PROTOCOL_DNS_SD, registrationListener);
step 2:
p2pManager.discoverServices(p2pChannel, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
...
}
@Override
public void onFailure(int code) {
...
}
});
So, is step 2 able to discover step 1's service?
See also questions close to this topic
-
How refresh listview when click button?
I have 3 classes: MainMenu, GoToProfiles, AddProfile.
Can you tell me how can I refresh (ListView) lv when i click (Button) add in my AddProfile class?
If you have any question just let me know, thanks!
MainMenu:
public class MainMenu extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_menu); displaySelectedScreen(R.id.today); navigationView.setNavigationItemSelectedListener(this); } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_close) { ActivityCompat.finishAffinity(this); } return super.onOptionsItemSelected(item); } private void displaySelectedScreen(int id) { Fragment fragment = null; switch(id) { case R.id.today: fragment = new GoToMain(); break; case R.id.listOfProfiles: fragment = new GoToProfiles(); break; } if(fragment != null) { FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.content_main, fragment); fragmentTransaction.commit(); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); switch(id) { case R.id.listOfProfiles: break; } } @SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { displaySelectedScreen(item.getItemId()); return true; } }
GoToProfiles:
public class GoToProfiles extends Fragment { @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); getActivity().setTitle("Profile list"); } @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View v = inflater.inflate(R.layout.profiles, container, false); fabz = (FloatingActionButton) v.findViewById(R.id.fabProfile); fabz.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent cel = new Intent(v.getContext(), AddProfile.class); startActivity(cel); } }); results = new ArrayList<String>(); lv = (ListView) v.findViewById(R.id.profileList); myDb = new DatabaseHelper(getActivity()); Cursor c = myDb.getAllData(); if(c.getCount() == 0) { Toast.makeText(getActivity(), "Baza danych jest pusta", Toast.LENGTH_LONG).show(); } else { while(c.moveToNext()) { results.add(c.getString(1)); adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, results); lv.setAdapter(adapter); } } return v; } }
AddProfile:
public class AddProfile extends AppCompatActivity { DatabaseHelper myDb; private static final String TAG = "AddProfile"; private Button add; private EditText txt; @Override protected void onCreate(Bundle savedInstanceState) { myDb = new DatabaseHelper(this); super.onCreate(savedInstanceState); setContentView(R.layout.add_profile); add = (Button) findViewById(R.id.adBut); txt = (EditText) findViewById(R.id.namField); add.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(txt.getText().length()>0) { myDb.insertData(txt.getText().toString()); onBackPressed(); } } }); } @Override public void onBackPressed() { super.onBackPressed(); finish(); } }
codetestcodetestcodetestcodetestcodetestcodetestcodetestcodetestcodetestcodetest
-
Android studio singed android app not installing
I am very new to android development and just made my first practice app it is a tic tac toe game, it runs well on emulator, but i try to install and run it on my mobile that is running android 7.1.1 i generate a signed apk with the release option selected
plays nice on emulator
but the i try to make an apk
generating a signed apk
with the release option selected
apk generated
But when i try to install on my mobile device it shows Problem parsing the package
This is the emulator that i am using, it shows x86 in cpu/ABI does that have to do with anything ?
my mobile device has a Cortex-A53 processor does that have to do with anything ?
goggling doesn't give an proper answer to this, any help would be appreciated thanks.
-
SearchView gets focus but does not show keyboard
I use the following code to implement a SearchView within the ActionBar:
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_songbook_filter, menu); MenuItem item = menu.add(getString(R.string.action_search)); item.setIcon(R.drawable.ic_action_search); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); mSearchView = new FilterSearchView(getActivity()); mSearchView.setOnQueryTextListener(this); mSearchView.setOnCloseListener(this); mSearchView.setIconifiedByDefault(false); item.setActionView(mSearchView); } @Override public void onPrepareOptionsMenu(Menu menu) { mSearchView.requestFocus(); mSearchView.requestFocusFromTouch(); mSearchView.setFocusable(true); }
This results in the following SearchView:
When I touch the magnifier glass icon, focus is given to the text field as expected. The cursor is inside the text field and is blinking (which is correct). It looks like this:
But the strange thing is, the soft keyboard is not opening up. So the user has to click into the text field again in order to see the keyboard come up. I want the user to have the keyboard up with a single click onto the magnifier glass icon. What is wrong here?
-
how can send and receive data along multiple devices without using any server or external network ?
I am creating an app in which I want to add some details. Now the same app is using some more users in their android devices. So I want that what ever i add in my app that data should be visible to every user in their device. But the problem is i can not use any server but i can use wifi , So is there any way to implement my idea.If it is please help to to do this.
I have seen something here related my idea. Demo app for WiFiP2P data sharing in android
-
in WifiP2pGroup, how to set passphrase for myself
I plant below api to my code and make app.
https://android.googlesource.com/platform/frameworks/base/+/cd92588/wifi/java/android/net/wifi/p2p
But I want to set passphrase for myself, but in WifiP2pGroup.java, setPassphrase is set hide, and even if I use setPassphrase function(I found android.jar which hide functions are opened), I can't change it for myself.
The question is I want to make my wifi for public(no passphrase), if I can't, I want to make passphrase to 00000000.
How can I do that?
import android.annotation.SuppressLint; import android.content.Context; import android.net.wifi.WifiConfiguration; import android.net.wifi.p2p.IWifiP2pManager; import android.net.wifi.p2p.WifiP2pGroup; import android.net.wifi.p2p.WifiP2pManager; import android.util.Log; import android.widget.Toast; public final class WifiDirectShare { private final String TAG = getClass().getSimpleName(); private Context applicationContext; private WifiP2pManager p2pManager; private WifiP2pManager.Channel channel; private GroupCreatedListener listener; public WifiDirectShare(Context context, GroupCreatedListener listener) { this.listener = listener; applicationContext = context.getApplicationContext(); } public void start() { initP2p(applicationContext); startP2pGroup(); } public void stop() { try { p2pManager.removeGroup(channel, new WifiP2pManager.ActionListener() { @Override public void onSuccess() { Log.i(TAG, "P2p removeGroup success"); } @Override public void onFailure(int reason) { Log.i(TAG, "P2p removeGroup failed. Reason : "+reason); } }); } catch (Exception e) {/*ignore*/} } @SuppressLint("ServiceCast") private void initP2p(Context context) { if (this.p2pManager == null || this.channel == null) { this.p2pManager = (WifiP2pManager) context.getSystemService(Context.WIFI_P2P_SERVICE); this.channel = this.p2pManager.initialize(applicationContext, context.getMainLooper(), new WifiP2pManager.ChannelListener() { public void onChannelDisconnected() { Log.i(TAG, "P2p channel initialization failed"); } }); } } private void startP2pGroup() { Thread createGroupThread = new Thread(createGroupRunnable); createGroupThread.start(); } private Runnable createGroupRunnable = new Runnable() { @Override public void run() { p2pManager.createGroup(channel, new WifiP2pManager.ActionListener() { public void onFailure(int error) { Log.i(TAG, "createGroup failed. Error code : "+error); } public void onSuccess() { p2pManager.requestGroupInfo(channel, groupInfoListener); } }); } }; private WifiP2pManager.GroupInfoListener groupInfoListener = new WifiP2pManager.GroupInfoListener() { public void onGroupInfoAvailable(WifiP2pGroup group) { if (group != null) { if(group.isGroupOwner()) { Log.i(TAG, "group created with ssid = "+group.getNetworkName() + "\n and password = "+group.getPassphrase()); if(listener != null) listener.onGroupCreated(group.getNetworkName(), group.getPassphrase()); } } else p2pManager.requestGroupInfo(channel, groupInfoListener); } }; public interface GroupCreatedListener { void onGroupCreated(String ssid, String password); } }
mainActivity call part
share = new WifiDirectShare(MainActivity.this, this); share.start();
-
Android Wi-Fi Direct completely remove a connection then new connection
I am developing a Wi-FI Direct android app, I can connect and share information with 2 device. So discover peers and connection with a peer and data share are working.
I have to do a "random walk" with 10 device, so I have to connect 2 random device over and over again.
The problem is, 2 device connected successfully then removeGroup, after this one of these devices cant connect with the other 8 device. The other problem is they might cant discover peers after connection. So after a successfull connection the devices have to be ready for a new connection.
I think the real problem is, how to completely remove a connection with the other peer and then rediscover peers.
Can someone give me advice on how to completely remove a connection with the other peer?
Thanks
-
I need to develop an Android app will be connect to nearby devices
Please advise me the way .. I need to develop an Android application will be installed on many devices, for example in the university range .. This application has a main function and I have no problem in programming it .. But the application needs to be connected in the background between all versions of the application installed on all devices To share the information of the main function of each device .. Please advise me on the easiest options to let the application versions be connected without an external internet .. and thank you very much
-
Android Pixel 2 (8.1) DNS service discovery failure
Observing issue in discovering service of iOT device in Pixel 2.
OS 8.1 in other devices like Nexus / Pixel 1 find the serviceType with no issues.
Using NSD serviceDiscovery() , the log gets displays for Service Discovery Started. But its not finding the service (_customName._tcp.)
Has anyone faced such issue with Pixel 2 device?
-
NSD discovery not finding anything in Motog3 API 23
I'm having a strange behaviour in a MotoG3(API 23) device when doing the Nsd discovery. Both the discovery from NsdManager and the library https://github.com/andriydruk/RxDNSSD are not discovering any service.
I verified services are available in the network that the device is connected to. When trying the same thing in a device with Android N the discovery works well. Most importantly this discovery worked previously and it suddenly stopped working. I think something in the network could've changed but I do not know what it is.
Also trying the search on another network with services worked well in original device. So it is possible that some configuration of the network makes the discovery in the MotoG3(API 23) not find anything. Can't determine if it is a device or a API problem because I do not have a different device with same API to test this on.
To verify it was not an implementation mistake I downloaded ZeroConf Browser and it wasn't able to find services.
So my question is: Does anybody know what could be the cause of this or if there is any solution to make it work?