How can i On GPS Automatically without asking User? - android

I've tried this code but It's not working Properly.
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
sendBroadcast(intent, Manifest.permission.WRITE_SECURE_SETTINGS);
Getting this Error:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.setting/com.setting.activity.TraceLocationActivity}:
java.lang.SecurityException: Permission Denial: not allowed to send
broadcast android.location.GPS_ENABLED_CHANGE from pid=28258,
uid=10395
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2793)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
Caused by: java.lang.SecurityException: Permission Denial: not allowed to send
broadcast android.location.GPS_ENABLED_CHANGE from pid=28258,
uid=10395
at android.os.Parcel.readException(Parcel.java:1665)
at android.os.Parcel.readException(Parcel.java:1618)
at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:3533)
at android.app.ContextImpl.sendBroadcast(ContextImpl.java:1012)
at android.content.ContextWrapper.sendBroadcast(ContextWrapper.java:426)
at com.setting.activity.TraceLocationActivity.onCreate(TraceLocationActivity.java:46)
at android.app.Activity.performCreate(Activity.java:6915)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2746)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:156) 
at android.app.ActivityThread.main(ActivityThread.java:6523) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)

How can i On GPS Automatically without asking User?
This is not possible, for obvious privacy and security reasons.

Related

Permission Denial : Starting Intent ( lock task mode / kiosk mode )

Any one have a suggestion how to solve this error ?
I am trying to run lock task with intent getLaunchIntentForPackage but I have no idea why this error is coming and which type of permission it wants to run this task.
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.example.videoplayer cmp=com.example.videoplayer/.MainActivity } from ProcessRecord{fd194a9 7523:com.example.lock/u0a190} (pid=7523, uid=10190) with lockTaskMode=true
at android.os.Parcel.createExceptionOrNull(Parcel.java:2425)
at android.os.Parcel.createException(Parcel.java:2409)
at android.os.Parcel.readException(Parcel.java:2392)
at android.os.Parcel.readException(Parcel.java:2334)
at android.app.IActivityTaskManager$Stub$Proxy.startActivity(IActivityTaskManager.java:2326)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1758)
at android.app.Activity.startActivityForResult(Activity.java:5407)
at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:597)
at android.app.Activity.startActivity(Activity.java:5747)
at com.example.lock.MainActivity.launchApp(MainActivity.kt:110)
at com.example.lock.MainActivity.onCreate$lambda-0(MainActivity.kt:62)
at com.example.lock.MainActivity.$r8$lambda$yGvyKllS4GN5cYzDCcbSf8EdXb0(Unknown Source:0)
at com.example.lock.MainActivity$$ExternalSyntheticLambda0.onClick(Unknown Source:2)
at android.view.View.performClick(View.java:7455)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1194)
at android.view.View.performClickInternal(View.java:7432)
at android.view.View.access$3700(View.java:835)
at android.view.View$PerformClick.run(View.java:28810)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7842)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.wm.SafeActivityOptions.checkPermissions(SafeActivityOptions.java:283)
at com.android.server.wm.SafeActivityOptions.getOptions(SafeActivityOptions.java:155)
at com.android.server.wm.ActivityStarter.executeRequest(ActivityStarter.java:1006)
at com.android.server.wm.ActivityStarter.execute(ActivityStarter.java:670)
at com.android.server.wm.ActivityTaskManagerService.startActivityAsUser(ActivityTaskManagerService.java:1223)
I'm currently running into the same error. The only thing I can hand to you is that it can be solved by using the DevicePolicyManager.setLockTaskPackages as stated on the android site: https://developer.android.com/work/dpc/dedicated-devices/lock-task-mode#allowlist_apps

Android app relase - Facebook login button crash

