broadcastreceiver - Need to run my app before the unlock screen in android -
i need run app user clicks on unlock screen. have used action_user_present intent in broadcastreceiver check. used following code. need show app before unlock screen. app visible after unlock screen. appreciated.
my broadcastreceiver
package com.progressindicator; import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.view.windowmanager; public class receive extends broadcastreceiver { @override public void onreceive(context context, intent intent) { // todo auto-generated method stub if (intent.getaction() != null) { if (intent.getaction().equals(intent.action_user_present)) { intent s = new intent(context, progressindicator.class); s.setflags(intent.flag_activity_brought_to_front); // s.setflags(windowmanager.layoutparams.flag_dismiss_keyguard); s.setflags(intent.flag_activity_clear_top); s.addflags(intent.flag_activity_new_task); context.startactivity(s); } } } }
manifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.progressindicator" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="9" android:targetsdkversion="17" /> <uses-permission android:name="android.permission.disable_keyguard" /> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.progressindicator.progressindicator" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <receiver android:name=".receive" > <intent-filter android:enabled="true" android:exported="false" > <action android:name="android.intent.action.user_present" /> </intent-filter> </receiver> </application> </manifest>
my activity:
package com.progressindicator; import android.app.activity; import android.graphics.drawable.animationdrawable; import android.os.bundle; import android.view.menu; import android.view.window; import android.view.windowmanager; import android.view.windowmanager.layoutparams; import android.widget.imageview; import android.widget.linearlayout; public class progressindicator extends activity { imageview loading; animationdrawable loadanimation; private window wind; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); //setcontentview(r.layout.activity_progress_indicator); // requestwindowfeature(window.feature_no_title); // requestwindowfeature(windowmanager.layoutparams.flag_show_when_locked); // wind = this.getwindow(); // wind.addflags(layoutparams.flag_dismiss_keyguard); // wind.addflags(layoutparams.flag_show_when_locked); // wind.addflags(layoutparams.flag_turn_screen_on); getwindow().addflags( windowmanager.layoutparams.flag_show_when_locked ); linearlayout main = new linearlayout(this); main.setorientation(linearlayout.vertical); setcontentview(main); loading = new imageview(this); loading.setimageresource(r.drawable.loading); loadanimation = (animationdrawable)loading.getdrawable(); main.addview(loading); } @override public void onwindowfocuschanged(boolean hasfocus){ loadanimation.start(); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.progress_indicator, menu); return true; } }
try adding windowmanager.layoutparams.flag_show_when_locked activity started, temporarily disable keyguard/keylock long activity on top of other windows.
Comments
Post a Comment