toast message I DON'T WANT TO SHOW. is it possible? - android

My problem is: I need to pass present activity's context. and than toast message is shown. (when using external library that can not be edited)
When i pass my context. This always returns toast message.
But i don't want to show toast message.
Is it possible?
I'm using external MultiImagePicker library
here is my main code, just initialized. i do nothing.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Picker.Builder(this,new MyPickListener(),R.style.MIP_theme)
.setLimit(2)
.setPickMode(Picker.PickMode.MULTIPLE_IMAGES)
.build()
.startActivity();
}
private class MyPickListener implements Picker.PickListener
{
#Override
public void onPickedSuccessfully(final ArrayList<ImageEntry> images)
{
for(ImageEntry image : images){
Log.d("onPickedSuccessfully", "image.path #"+image.path);
}
}
#Override
public void onCancel(){
}
}
gradle(Module:app)
repositories {
maven { url 'https://dl.bintray.com/yazeed44/maven' }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'net.yazeed44.imagepicker:imagepicker:1.3.0'
}
I really appreciate any help.

Try this,
You can go to the library, open that class and remove toast from the onCancel method().
#Override
public void onCancel() {
Log.i(TAG, "User canceled picker activity");
}

Related

How to solve this error 'com.google.ads.mediation.admob.AdMobAdapter cannot be cast to com.google.android.gms.ads.mediation.m '?

am using firebase adapter in my project, now am integrate admob for rewarded ad it's working fine, but every video after completion it will throw following error...
java.lang.ClassCastException: com.google.ads.mediation.admob.AdMobAdapter cannot be cast to com.google.android.gms.ads.mediation.m
at com.google.android.gms.ads.internal.mediation.client.y.a(:com.google.android.gms.dynamite_dynamitemodulesa#12685008#12.6.85 (020306-197041431):262)
at com.google.android.gms.ads.internal.reward.c.b(:com.google.android.gms.dynamite_dynamitemodulesa#12685008#12.6.85 (020306-197041431):54)
at com.google.android.gms.ads.internal.reward.client.e.onTransact(:com.google.android.gms.dynamite_dynamitemodulesa#12685008#12.6.85 (020306-197041431):56)
at android.os.Binder.transact(Binder.java:380)
at com.google.android.gms.internal.ads.zzej.transactAndReadExceptionReturnVoid(Unknown Source)
at com.google.android.gms.internal.ads.zzahb.zze(Unknown Source)
at com.google.android.gms.internal.ads.zzahm.resume(Unknown Source)
at com.mopub.mobileads.GooglePlayServicesRewardedVideo$1.onResume(GooglePlayServicesRewardedVideo.java:84)
at com.mopub.common.MoPubLifecycleManager.onResume(MoPubLifecycleManager.java:83)
at com.mopub.common.MoPub.onResume(MoPub.java:257)
at com.coderays.realquiz.RealQuizDashBoard.onResume(RealQuizDashBoard.java:956)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1280)
at android.app.Activity.performResume(Activity.java:6096)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3011)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3063)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1361)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
i will try this method https://stackoverflow.com/a/49959522/6477998 but still throw this error.
my gradle is..
dependencies {
implementation('com.mopub:mopub-sdk-interstitial:5.0.0#aar') {
transitive = true
}
// For rewarded videos. This will automatically also include interstitials
implementation('com.mopub:mopub-sdk-rewardedvideo:5.0.0#aar') {
transitive = true
}
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-ads:15.0.1'
}
Which one to change, please give me a solution, am searching still 3 days but no improvement.
Advance thanx...
thanks, the error will be fixed after long time.
Step 1: i remove my adapter class GooglePlayServicesRewardedVideo.java from com.mopub.mobileads( if you are using GooglePlayServicesInterstitial.java please remove ).
Step 2: then, put admob mediation sdk into build.gradle i.e implementation 'com.mopub.mediation:admob:15.0.0.8'.
Step 3: then, remove the following lines in your rewarded display activity.
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MoPubRewardedVideos.initializeRewardedVideo(this);
MoPub.onCreate(this); // remove
// ...
}
#Override
public void onPause() {
super.onPause();
MoPub.onPause(this); // remove
}
#Override
public void onResume() {
super.onResume();
MoPub.onResume(this); // remove
}
// The following methods are required for Chartboost rewarded video mediation
#Override
public void onStart() {
super.onStart();
MoPub.onStart(this); // remove
}
#Override
public void onRestart() {
super.onRestart();
MoPub.onRestart(this); // remove
}
#Override
public void onStop() {
super.onStop();
MoPub.onStop(this); // remove
}
#Override
public void onDestroy() {
super.onDestroy();
MoPub.onDestroy(this); // remove
}
#Override
public void onBackPressed() {
super.onBackPressed();
MoPub.onBackPressed(this); // remove
}
}
Step 4 : syn your project, and take a build. Its working fine without error.
thanks.