I have a problem with my app where I entered a login button with facebook.
When I use the app and on facebook developer options I have development mode, I have no problems,the app is working properly.
But from the moment I put it in release on facebook developer options, the app crashes as soon as I click on login
I've already put a key release hash on facebook developer, and I've made other attempts, but I can't understand the problem.
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
at android.view.View.performClick(View.java:6663)
at android.view.View.performClickInternal(View.java:6635)
at android.view.View.access$3100(View.java:794)
at android.view.View$PerformClick.run(View.java:26199)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
at android.view.View.performClick(View.java:6663) 
at android.view.View.performClickInternal(View.java:6635) 
at android.view.View.access$3100(View.java:794) 
at android.view.View$PerformClick.run(View.java:26199) 
at android.os.Handler.handleCallback(Handler.java:907) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:216) 
at android.app.ActivityThread.main(ActivityThread.java:7625) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987) 
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'long java.util.Date.getTime()' on a null object reference
at java.util.Calendar.setTime(Calendar.java:1749)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:984)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:977)
at java.text.DateFormat.format(DateFormat.java:341)
at com.example.tpistis.tauros.LoginActivity.registra_cliente(LoginActivity.java:270)
at com.example.tpistis.tauros.LoginActivity.apri_app(LoginActivity.java:242)
at java.lang.reflect.Method.invoke(Native Method) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385) 
at android.view.View.performClick(View.java:6663) 
at android.view.View.performClickInternal(View.java:6635) 
at android.view.View.access$3100(View.java:794) 
at android.view.View$PerformClick.run(View.java:26199) 
at android.os.Handler.handleCallback(Handler.java:907) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:216) 
at android.app.ActivityThread.main(ActivityThread.java:7625) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987) 
For those who were looking for an answer, the problem was that on FacebookDevoloper I did not have the privileges to be able to acquire the date of birth, basically you can only acquire name and last name, then the app crashes.

Failed to find provider null for user 0; expected to find a valid ContentProvider for this authority Android Oreo

I am facing two inter related issue,
I am facing following issue in Android Oreo device,
java.lang.RuntimeException: Error receiving broadcast Intent { act=com.example.bluetooth.le.ACTION_REMOTE_RSSI_UPDATED flg=0x10 (has extras) } in com.linka.linkaapikit.module.widget.LockGattUpdateReceiver$1#762cfd9
at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$-android_app_LoadedApk$ReceiverDispatcher$Args_52197(LoadedApk.java:1315)
at android.app.-$Lambda$aS31cHIhRx41653CMnd4gZqshIQ.$m$7(Unknown Source:4)
at android.app.-$Lambda$aS31cHIhRx41653CMnd4gZqshIQ.run(Unknown Source:39)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:172)
at android.app.ActivityThread.main(ActivityThread.java:6590)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.SecurityException: Failed to find provider null for user 0; expected to find a valid ContentProvider for this authority
at android.os.Parcel.readException(Parcel.java:2005)
at android.os.Parcel.readException(Parcel.java:1951)
at android.content.IContentService$Stub$Proxy.notifyChange(IContentService.java:801)
at android.content.ContentResolver.notifyChange(ContentResolver.java:2049)
at android.content.ContentResolver.notifyChange(ContentResolver.java:2000)
at android.content.ContentResolver.notifyChange(ContentResolver.java:1970)
at com.activeandroid.Model.save(Model.java:162)
After that i find following solutions,
add in Android Manifest
<provider
android:name="com.activeandroid.content.ContentProvider"
android:authorities="com.myapp"
android:enabled="true"
android:exported="false"
/>
But after adding this line i got another issue that are following,
java.lang.IncompatibleClassChangeError: Superclass org.apache.http.params.BasicHttpParams of org.apache.http.params.SyncBasicHttpParams is declared final (declaration of 'org.apache.http.params.SyncBasicHttpParams' appears in /data/app/com.kolonishare-6KsxqUHOK_Q45cGI0D0bHg==/base.apk:classes16.dex)
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:453)
at com.activeandroid.ModelInfo.scanForModelClasses(ModelInfo.java:187)
at com.activeandroid.ModelInfo.scanForModel(ModelInfo.java:152)
at com.activeandroid.ModelInfo.<init>(ModelInfo.java:63)
at com.activeandroid.Cache.initialize(Cache.java:66)
at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:44)
at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:34)
at com.activeandroid.content.ContentProvider.onCreate(ContentProvider.java:39)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1919)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1894)
at android.app.ActivityThread.installProvider(ActivityThread.java:6285)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5851)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5772)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
I clean and also rebuild project, invalidate restart but getting same error.
you need put your xml in this
<provider android:name="com.activeandroid.content.ContentProvider"
android:authorities="${applicationId}.fileprovider"
android:enabled="true"
android:exported="false" />

