I’m working on an app in which I want to run some services when default Android options are accessed, i.e. when Play Music or Gallery is accessed generate a Toast and so on… Is it possible to do this?? Here is my code.
Here is where I start my service in the Main Activity:
if(autoBrightOn){
startService(new Intent(this, MyService.class));
}
and my Service.class
public class MyService extends Service {
private static final String TAG = "MyService";
@Override
public IBinder onBind(Intent intent) {
Log.w(" ibinder ","");
return null;
}
@Override
public void onCreate() {
// Toast.makeText(this, "My Service Created",0).show();
Log.w(TAG, "onCreate");
}
@Override
public void onDestroy() {
// Toast.makeText(this, "My Service Stopped",0).show();
// Log.w(TAG, "onDestroy");
// player.stop();
}
@Override
public void onStart(Intent intent, int startid) {
Toast.makeText(this, "My Service Started :"+intent+" start id :"+startid,0).show();
// Log.d(TAG, "onStart");
// player.start();
Intent intentBrowseFiles = new Intent(Intent.ACTION_VIEW);
intentBrowseFiles.setType("image/*");
intentBrowseFiles.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentBrowseFiles);
}
You could create a custom
BroadcastReceiverand listen for differentIntents sent out. There doesn’t appear to be a ‘catch-all’ACTIVITY_STARTEDso you may need to create a pretty detailed list ofIntents to listen for. Here’s the AndroidIntentReference:http://developer.android.com/reference/android/content/Intent.html