zxing qr code scanner camera showing white screen

Good day! i'm having an issue with the qr code scanner in android marshmallow and nougat using the library that i have added as dependency in my project the camera shows white screen. Code runs perfectly in lollipop and kitkat. Please let me know if there was something i have missed or something i will do to make it work. I have paste my snippets of code down below. It is my pleasure if you give me some time to notice my concern. I have seen similar topic of my issue but it did not help me work out or i have implemented it wrong. Thank you in advance.
I have zxing jar library for generating qr code, and i used me.dm7.barcodescanner:zxing:1.8.4 for scanning qr codes:
dependency {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/zxing-2.1.jar')
compile('me.dm7.barcodescanner:zxing:1.8.4'){
exclude group: 'com.google.zxing'
}
}
The Activity for the opening of the camera:
public class ScanQRCodeActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler {
private String strDataEncrypted;
private ZXingScannerView mScannerView;
public static String strEncrypt;
public static String strEncrypted;
public static String strIV;
public static boolean isScanSuccess = false;
#Override
public void onCreate(Bundle state) {
super.onCreate(state);
mScannerView = new ZXingScannerView(this);
setContentView(mScannerView);
}
#Override
public void onResume() {
super.onResume();
mScannerView.setResultHandler(this);
mScannerView.startCamera();
}
#Override
public void onPause() {
super.onPause();
mScannerView.stopCamera();
}
#Override
public void handleResult(Result result) {
strDataEncrypted = result.getText();
Log.wtf("handleResult", strDataEncrypted);
String[] strSplit = strDataEncrypted.split("\\|\\|");
strEncrypted = strSplit[0].trim();
strIV = strSplit[1];
CryptLibHelper cryptLibHelper = new CryptLibHelper();
cryptLibHelper.decrypt(strEncrypted, strIV, new CryptLibHelper.CryptLibDecryptCallback() {
#Override
public void onDecryptFailed(String str_message) {
Log.wtf("onDecryptFailed", str_message);
}
#Override
public void onDecryptSuccess(String str_message) {
if (str_message.contains("}")) {
strEncrypt = str_message.replace("}", "");
Log.wtf("onDecryptSuccess", strEncrypt);
}
}
});
onBackPressed();
isScanSuccess = true;
mScannerView.resumeCameraPreview(this);
}
}
Have you added CAMERA permission check in your app?? Since from marshmallow onwards you need to ask user for some permissions.
You can first try to manually give permission to your app from device settings.
I was experiencing this issue on and off, my problem was that my application was requesting camera permissions too late! Make sure your application is requesting the camera permissions BEFORE an instance of ZXing qr scanner is created.

what is Google Play services MeasurementBrokerService and how to stop it?

