Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8669927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:35:37+00:00 2026-06-12T18:35:37+00:00

I am attempting to get my android to launch an activity when it registers

  • 0

I am attempting to get my android to launch an activity when it registers a Bluetooth connection, I have all the proper permissions and this code runs fine up to the point that it needs to launch the intent. After that it crashes out. Right now I do not have a logcat for this as its on a live test on my phone.

So, lets play another game of “How do I fix this?”

public class detectService extends Service {

public void onCreate() {
    IntentFilter filter1 = new IntentFilter(
            BluetoothDevice.ACTION_ACL_CONNECTED);
    this.registerReceiver(mReceiver, filter1);
    Toast.makeText(this, "Starting Service!", Toast.LENGTH_LONG).show();
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    return START_STICKY;
}

// The BroadcastReceiver that listens for bluetooth broadcasts
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        BluetoothAdapter device = intent
                .getParcelableExtra(BluetoothDevice.ACTION_ACL_CONNECTED);

        if (device.equals(action)) {
            // Device is now connected
            // Start Second Activity
            Intent otherIntent = new Intent(detectService.this,
                    otherClass.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(otherIntent);
        }
    };
};
@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}
}

Thanks to the help of someone on here I now have logcat on my phone! Here is a copy of the errors:

E/AndroidRuntime(  567): FATAL EXCEPTION: main
E/AndroidRuntime(  567): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.bluetooth.device.action.ACL_CONNECTED (has extras) } in lionsimages.com.bluetoothalert.detectService$1@4051ad68
E/AndroidRuntime(  567):    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:722)
E/AndroidRuntime(  567):    at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime(  567):    at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(  567):    at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime(  567):    at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime(  567):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  567):    at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(  567):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
E/AndroidRuntime(  567):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
E/AndroidRuntime(  567):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  567): Caused by: java.lang.NullPointerException
E/AndroidRuntime(  567):    at lionsimages.com.bluetoothalert.detectService$1.onReceive(detectService.java:39)
E/AndroidRuntime(  567):    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:709)
E/AndroidRuntime(  567):    ... 9 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:35:40+00:00Added an answer on June 12, 2026 at 6:35 pm

    In your onReceive() method you do this:

       BluetoothAdapter device = intent
                .getParcelableExtra(BluetoothDevice.ACTION_ACL_CONNECTED);
    

    But there is no extra with that name in this broadcast Intent. If you want to get the device from the Intent then you need this instead:

       BluetoothDevice device = intent
                .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
    

    However, if I look at your code you seem to only want to check if the Intent ACTION is ACTION_ACL_CONNECTED. If that is all you want to do, then use this code instead:

    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
    
        if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
            // Device is now connected
            // Start Second Activity
            Intent otherIntent = new Intent(detectService.this,
                    otherClass.class);
            // NOTE: I changed "intent" to "otherIntent" in the following line as well!
            otherIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(otherIntent);
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to launch my application but this is what I get. I
Attempting to get Spring internationalization working. I have used classpath:messages basename, created .properties files
Im attempting to get a block of text from a file I have already
I am attempting to get rails routes paths via nested resources. I have looked
I have been attempting to get log4net logging in my asp.net web application with
I am attempting to get the string representation of an Android device's current WiFi
I am attempting to get a list of all friend messages posted by the
I'm creating my first android app (or attempting to anyway) and i have a
i am attempting to get my android app to work on both phone type
I'm finally attempting to run proguard for my android app but I get the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.