android.content.ActivityNotFoundException: passing url to the intent - java

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.

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");

CustomTabsIntent launchUrl throws SecurityException - Permission Denial

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

Twitter No package identifier when getting value for resource number 0x00000000

I'm trying to implement twitter login in my android app.
I've followed the instructions ( https://dev.twitter.com/twitter-kit/android/twitter-login ) but when I call Fabric.with(this, new Twitter(authConfig)); the following exception occur.
06-02 14:03:00.267 5623-5638/it.quepasa W/ResourceType﹕ No package identifier when getting value for resource number 0x00000000
06-02 14:03:00.323 5623-5638/it.quepasa E/Fabric﹕ Could not calculate hash for app icon.
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:1033)
at android.content.res.Resources.openRawResource(Resources.java:958)
at android.content.res.Resources.openRawResource(Resources.java:940)
at io.fabric.sdk.android.services.common.CommonUtils.getAppIconHashOrNull(CommonUtils.java:861)
at io.fabric.sdk.android.Onboarding.doInBackground(Onboarding.java:97)
at io.fabric.sdk.android.Onboarding.doInBackground(Onboarding.java:45)
at io.fabric.sdk.android.InitializationTask.doInBackground(InitializationTask.java:63)
at io.fabric.sdk.android.InitializationTask.doInBackground(InitializationTask.java:28)
at io.fabric.sdk.android.services.concurrency.AsyncTask$2.call(AsyncTask.java:311)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:838)
06-02 14:03:00.331 5623-5638/it.quepasa W/ResourceType﹕ No package identifier when getting value for resource number 0x00000000
06-02 14:03:00.333 5623-5638/it.quepasa E/Fabric﹕ Could not calculate hash for app icon.
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:1033)
at android.content.res.Resources.openRawResource(Resources.java:958)
at android.content.res.Resources.openRawResource(Resources.java:940)
at io.fabric.sdk.android.services.common.CommonUtils.getAppIconHashOrNull(CommonUtils.java:861)
at io.fabric.sdk.android.services.settings.Settings.initialize(Settings.java:90)
at io.fabric.sdk.android.Onboarding.retrieveSettingsData(Onboarding.java:123)
at io.fabric.sdk.android.Onboarding.doInBackground(Onboarding.java:99)
at io.fabric.sdk.android.Onboarding.doInBackground(Onboarding.java:45)
at io.fabric.sdk.android.InitializationTask.doInBackground(InitializationTask.java:63)
at io.fabric.sdk.android.InitializationTask.doInBackground(InitializationTask.java:28)
at io.fabric.sdk.android.services.concurrency.AsyncTask$2.call(AsyncTask.java:311)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:838)
I've tried to redo all the process using fabric plugin for android studio but it just redo the steps that I did manually and the problem persists.
Another exception occur when I tap on the login button:
06-02 11:22:23.611 24124-24124/it.quepasa E/Twitter﹕ Failed to get request token
com.twitter.sdk.android.core.TwitterApiException: method POST must have a request body.
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:400)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at retrofit.Platform$Android$2$1.run(Platform.java:142)
at java.lang.Thread.run(Thread.java:838)
06-02 11:22:23.686 24124-24124/it.quepasa E/Twitter﹕ Authorization completed with an error
com.twitter.sdk.android.core.TwitterAuthException: Failed to get request token
at com.twitter.sdk.android.core.identity.OAuthController$1.failure(OAuthController.java:78)
at com.twitter.sdk.android.core.internal.oauth.OAuth1aService$1.failure(OAuth1aService.java:198)
at com.twitter.sdk.android.core.Callback.failure(Callback.java:28)
at retrofit.CallbackRunnable$2.run(CallbackRunnable.java:53)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5370)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Here there is my code:
AndroidManifest.xml:
<meta-data
android:name="io.fabric.ApiKey"
android:value="XXXXXXXX" />
MainActivity.java:
TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
Fabric.with(this, new Twitter(authConfig), new Crashlytics()); //I've tried without crashlytics, same problem. Crashlytics works..
LoginActivity.java:
loginButton = (TwitterLoginButton) findViewById(R.id.twitter_login_buttons);
loginButton.setCallback(new Callback<TwitterSession>() {
#Override
public void success(Result<TwitterSession> result) {
Log.d(TAG, "Success");
}
#Override
public void failure(TwitterException exception) {
Log.d(TAG, "Failure");
}
});
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
loginButton.onActivityResult(requestCode, resultCode, data);
}
Any idea? I'm loosing too much time on this :(
Thank you!
Note: I don't have the twitter app installed. It's supposed to work in a webview.
Found the issue with the first exception. Apparently there are two different problems.
In my AndroidManifest.xml I was missing the attribute android:icon in <application ...>
I hope this will help others.