I have created a Service which listens to a Firebase location.
This is a simple service with low memory usage. Unfortunately, I am seeing a Google play services service called MeasurementBrokerService joining my service and not freeing memory.
Unlike a related question :
"Service MeasurementBrokerService is in use" is showing in my application process
The above question has no accepted answer, so kindly do not mark this as a duplicate
I am not using firebase-appindexing.
Following is my app level gradle file:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.project.recommendedapp"
minSdkVersion 21
targetSdkVersion 25
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:cardview-v7:25.1.0'
compile 'com.android.support:recyclerview-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:support-v4:25.1.0'
compile 'com.github.clans:fab:1.6.4'
compile 'com.google.android.gms:play-services-location:10.0.1'
compile('com.crashlytics.sdk.android:crashlytics:2.6.0#aar') {
transitive = true;
}
compile 'com.facebook.fresco:fresco:1.0.0'
compile 'com.google.firebase:firebase-database:10.0.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'
compile 'com.squareup.okhttp3:okhttp:3.5.0'
}
apply plugin: 'com.google.gms.google-services'
Can someone please guide me as to how to stop the service from joining my process.
The service is as follows:
public class SubscriptionListenerService extends Service {
DatabaseReference userNodeSubscriptionRef;
ChildEventListener subscribedTopicsListener;
SharedPreferences sessionPref,subscribedTopicsPreference;
SharedPreferences.Editor subscribedtopicsprefeditor;
String userid;
boolean stoppedInternally = false;
SharedPreferences.OnSharedPreferenceChangeListener sessionPrefChangeListener;
#Nullable
#Override
public IBinder onBind(Intent intent) {
//do not need a binder over here
return null;
}
#Override
public void onCreate(){
super.onCreate();
Log.d("FragmentCreate","onCreate called inside service");
sessionPref = getSharedPreferences("SessionPref",0);
subscribedTopicsPreference=getSharedPreferences("subscribedTopicsPreference",0);
subscribedtopicsprefeditor=subscribedTopicsPreference.edit();
userid = sessionPref.getString("userid",null);
sessionPrefChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
#Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Log.d("FragmentCreate","The shared preference changed "+key);
stoppedInternally=true;
sessionPref.unregisterOnSharedPreferenceChangeListener(this);
if(userNodeSubscriptionRef!=null && subscribedTopicsListener!=null){
userNodeSubscriptionRef.removeEventListener(subscribedTopicsListener);
}
stopSelf();
}
};
sessionPref.registerOnSharedPreferenceChangeListener(sessionPrefChangeListener);
subscribedTopicsListener = new ChildEventListener() {
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if(!(dataSnapshot.getValue() instanceof Boolean)){
Log.d("FragmentCreate","Please test subscriptions with a boolean value");
}else {
if ((Boolean) dataSnapshot.getValue()) {
//here we subscribe to the topic as the topic has a true value
Log.d("FragmentCreate", "Subscribing to topic " + dataSnapshot.getKey()+" "+this.getClass().getName());
subscribedtopicsprefeditor.putBoolean(dataSnapshot.getKey(), true);
FirebaseMessaging.getInstance().subscribeToTopic(dataSnapshot.getKey());
} else {
//here we unsubscribed from the topic as the topic has a false value
Log.d("FragmentCreate", "Unsubscribing from topic " + dataSnapshot.getKey()+" "+this.getClass().getName());
subscribedtopicsprefeditor.remove(dataSnapshot.getKey());
FirebaseMessaging.getInstance().unsubscribeFromTopic(dataSnapshot.getKey());
}
subscribedtopicsprefeditor.commit();
}
}
#Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
//either an unsubscription will trigger this, or a re-subscription after an unsubscription
if(!(dataSnapshot.getValue() instanceof Boolean)){
Log.d("FragmentCreate","Please test subscriptions with a boolean value");
}else{
if((Boolean)dataSnapshot.getValue()){
Log.d("FragmentCreate","Subscribing to topic "+dataSnapshot.getKey()+" "+this.getClass().getName());
subscribedtopicsprefeditor.putBoolean(dataSnapshot.getKey(),true);
FirebaseMessaging.getInstance().subscribeToTopic(dataSnapshot.getKey());
}else{
Log.d("FragmentCreate","Unsubscribing from topic "+dataSnapshot.getKey()+" "+this.getClass().getName());
subscribedtopicsprefeditor.remove(dataSnapshot.getKey());
FirebaseMessaging.getInstance().unsubscribeFromTopic(dataSnapshot.getKey());
}
subscribedtopicsprefeditor.commit();
}
}
#Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
//Log.d("FragmentCreate","Unubscribing from topic "+dataSnapshot.getKey());
//FirebaseMessaging.getInstance().unsubscribeFromTopic(dataSnapshot.getKey());
}
#Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
//do nothing, this won't happen --- rather this isnt important
}
#Override
public void onCancelled(DatabaseError databaseError) {
Log.d("FragmentCreate","Failed to listen to subscriptions node");
}
};
if(userid!=null){
Log.d("FragmentCreate","Found user id in service "+userid);
userNodeSubscriptionRef = FirebaseDatabase.getInstance().getReference().child("Users").child(userid).child("subscriptions");
userNodeSubscriptionRef.addChildEventListener(subscribedTopicsListener);
userNodeSubscriptionRef.keepSynced(true);
}else{
Log.d("FragmentCreate","Couldn't find user id");
stoppedInternally=true;
stopSelf();
}
}
#Override
public int onStartCommand(Intent intent,int flags,int startId){
//don't need anything done over here
//The intent can have the following extras
//If the intent was started by the alarm manager ..... it will contain android.intent.extra.ALARM_COUNT
//If the intent was sent by the broadcast receiver listening for boot/update ... it will contain wakelockid
//If it was started from within the app .... it will contain no extras in the intent
//The following will not throw an exception if the intent does not have an wakelockid in extra
//As per android doc... the following method releases the wakelock if any specified inside the extra and returns true
//If no wakelockid is specified, it will return false;
if(intent!=null){
if(BootEventReceiver.completeWakefulIntent(intent)){
Log.d("FragmentCreate","Wakelock released");
}else{
Log.d("FragmentCreate","Wakelock not acquired in the first place");
}
}else{
Log.d("FragmentCreate","Intent started by regular app usage");
}
return START_STICKY;
}
#Override
public void onDestroy(){
if(userNodeSubscriptionRef!=null){
userNodeSubscriptionRef.keepSynced(false);
}
userNodeSubscriptionRef = null;
subscribedTopicsListener = null;
sessionPref = null;
subscribedTopicsPreference = null;
subscribedtopicsprefeditor = null;
userid = null;
sessionPrefChangeListener = null;
if(stoppedInternally){
Log.d("FragmentCreate","Service getting stopped due to no userid or due to logout or data clearance...do not restart auto.. it will launch when user logs in or signs up");
}else{
Log.d("FragmentCreate","Service getting killed by user explicitly from running services or by force stop ... attempt restart");
//well basically restart the service using an alarm manager ... restart after one minute
AlarmManager alarmManager = (AlarmManager) this.getSystemService(ALARM_SERVICE);
Intent restartServiceIntent = new Intent(this,SubscriptionListenerService.class);
restartServiceIntent.setPackage(this.getPackageName());
//context , uniqueid to identify the intent , actual intent , type of pending intent
PendingIntent pendingIntentToBeFired = PendingIntent.getService(this,1,restartServiceIntent,PendingIntent.FLAG_ONE_SHOT);
if(Build.VERSION.SDK_INT>=23){
alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+600000,pendingIntentToBeFired);
}else{
alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+600000,pendingIntentToBeFired);
}
}
super.onDestroy();
}
}
I checked that somehow still google AppMeasurement service was running on my device.
I have resorted to using the following approach:
The following stops data collection by firebase.
https://firebase.google.com/support/guides/disable-analytics tells us the following approach
<meta-data android:name="firebase_analytics_collection_deactivated" android:value="true" />
This alone still can't stop the appMeasurement from initializing.
The second step that has solved is adding the following to the app level gradle file:
configurations {
all*.exclude group: 'com.google.firebase', module: 'firebase-core'
}
This basically removes all the code that firebase analytics uses.
In case it still doesn't work, make sure that the gradle does not include broad play service dependency
eg: compile 'com.google.android.gms:play-services-location:10.0.1'
instead of 'com.google.android.gms:play-services:10.0.1'
Worst case and i have not tested this as the above solved it for me is:
https://developers.google.com/analytics/devguides/collection/android/v4/advanced
Google should really stop putting unwanted things without the dev's permission IMHO. Hope this helps someone

