0

Today the illumination API was released and I tried to make a simple app of showing of a blink of the illumination bar upon click of a button. I just copy-pasted the code in the sony developers website, but it gives error that, there is no acitivity to handle this intent START_LED. Here's the main_activity:

package com.example.myillumin;

import com.sonyericsson.illumination.IlluminationIntent;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

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

        b1= (Button) findViewById(R.id.button1);
        b1.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View arg0){
                Intent intent=new Intent(IlluminationIntent.ACTION_START_LED);
                intent.putExtra(IlluminationIntent.EXTRA_LED_COLOR,0xFFFF0000);
                intent.putExtra(IlluminationIntent.EXTRA_PACKAGE_NAME, "com.example.myillumin");
                startActivity(intent);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}

And here's the manifest file I tried to modify seeing other posts of stackoverflow.

<uses-permission android:name="com.sonyericsson.illumination.permission.ILLUMINATION"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.myillumin.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.sonyericsson.illumination.IlluminationIntent"
            android:label="@string/activity_name" 
            android:exported="false">
            <intent-filter>
                <action android:name="com.sonyericsson.illumination.intent.action.START_LED" />
                <category android:name="android.intent.category.DEFAULT" />           
            </intent-filter>
        </activity>
    </application>

</manifest>

Please help me out :(

Konrad Borowski
  • 11,584
  • 3
  • 57
  • 71
Suraj Kumar Sau
  • 438
  • 6
  • 10

2 Answers2

0

The illumination bar API uses a 'service' to change the colors of the bar, so you have to start a Service not an Activity.

So, in your code,

Intent intent=new Intent(IlluminationIntent.ACTION_START_LED);
                intent.putExtra(IlluminationIntent.EXTRA_LED_COLOR,0xFFFF0000);
                intent.putExtra(IlluminationIntent.EXTRA_PACKAGE_NAME, "com.example.myillumin");
                startActivity(intent);

instead of starting an activity with the intent, try starting a service with the created Intent. From:

 startActivity(intent);

change to

startService(intent);

You can also check whether the device supports the API by calling:

Intent checkIntent = new Intent(IlluminationIntent.ACTION_STOP_LED);
if (null == getPackageManager().resolveService(checkIntent,
                PackageManager.GET_RESOLVED_FILTER)) {
               //  Not supported
}
Alex Styl
  • 3,982
  • 2
  • 28
  • 47
0

In order to start the illumination service you must provide the intent with certain mandatory fields, you already have IlluminationIntent.EXTRA_PACKAGE_NAME and IlluminationIntent.ACTION_START_LED so now u need to add IlluminationIntent.EXTRA_LED_ID, therefore, inside the onClick method Add the line:

intent.putExtra(IlluminationIntent.EXTRA_LED_ID, IlluminationIntent.VALUE_BUTTON_2);

Since it is a service, you need to change:

startActivity(intent);

And replace it with:

startService(intent);