Failed to Enable AutoFill Service by using Intent in Android O

I used this code for enabling the Enable AutoFill Service.
Intent dialogIntent = new Intent(Settings.ACTION_REQUEST_SET_AUTOFILL_SERVICE);
startActivity(dialogIntent);
I got the next exception:
FATAL EXCEPTION: main
Process: com.example.android.autofillframework, PID: 7683
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.autofillframework/com.example.android.autofillframework.app.StandardSignInActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.REQUEST_SET_AUTOFILL_SERVICE }
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.REQUEST_SET_AUTOFILL_SERVICE }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1936)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1615)
at android.app.Activity.startActivityForResult(Activity.java:4472)
at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:65)
at android.app.Activity.startActivityForResult(Activity.java:4430)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:711)
at android.app.Activity.startActivity(Activity.java:4791)
at android.app.Activity.startActivity(Activity.java:4759)
at com.example.android.autofillframework.app.StandardSignInActivity.onCreate(StandardSignInActivity.java:53)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
You're missing the package name in the intent. From the javadoc:
Input: Intent's data URI set with an application name, using the "package" schema (like "package:com.my.app").
You're missing the package name in the intent. pass your app package name in intent.setData().
like:
Intent intent = new Intent(android.provider.Settings.ACTION_REQUEST_SET_AUTOFILL_SERVICE);
intent.setData(Uri.parse("package:<YOUR_APP_PACKAGE_NAME>"));
startActivity(intent)
On Huawei devices, it seems like this even happens if you check correctly for hasEnabledAutofillServices() and isAutofillSupported() and if you include the package.

Exception while turning on GPS [duplicate]

This question already has answers here:
android app crash on android 4.4 due to gps permission denial
(2 answers)
Closed 6 years ago.
This is my code:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
sendBroadcast(intent);
}
}
This is the error in logcat:
FATAL EXCEPTION: main
Process: com.example.satyajittarafdar.gps_on_automatic, PID: 20469
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.satyajittarafdar.gps_on_automatic/com.example.satyajittarafdar.gps_on_automatic.MainActivity}:
java.lang.SecurityException: Permission Denial: not allowed to send
broadcast android.location.GPS_ENABLED_CHANGE from pid=20469,
uid=10240
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2429)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1357)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5459)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: java.lang.SecurityException: Permission Denial: not allowed
to send broadcast android.location.GPS_ENABLED_CHANGE from pid=20469,
uid=10240
at android.os.Parcel.readException(Parcel.java:1620)
at android.os.Parcel.readException(Parcel.java:1573)
at
android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:3128)
at android.app.ContextImpl.sendBroadcast(ContextImpl.java:767)
at
android.content.ContextWrapper.sendBroadcast(ContextWrapper.java:396)
at
com.example.satyajittarafdar.gps_on_automatic.MainActivity.onCreate(MainActivity.java:19)
at android.app.Activity.performCreate(Activity.java:6259)
at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2382)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1357) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5459) 
at java.lang.reflect.Method.invoke(Native Method) 
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
This is not available as public API, and you cannot change GPS state programmatically from Android 4.4 and above. you have prepare intent and redirect user to settings.
startActivity(context, new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
here are some references:
https://stackoverflow.com/a/22529296/3758024
https://stackoverflow.com/a/20236331/3758024
You cannot change the gps state programmaticly since android version 4.4.
Good explanation why: Read this post
What you should so is using intent to send the user to the phoen setting and request him to enable it manually.

Categories

Resources