Activity crashes because of Intent with ACTION_SEND

I have an Intent to share a image from an view. It works, but once I canceled it to upload it on Instagram and I received an exception.
Google didn't help...
Intent
if(!getStringName().equals(" ")) {//check if it is usefull
LinearLayout table=(LinearLayout) findViewById(R.id.table_linear);
table.setDrawingCacheEnabled(true);
Bitmap bitmap = table.getDrawingCache();
String imagepath=saveBitmap(bitmap);
//sv.setDrawingCacheEnabled(false);
Intent shareImage=new Intent();
shareImage.setAction(Intent.ACTION_SEND);
shareImage.setType("image/png");
shareImage.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name));
shareImage.putExtra(Intent.EXTRA_TEXT, getStringName());
shareImage.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imagepath)));
startActivity(shareImage);
//new RalaAlertToast(context, getString(R.string.share_success), false);
}else {
//show message, that it's not useful
}
Stack Trace
java.lang.RuntimeException: Unable to start activity ComponentInfo{at.ralaweb.ralaprogramme.subnetztabelle/at.ralaweb.ralaprogramme.subnetztabelle.ActivityMain}: java.lang.RuntimeException: Parcel android.os.Parcel#41f7d760: Unmarshalling unknown type code 2131558402 at offset 200
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2227)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2276)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5146)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Parcel android.os.Parcel#41f7d760: Unmarshalling unknown type code 2131558402 at offset 200
at android.os.Parcel.readValue(Parcel.java:2080)
at android.os.Parcel.readSparseArrayInternal(Parcel.java:2363)
at android.os.Parcel.readSparseArray(Parcel.java:1735)
at android.os.Parcel.readValue(Parcel.java:2070)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2314)
at android.os.Bundle.unparcel(Bundle.java:249)
at android.os.Bundle.getSparseParcelableArray(Bundle.java:1273)
at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1794)
at android.app.Activity.onRestoreInstanceState(Activity.java:948)
at android.app.Activity.performRestoreInstanceState(Activity.java:920)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1138)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
... 12 more
another thing: should I disable the drawing cache after the export?

Broadcast receiver, check a checkbox preference state on bootup then send a notification