How to observe network changes in RxAndroid

I’m using the code given here.
I put those code blocks as classes in my project’s util package. And then in the main activity class I wrote this..
class MenuActivity {
// Variable declaration
private final CompositeSubscription mConnectionSubscription = new CompositeSubscription();
#Override
protected void onCreate(Bundle savedInstanceState) {
// Some initialisation of UI elements done here
mConnectionSubscription.add(AppObservable.bindActivity(this, NetworkUtils.observe(this)).subscribe(new Action1<NetworkUtils.State>() {
#Override
public void call(NetworkUtils.State state) {
if(state == NetworkUtils.State.NOT_CONNECTED)
Timber.i("Connection lost");
else
Timber.i("Connected");
}
}));
}
My goal is to monitor the changes and change a variable MyApp.isConnected defined in the MyApp class statically whenever the network changes to true false. Help would be appreciated. Thank you 😄
You asked me for an answer in another thread. I'm answering late, because I needed some time to develop and test solution, which I find good enough.
I've recently created new project called ReactiveNetwork.
It's open-source and available at: https://github.com/pwittchen/ReactiveNetwork.
You can add the following dependency to your build.gradle file:
dependencies {
compile 'com.github.pwittchen:reactivenetwork:x.y.z'
}
Then, you can replace x.y.z with the latest version number.
After that, you can use library in the following way:
ReactiveNetwork.observeNetworkConnectivity(context)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<ConnectivityStatus>() {
#Override public void call(Connectivity connectivity) {
if(connectivity.getState() == NetworkInfo.State.DISCONNECTED) {
Timber.i("Connection lost");
} else if(connectivity.getState() == NetworkInfo.State.CONNECTED) {
Timber.i("Connected");
}
}
});
You can also use filter(...) method from RxJava if you want to react only on a single type of event.
You can create a subscription in onResume() method and then unsubscribe it in onPause() method inside Activity.
You can find more examples of usage and sample app on the website of the project on GitHub.
Moreover, you can read about NetworkInfo.State enum from Android API, which is now used by the library.
Try to use rxnetwork-android:
public class MainActivity extends AppCompatActivity{
private Subscription sendStateSubscription;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Observable<RxNetwork.State> sendStateStream =
RxNetwork.stream(this);
sendStateSubscription = AppObservable.bindActivity(
this, sendStateStream
).subscribe(new Action1<RxNetwork.State>() {
#Override public void call(RxNetwork.State state) {
if(state == RxNetwork.State.NOT_CONNECTED)
Timber.i("Connection lost");
else
Timber.i("Connected");
}
});
}
#Override protected void onDestroy() {
sendStateSubscription.unsubscribe();
sendStateSubscription = null;
super.onDestroy();
}
}

