mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-07 05:24:46 +01:00
fix crash around uri permissions for new OS version
Use a FileProvider with all the necessary xml changes to pass apk to installer without crashing it or myself.
This commit is contained in:
parent
1abc6e39fd
commit
8f9c9e0623
5 changed files with 25 additions and 14 deletions
|
@ -43,6 +43,16 @@
|
|||
android:theme="@style/AppTheme"
|
||||
>
|
||||
|
||||
<provider android:name="android.support.v4.content.FileProvider"
|
||||
android:authorities="${applicationId}.provider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true"
|
||||
>
|
||||
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/provider_paths"
|
||||
/>
|
||||
</provider>
|
||||
|
||||
<activity android:name="MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="standard"
|
||||
|
|
|
@ -172,7 +172,7 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
callListener( m_uri, true );
|
||||
} else if ( null != m_appFile ) {
|
||||
// launch the installer
|
||||
Intent intent = Utils.makeInstallIntent( m_appFile );
|
||||
Intent intent = Utils.makeInstallIntent( m_activity, m_appFile );
|
||||
startActivity( intent );
|
||||
} else {
|
||||
// we failed at something....
|
||||
|
@ -473,5 +473,4 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
intent.putExtra( APK_EXTRA, url );
|
||||
return intent;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1451,8 +1451,6 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
showItemsIf( ONEGAME_ITEMS, menu, 1 == nGamesSelected );
|
||||
showItemsIf( ONEGROUP_ITEMS, menu, 1 == nGroupsSelected );
|
||||
|
||||
// check for updates only serves release builds, so don't offer in
|
||||
// DEBUG case
|
||||
boolean enable = showDbg && nothingSelected
|
||||
&& UpdateCheckReceiver.haveToCheck( m_activity );
|
||||
Utils.setItemVisible( menu, R.id.games_menu_checkupdates, enable );
|
||||
|
|
|
@ -256,7 +256,8 @@ public class UpdateCheckReceiver extends BroadcastReceiver {
|
|||
m_dals = dals;
|
||||
}
|
||||
|
||||
@Override protected String doInBackground( Void... unused )
|
||||
@Override
|
||||
protected String doInBackground( Void... unused )
|
||||
{
|
||||
HttpURLConnection conn
|
||||
= NetUtils.makeHttpUpdateConn( m_context, "getUpdates" );
|
||||
|
@ -267,7 +268,8 @@ public class UpdateCheckReceiver extends BroadcastReceiver {
|
|||
return json;
|
||||
}
|
||||
|
||||
@Override protected void onPostExecute( String json )
|
||||
@Override
|
||||
protected void onPostExecute( String json )
|
||||
{
|
||||
if ( null != json ) {
|
||||
makeNotificationsIf( json, m_params );
|
||||
|
|
|
@ -34,17 +34,16 @@ import android.content.pm.PackageManager;
|
|||
import android.content.pm.ResolveInfo;
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.text.ClipboardManager;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.media.Ringtone;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.provider.ContactsContract.PhoneLookup;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.content.FileProvider;
|
||||
import android.telephony.PhoneNumberUtils;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import android.text.ClipboardManager;
|
||||
import android.util.Base64;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
@ -486,13 +485,16 @@ public class Utils {
|
|||
return null == s_appVersion? 0 : s_appVersion;
|
||||
}
|
||||
|
||||
public static Intent makeInstallIntent( File file )
|
||||
public static Intent makeInstallIntent( Context context, File file )
|
||||
{
|
||||
String withScheme = "file://" + file.getPath();
|
||||
Uri uri = Uri.parse( withScheme );
|
||||
Uri uri = FileProvider
|
||||
.getUriForFile( context,
|
||||
BuildConfig.APPLICATION_ID + ".provider",
|
||||
file );
|
||||
Intent intent = new Intent( Intent.ACTION_VIEW );
|
||||
intent.setDataAndType( uri, XWConstants.APK_TYPE );
|
||||
intent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
|
||||
intent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_GRANT_READ_URI_PERMISSION );
|
||||
return intent;
|
||||
}
|
||||
|
||||
|
@ -501,7 +503,7 @@ public class Utils {
|
|||
{
|
||||
boolean result = false;
|
||||
PackageManager pm = context.getPackageManager();
|
||||
Intent intent = makeInstallIntent( path );
|
||||
Intent intent = makeInstallIntent( context, path );
|
||||
List<ResolveInfo> doers =
|
||||
pm.queryIntentActivities( intent,
|
||||
PackageManager.MATCH_DEFAULT_ONLY );
|
||||
|
|
Loading…
Reference in a new issue