CustomTabsIntent launchUrl throws SecurityException - Permission Denial - java

I am using chrome tabs to view URLs from my android app, but i got some crashes with this stacktrace
Fatal Exception: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.VIEW dat=http://www.ikea.com/... cmp=com.alibaba.intl.android.apps.poseidon/com.alibaba.android.intl.weex.activity.WeexPageActivity (has extras) } from ProcessRecord{2fec948 29204:com.myapp/u0a71} (pid=29204, uid=10071) not exported from uid 10219
at android.os.Parcel.readException(Parcel.java:1620)
at android.os.Parcel.readException(Parcel.java:1573)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:3131)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1540)
at android.app.Activity.startActivityForResult(Activity.java:4283)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivity(Activity.java:4563)
at android.support.v4.content.ContextCompatJellybean.startActivity(ContextCompatJellybean.java:34)
at android.support.v4.content.ContextCompat.startActivity(ContextCompat.java:151)
at android.support.customtabs.CustomTabsIntent.launchUrl(CustomTabsIntent.java:262)
at com.myapp.chromeCustomTabs.CustomTabActivityHelper.openCustomTab(CustomTabActivityHelper.java:34)
at com.myapp.ProductSpecsActivity.goToStoreWebPage(ProductSpecsActivity.java:253)
at com.myapp.ProductSpecsActivity.goSeeDescription(ProductSpecsActivity.java:190)
at com.myapp.ProductSpecsActivity_ViewBinding$4.doClick(ProductSpecsActivity_ViewBinding.java:80)
at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)
at android.view.View.performClick(View.java:5697)
at android.widget.TextView.performClick(TextView.java:10826)
at android.view.View$PerformClick.run(View.java:22526)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7225)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
So, can anyone helps me to figure out what is the problem ? BTW it only happens on some devices and i can't reproduce it while testing on my own devices.
and here is the method that causes the issue
public static void openCustomTab(Activity activity,
Uri uri) {
// create an intent builder
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
// Begin customizing
// set toolbar colors
intentBuilder.setToolbarColor(ContextCompat.getColor(activity, R.color.colorPrimary));
intentBuilder.setSecondaryToolbarColor(ContextCompat.getColor(activity, R.color.colorPrimaryDark));
// set start and exit animations
intentBuilder.setStartAnimations(activity, R.anim.slide_in_right, R.anim.slide_in_right);
intentBuilder.setExitAnimations(activity, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
// build custom tabs intent
CustomTabsIntent customTabsIntent = intentBuilder.build();
// launch the url
customTabsIntent.launchUrl(activity, uri);
}
activity the launches the CustomTab in manifest
<activity
android:name=".ui.activities.productspecs.ProductSpecsActivity"
android:configChanges="orientation|screenSize"
android:label="#string/title_activity_product_specs"
android:theme="#style/AppTheme.Base"
android:windowSoftInputMode="adjustResize" />

That was the issue, https://github.com/alibaba/weex/issues/2139 it is related to Alibaba's app bug conflicts with a CustomTabs

Related

Share app through intent but it is not working

I am making chat app and want to share app via Intent . There are not many solution to the problem please help. here is my code but it is throwing error in start Activity
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
#SuppressLint("NonConstantResourceId")
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem menuItem) {
switch (menuItem.getItemId()){
case R.id.share :
ApplicationInfo api = getApplicationContext().getApplicationInfo();
String apkPatch = api.sourceDir;
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("application/vnd.android.package-archive");
intent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(apkPatch)));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(intent, "ShareVia"));
Toast.makeText(NavigationActivity.this, "shareVia", Toast.LENGTH_SHORT).show();
case R.id.aboutus :
Toast.makeText(getApplicationContext(), "aboutUs", Toast.LENGTH_SHORT).show();
}
return true;
}
});
and this is the error in Run screen
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.chatbox, PID: 19897
android.os.FileUriExposedException: file:///data/app/com.example.chatbox-7bck8l1ys2PwFlDmiMFq2w%3D%3D/base.apk exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:2083)
at android.net.Uri.checkFileUriExposed(Uri.java:2388)
at android.content.ClipData.prepareToLeaveProcess(ClipData.java:977)
at android.content.Intent.prepareToLeaveProcess(Intent.java:10809)
at android.content.Intent.prepareToLeaveProcess(Intent.java:10815)
at android.content.Intent.prepareToLeaveProcess(Intent.java:10794)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1710)
at android.app.Activity.startActivityForResult(Activity.java:5331)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:675)
at android.app.Activity.startActivityForResult(Activity.java:5262)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:662)
at android.app.Activity.startActivity(Activity.java:5660)
at android.app.Activity.startActivity(Activity.java:5628)
at com.example.chatbox.NavigationActivity$1.onNavigationItemSelected(NavigationActivity.java:121)
at com.google.android.material.navigation.NavigationView$1.onMenuItemSelected(NavigationView.java:170)
at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:834)
at androidx.appcompat.view.menu.SubMenuBuilder.dispatchMenuItemSelected(SubMenuBuilder.java:91)
at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158)
at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:985)
at com.google.android.material.internal.NavigationMenuPresenter$1.onClick(NavigationMenuPresenter.java:352)
at android.view.View.performClick(View.java:7257)
at android.view.View.performClickInternal(View.java:7213)
at android.view.View.access$3800(View.java:828)
at android.view.View$PerformClick.run(View.java:27921)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7830)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1040)
I/Process: Sending signal. PID: 19897 SIG: 9
The problem is that for new APIs, a file URI scheme is different than its scheme of old APIs. So creating a file using new File(apkPatch) will raise this exception for newer APIs.
So, you can pass the String to Uri.parse, not the File for solving this instead of using Uri.fromFile
So replace the below line of code:
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(apkPatch)));
With:
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(apkPatch));
I have tried your solutions and it works pretty well but the apk file name is base.apk but i want my app name there(Chat Box) instead of base
Now to change the apk file name add below to the intent
intent.putExtra(Intent.EXTRA_SUBJECT, "Chat Box.apk");

