android - update My App Issue -
i'm developing non-public android app, i.e. app won't available in global android market. app installed on limited number of clients, e.g. using apk file.i have .apk in sd card , trying update application application. that, i'm using intent
my code
intent intent = new intent(intent.action_view); intent.setdataandtype(uri.fromfile(new file(environment.getexternalstoragedirectory().getpath()+"/" +"test.apk")), "application/vnd.android.package-archive"); startactivity(intent);
note : working fine, after updating it, application closed.
the question "how prevent ?"
i'm use broadcast receiver re-open app
public class autostart extends broadcastreceiver{ @override public void onreceive(context context, intent intent) { if (intent.getaction().equals(intent.action_boot_completed)){ intent = new intent(context, abcactivity.class); i.addflags(intent.flag_activity_new_task); context.startactivity(i); }else{ intent = new intent(context, xyzactivity.class); i.addflags(intent.flag_activity_new_task); context.startactivity(i); } }
problem 1 :- can't re-open activity when
"android.intent.action.package_added",
"android.intent.action.package_install",
"android.intent.action.package_changed"
<receiver android:name=".autostart" android:enabled="true" android:exported="true" > <intent-filter android:priority="100" > <action android:name="android.intent.action.boot_completed" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.package_added" /> <data android:scheme="package" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.package_install" /> <data android:scheme="package" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.package_changed" /> <data android:scheme="package" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.package_replaced" /> <data android:scheme="package" /> </intent-filter> </receiver>
"android.intent.action.boot_completed" working properly
permissions given
1 > <uses-permission android:name="android.permission.receive_boot_completed" /> 2 > <uses-permission android:name="android.permission.restart_packages" /> 3 > <uses-permission android:name="android.permission.write_external_storage" />
unfortunately can't prevent process been terminated when re-install itself, , other hand - you'll never receive any broadcast if own app been re-install @ time.
if had implement such feature, solve problem this:
trick number 1:
creating app (that installed somehow on user's device) roll act sort of "watch-dog": app listen installation broadcasts, , because it's different app 1 been installed - won't have problem launch "original app".
of-course don't forget user need "launch" @ least ones watch-dog app, because android 4 receivers won't work until app process started @ least ones from. security reasons..
trick number 2:
another option registered in manifest app action_time_tick
broadcast. can count on broadcast called each number of seconds, , implement when receives logic recognize if app right need launch main activity or not.
this approach work, performances reason not - because app process alive time because reacts broadcast. if don't care - not problem
trick number 3:
provide pendingintent
alarmmanager
before start installation activity 30-50 seconds after. pending intent hold intent re-launch app.
assuming app installed until - work.
Comments
Post a Comment