mrmitew / RxWifiP2pManager

An RxJava wrapper for Android's WifiP2pManager, allowing you to use reactive APIs to manage Wi-Fi peer-to-peer connectivity (DEPRECATED)
28 stars 9 forks source link

Unable to install the library #1

Closed ParagRKadam closed 7 years ago

ParagRKadam commented 7 years ago

I created a new project and added the following lines in my gradle file:-

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.1'
    compile 'com.android.support:design:25.1.1'
    testCompile 'junit:junit:4.12'

    compile project(":library")
    compile 'io.reactivex:rxjava:1.2.1'
    compile 'io.reactivex:rxandroid:1.2.1'
    compile 'com.cantrowitz:rxbroadcast:1.1.0'
}

Along with that I have also added the "library" project alongside the folder "app". When I sync the project it gives error saying :-

Error:(33, 0) Project with path ':library' could not be found in project ':app'.

How do I install this library?

mrmitew commented 7 years ago

Hello @ParagRKadam,

First of all, thank you for considering using my library. To make use of it, you will need to add it as an additional module to your existing project. One way to do that is to clone the "library" folder to the root folder of your project, eg: /home/user/projects/my project/. You can name the "library" folder name to anything you would like to. Then, you need to append your settings.gradle with , ':library-folder-name:. The settings.gradle file will look at the end something on the lines of: include ':app', ':library'. Next, you need to add compile project(":library") and compile 'io.reactivex:rxjava:1.2.1' to your gradle dependencies in build.gradle of your app's module - just like you already did. RxAndroid and RxBroadcast are not necessary if you are not planning on using them in addition.

Please note that this library is using RxJava v1.x and not v2.x. If you are not familiar with the differences, you can them here. Not too long time ago I built the library from scratch using RxJava v2.x for one of my new projects, but I haven't found enough free time to make it available to everyone. If you are interested in using it, I will push myself to release a beta version in the very near future.

If this answer resolved your problem, please close the issue. Should you have other questions, please do not hesitate to ask.

Thanks! :)

ParagRKadam commented 7 years ago

Thank you for the swift reply, really appreciated :) I did not get the following that you said as I find it a bit unclear:-

Then, you need to append your settings.gradle with , ':library-folder-name:. The settings.gradle file will look at the end something on the lines of: include ':app', ':library'.

If I append my settings.gradle with ':library-folder-name: then how can my setting.gradle look like this in the end?

include ':app', ':library'

And also what is the additional 'folder-name' meant for?

Anyways, my settings.gradle look like this now:-

include ':app', ':library'

and have i have also put the following dependencies in my app level gradle file:-

compile project(":library")
compile 'io.reactivex:rxjava:1.2.1'

However now it gives a new error:-

Error:Circular reference between projects: :library -> :library

Can you please help me get rid of it. Thanks.

ParagRKadam commented 7 years ago

Hi Sir the problem got solved. There was compile project(":library") line in the gradle file of the library itself that induced the circular dependency. Removing that line solved it. Thanks.

mrmitew commented 7 years ago

I am glad to find out that all's good now :)

On Mon, Apr 17, 2017, 13:44 ParagRKadam notifications@github.com wrote:

Closed #1 https://github.com/mrmitew/RxWifiP2pManager/issues/1.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/mrmitew/RxWifiP2pManager/issues/1#event-1044892319, or mute the thread https://github.com/notifications/unsubscribe-auth/AIJtqyU2S1y2DyUODiYV6Fhk4ds8SKlCks5rw1CggaJpZM4M_CJQ .

--

Kind regards, Stefan Mitev

ParagRKadam commented 7 years ago

Hi Sir, I have a special requirement and want to cross check with you if this library can fulfill the requirement. I am developing a app which will turn the phone's hotspot on/off. When the hotspot is on the app will display a list of all the available devices who have their Wifi turned on, it may or may not be connected to the hotspot still it should appear in the list. Is this possible with this library? If not then is there any way you know this can be achieved? Thanks.

mrmitew commented 7 years ago

It is possible. Just use the functionality to discover all nearby devices :) - this will include all devices regardless if they have been paired with your phone or not.

ParagRKadam commented 7 years ago

After implementing your suggestion ,this is the code i have come up with:-


import android.content.Context;
import android.net.wifi.p2p.WifiP2pManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import com.stetcho.rxwifip2pmanager.data.wifi.RxWifiP2pManager;
import com.stetcho.rxwifip2pmanager.data.wifi.broadcast.factory.WifiP2pBroadcastObservableManagerFactory;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class MainActivity extends AppCompatActivity {

RxWifiP2pManager rxWifiP2pManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        rxWifiP2pManager = new RxWifiP2pManager(
                getApplicationContext(),
                (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE),
                new WifiP2pBroadcastObservableManagerFactory(getApplicationContext()));

        rxWifiP2pManager.discoverAndRequestPeersList()
                .timeout(5, TimeUnit.SECONDS) // Optional, but recommended
                .subscribeOn(Schedulers.computation())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(wifiP2pDeviceList -> Log.d("log", Arrays.toString(wifiP2pDeviceList.getDeviceList().toArray())));
    }
}

This code gives me the following error:-

FATAL EXCEPTION: main
  Process: com.abc.test, PID: 17571
  java.lang.IllegalStateException: Exception thrown on Scheduler.Worker thread. Add `onError` handling.
      at rx.android.schedulers.LooperScheduler$ScheduledAction.run(LooperScheduler.java:112)
      at android.os.Handler.handleCallback(Handler.java:739)
      at android.os.Handler.dispatchMessage(Handler.java:95)
      at android.os.Looper.loop(Looper.java:158)
      at android.app.ActivityThread.main(ActivityThread.java:7229)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
   Caused by: rx.exceptions.OnErrorNotImplementedException
      at rx.Single$12.onError(Single.java:1578)
      at rx.internal.operators.SingleObserveOn$ObserveOnSingleSubscriber.call(SingleObserveOn.java:84)
      at rx.android.schedulers.LooperScheduler$ScheduledAction.run(LooperScheduler.java:107)
      at android.os.Handler.handleCallback(Handler.java:739) 
      at android.os.Handler.dispatchMessage(Handler.java:95) 
      at android.os.Looper.loop(Looper.java:158) 
      at android.app.ActivityThread.main(ActivityThread.java:7229) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
   Caused by: java.util.concurrent.TimeoutException
      at rx.Single.timeout(Single.java:2088)
      at rx.Single.timeout(Single.java:2012)
      at com.abc.test.MainActivity.onCreate(MainActivity.java:33)
      at android.app.Activity.performCreate(Activity.java:6876)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350)
      at android.app.ActivityThread.access$1100(ActivityThread.java:222)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:158) 
      at android.app.ActivityThread.main(ActivityThread.java:7229) 
      at java.lang.reflect.Method.invoke(Native Method)
ParagRKadam commented 7 years ago

The exception comes after timeout i.e. after 5 seconds.