splash screen is not working in android 6

I have added splash screen in my app but the app crashes when is run on Android 6. The interesting thing is that the app runs fine on Android 9.
Don't know what to do.
Target SDK - 28.
min SDK= 19
it is showing error on oncreate method while run app on android 6
splash.java
import android.os.Bundle;
import android.os.Handler;
public class splash extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // it showing error here.
setContentView(R.layout.activity_splash);
int SPLASH_TIME_OUT = 4000;
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent splashintent=new Intent(splash.this,MainActivity.class);
startActivity(splashintent);
finish();
}
}, SPLASH_TIME_OUT);
}
}
logs
06-22 16:17:30.930 10294-10294/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.napps.wallpaper, PID: 10294
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.napps.wallpaper/com.napps.wallpaper.splash}: android.content.res.Resources$NotFoundException: Resource ID #0x7f07009e
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2655)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2725)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1572)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5896)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f07009e
at android.content.res.Resources.getValue(Resources.java:1595)
at androidx.appcompat.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:331)
at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:198)
at androidx.appcompat.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:86)
at androidx.appcompat.app.AppCompatDelegateImpl.<init>(AppCompatDelegateImpl.java:260)
at androidx.appcompat.app.AppCompatDelegate.create(AppCompatDelegate.java:182)
at androidx.appcompat.app.AppCompatActivity.getDelegate(AppCompatActivity.java:520)
at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
at com.napps.wallpaper.splash.onCreate(splash.java:13)
at android.app.Activity.performCreate(Activity.java:6298)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2608)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2725) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1572) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:207) 
at android.app.ActivityThread.main(ActivityThread.java:5896) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 
There might be problem with your drawable Image. While copying image Please check the folder in which you are copying.
Try to add the image in drawable folder not drawable-21
I would suggest to remove old image and Add Image again to proper directory.

easiest way to play mp3 from storage