My problem is that when I try to read a checkbox preference state from a different activity on bootup then send a status bar notification. Then when the device boots the I get a force close error message popup then when I go into the error log I don't understand what happens.
The code for the broadcast receiver is shown below:
#Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
//this creates a reference to my preferences activity
Prefs prefsC = new Prefs();
SharedPreferences prefs = context.getSharedPreferences("Prefs", 0);
int status = Integer.parseInt(prefs.getString("bootup", "-1"));
if(status > 0){
//notifyNS is a method that sends the status bar notification
prefsC.notifyNS("", R.drawable.n);
//the setCheckedNS method is just a custom method I made to set the state of a checkbox preference
prefsC.setCheckedNS("icon", false);
}else{
prefsC.setCheckedNS("enable", false);
prefsC.setCheckedNS("icon", false);
prefsC.setCheckedNS("bootup", false);
}
}
}
So could you help me solve the issue on why it force closes on bootup. So basically what I want to do is read a checkbox preference state on bootup then send a status bar notification.
This is my error log response:
04-16 11:23:15.546: ERROR/AndroidRuntime(977): FATAL EXCEPTION: main
04-16 11:23:15.546: ERROR/AndroidRuntime(977): java.lang.RuntimeException: Unable to instantiate receiver com.brandon.labs.nsettings.receivers.notifyBootup: java.lang.ClassNotFoundException: com.brandon.labs.nsettings.receivers.notifyBootup in loader dalvik.system.PathClassLoader[/data/app/com.brandon.labs.nsettings-1.apk]
04-16 11:23:15.546: ERROR/AndroidRuntime(977): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2913)
04-16 11:23:15.546: ERROR/AndroidRuntime(977): at android.app.ActivityThread.access$3200(ActivityThread.java:135)
04-16 11:23:15.546: ERROR/AndroidRuntime(977): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2198)
04-16 11:23:15.546: ERROR/AndroidRuntime(977): at android.os.Handler.dispatchMessage(Handler.java:99)
04-16 11:23:15.546: ERROR/AndroidRuntime(977): at android.os.Looper.loop(Looper.java:144)
04-16 11:23:15.546: ERROR/AndroidRuntime(977): at android.app.ActivityThread.main(ActivityThread.java:4937)
04-16 11:23:15.546: ERROR/AndroidRuntime(977): at java.lang.reflect.Method.invokeNative(Native Method)
04-16 11:23:15.546: ERROR/AndroidRuntime(977): at java.lang.reflect.Method.invoke(Method.java:521)
04-16 11:23:15.546: ERROR/AndroidRuntime(977): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-16 11:23:15.546: ERROR/AndroidRuntime(977): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-16 11:23:15.546: ERROR/AndroidRuntime(977): at dalvik.system.NativeStart.main(Native Method)
04-16 11:23:15.546: ERROR/AndroidRuntime(977): Caused by: java.lang.ClassNotFoundException: com.brandon.labs.nsettings.receivers.notifyBootup in loader dalvik.system.PathClassLoader[/data/app/com.brandon.labs.nsettings-1.apk]
04-16 11:23:15.546: ERROR/AndroidRuntime(977): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-16 11:23:15.546: ERROR/AndroidRuntime(977): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-16 11:23:15.546: ERROR/AndroidRuntime(977): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-16 11:23:15.546: ERROR/AndroidRuntime(977): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2904)
04-16 11:23:15.546: ERROR/AndroidRuntime(977): ... 10 more
So I have no clue what to do from here.
Alright I have figured out what I have done wrong. What it is how I was connecting the context to the notificationManger construct method and Intent construct method.
Here is my new and revised code that works:
`public class BootupReceiver extends BroadcastReceiver {
private static final boolean BOOTUP_TRUE = true;
private static final String BOOTUP_KEY = "bootup";
#Override
public void onReceive(Context context, Intent intent) {
if(getBootup(context)) {
Toast toast2 = Toast.makeText(context, "getBootup", Toast.LENGTH_SHORT);
toast2.show();
NotificationManager NotifyM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification Notify = new Notification(R.drawable.n,
"NSettings Enabled", System.currentTimeMillis());
Notify.flags |= Notification.FLAG_NO_CLEAR;
Notify.flags |= Notification.FLAG_ONGOING_EVENT;
RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification);
Notify.contentView = contentView;
Intent notificationIntent = new Intent(context, Toggles.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
Notify.contentIntent = contentIntent;
Toast toast = Toast.makeText(context, "Notify about to be sent", Toast.LENGTH_SHORT);
toast.show();
int HELO_ID = 00000;
NotifyM.notify(HELLO_ID, Notify);
Toast toast1 = Toast.makeText(context, "Notify sent", Toast.LENGTH_SHORT);
toast1.show();
}
Intent serviceIntent = new Intent();
serviceIntent.setAction("com.brandon.labs.nsettings.NotifyService");
context.startService(serviceIntent);
}
public static boolean getBootup(Context context){
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(BOOTUP_KEY, BOOTUP_TRUE);
}
}
`
Since this question has gotten more than 100 views I thought it would be nice of me to post the code that works properly.
Note: I don't know why the closing curly bracket for the class isn't showing with the rest of the code it's a stackoverflow error
According to log ('java.lang.RuntimeException: Unable to instantiate receiver'), system is unable to create instance of your receiver class, because system is unable to find specified class (com.brandon.labs.nsettings.receivers.notifyBootup). I think it is probably problems with name (of receiver class) in your AndroidManifest.xml file, and it is not related to preferences.
In future, if you will get another exception, i recommend you to read carefully message of exception ;) and stack trace. Usually they contains the half of answer to your question.
And for popular mistakes - you can try to type exception text into Google (excluding some specific info such as name of class), and you will find solution very fast.
Have you added the following to your AndroidManifest.xml along with registering the BroadcastReceiver??
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

Categories

Resources