SocketIOClient example does not compile

I've got a Andriod Studio project and I'm trying to use the SocketIOClient from the AndroidAsync library. I'm building the library with the command:
dependencies {
compile 'com.koushikdutta.androidasync:AndroidAsync:1.0.0'
}
I was able to get the websocket example to work, but there's seems to be a version issue with the 1.0 and the SocketIOClient example. I've also tried using the 2.0 jar file, but SocketIOClient doesn't appear to be defined there at all(this is one of my first andriod applications, so maybe I'm just doing something wrong). Does anyone know what needs to be done to get the following code to compile:
SocketIOClient.connect(AsyncHttpClient.getDefaultInstance(), "http://192.168.1.2:3000", new ConnectCallback() {
#Override
public void onConnectCompleted(Exception ex, SocketIOClient client) {
if (ex != null) {
ex.printStackTrace();
return;
}
client.setStringCallback(new StringCallback() {
#Override
public void onString(String string) {
System.out.println(string);
}
});
client.on("someEvent", new EventCallback() {
#Override
public void onEvent(JSONArray argument, Acknowledge acknowledge) {
System.out.println("args: " + arguments.toString());
}
});
client.setJSONCallback(new JSONCallback() {
#Override
public void onJSON(JSONObject json) {
System.out.println("json: " + json.toString());
}
});
}
});
Thanks,
Scott

Categories

Resources