I'm a newbie. I just want to play mp3 in my app.
I've read the documentation and I browsed through many websites including this one.
The steps should be
MediaPlayer.setDataSource(String) or (context, Uri)
.prepare();
.start();
My file is in /storage/emulated/0/New Folder/ztz3.mp3 ..
if i use External.getExternalDirectory().getPath() the result is /storage/emulated/0/
but it just won't play.
I've browsed many sites.. trying many things but it just didn't work.
I've used permission to read external storage.
and the sites I'm browsing has too many different answers which only confused me more.
some use AudioManager.STREAM.. some use MediaPlayer.create.
and I followed that too.. but it just won't play.
public class MainActivity extends AppCompatActivity {
Button buttonPlay;
MediaPlayer mediaPlayer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button buttonPlay = (Button) findViewById(R.id.buttonPlay);
// String filePath = Environment.getExternalStorageDirectory()+
// "/New Folder/ztz_3_adding.mp3";
// String filePath = "/storage/emulated/0/New Folder/ztz_3_adding.mp3";
Log.e("Dir", Environment.getExternalStorageDirectory().toString());
Log.e("Directory", Environment.getExternalStorageDirectory().getPath());
mediaPlayer = new MediaPlayer();
//mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
// mediaPlayer.setDataSource("/storage/emulated/0/New Folder/ztz_3_adding.mp3");
// mediaPlayer.setDataSource("file://storage/emulated/0/New Folder/ztz_3_adding.mp3");
mediaPlayer.setDataSource(getApplicationContext(),
Uri.parse(Environment.getExternalStorageDirectory().getPath()+
"/New Folder/ztz_3_adding.mp3"));
} catch (IOException e) {
e.printStackTrace();
}
try {
mediaPlayer.prepare();
//mediaPlayer.prepareAsync();
} catch (IOException e) {
e.printStackTrace();
}
buttonPlay.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mediaPlayer.start();
}
});
}
}
I think the problem is in the prepare() method.. but I don't know how to fix it.
I've read and tried a site that said to use static MediaPlayer.create or something.
I just want a simple media player that use a string value that I can change anytime to play mp3 files based on the layout.
thanks for the help before...
the log...
02-25 22:10:08.546 17345-17345/com.echo.tesmediaplayer E/Dir:
/storage/emulated/0 02-25 22:10:08.548
17345-17345/com.echo.tesmediaplayer E/Directory: /storage/emulated/0
02-25 22:10:08.563 17345-17345/? E/MediaPlayer: prepareAsync called in
state 1 02-25 22:10:08.564 17345-17345/? E/AndroidRuntime: FATAL
EXCEPTION: main
Process: com.echo.tesmediaplayer, PID: 17345
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.echo.tesmediaplayer/com.echo.tesmediaplayer.MainActivity}:java.lang.IllegalStateException
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2440)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2500)at
android.app.ActivityThread.access$900(ActivityThread.java:163)at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1362)at
android.os.Handler.dispatchMessage(Handler.java:102) at
android.os.Looper.loop(Looper.java:148) at
android.app.ActivityThread.main(ActivityThread.java:5585) at
java.lang.reflect.Method.invoke(Native Method) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
Caused by: java.lang.IllegalStateExceptionat
android.media.MediaPlayer._prepare(Native Method) at
android.media.MediaPlayer.prepare(MediaPlayer.java:1158) at
com.echo.tesmediaplayer.MainActivity.onCreate(MainActivity.java:48)
at android.app.Activity.performCreate(Activity.java:6279) at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2500)
at android.app.ActivityThread.access$900(ActivityThread.java:163) at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1362)
at android.os.Handler.dispatchMessage(Handler.java:102) at
android.os.Looper.loop(Looper.java:148) at
android.app.ActivityThread.main(ActivityThread.java:5585) at
java.lang.reflect.Method.invoke(Native Method) at
.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
Do you have the permissions set correctly?
You need:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
See: https://developer.android.com/guide/topics/media/mediaplayer.html#manifest

android.content.ActivityNotFoundException: passing url to the intent

I have the following error in my app:
Fatal Exception: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://m.fretebras.com.br/fretes }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
at android.app.Activity.startActivityForResult(Activity.java:3468)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
at android.app.Activity.startActivityForResult(Activity.java:3429)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:856)
at android.app.Activity.startActivity(Activity.java:3671)
at android.app.Activity.startActivity(Activity.java:3639)
at br.lgfelicio.atividades.Checkin.acaoBotao(Checkin.java:773)
at br.lgfelicio.atividades.Checkin$12.onClick(Checkin.java:312)
at android.view.View.performClick(View.java:4461)
at android.view.View$PerformClick.run(View.java:18543)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5118)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(NativeStart.java)
Code with error:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://m.fretebras.com.br/fretes"));
startActivity(i);
The error occurs in versions 6.0.1 android, I have no idea why it's happening, I believe that by passing the url to Intent is all right. Can someone help me?
Seems like no browser installed on your phone. Please verify and to avoid crash use below code.
try {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://m.fretebras.com.br/fretes"));
startActivity(i);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
}
Note - This code will just ignore your crash, if no browser found.

Why is dialog.show() causing my app to crash?

I've been trying to get a dialog message to work on android and the app always crash when it reaches "dialog.show();"
public class Logic extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
dialogBuilder.setTitle("Alarm");
dialogBuilder.setMessage(messageActivity.getMes());
dialogBuilder.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog dialog = dialogBuilder.create();
dialog.show();
}
}
Here is my logcat:
FATAL EXCEPTION: main
Process: it226.myapplicationit226androidapp, PID: 19598
java.lang.RuntimeException: Unable to start receiver it226.myapplicationit226androidapp.Logic: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2732)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
at android.view.ViewRootImpl.setView(ViewRootImpl.java:571)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:310)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
at android.app.Dialog.show(Dialog.java:319)
at it226.myapplicationit226androidapp.Logic.onReceive(Logic.java:65)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2725)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
You can't create dialog from receiver.
Creating dialogs is allowed only from UI components (which have looper).
You could start transparent activity with dialog, which would be the same for user.
You can't create a dialog using the context of a BroadcastReceiver, you has two options to solve this problem:
first one is to create a regular Activity which has only the size of the dialog as a shown part and the full remaining is transparent:
Intent newIntent = new Intent(context, Displayer.class);
newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(newIntent);
second one is to hold your Activity context and then use it in creating the dialog, but at this method you have to make sure what is the activity that is currently open:
// in your activity onCreate
ctx = YourActivity.this; // let's suppose ctx is static and general var
////////////////////////////////////////////////
// in the BroadcastReceiver
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(YourActivity.ctx);

Categories

Resources