我的用户报告当他们尝试使用我的应用程序(而不是启动器应用程序)选择窗口小部件时发生崩溃.我正在使用标准的小部件选择器代码,它始终有效,并且仍适用于所有设备,LG G2和LG G3除外.
我发现了一些类似的问题,但他们都提到了Android 2.1遭遇的崩溃,这是用空数据解决方法解决的(已在我的代码中实现).
还使用了另一种获取小部件的方法,没有官方选择器 - 这有效,但要求应用程序是BIND_APPWIDGET权限的系统应用程序.
任何人都遇到过这个问题,也许找到了解决方法或解决方案?
谢谢
这是代码:
public static void selectWidget(AppWidgetHost appWidgetHost, final Activity activity) {
try {
int appWidgetId = appWidgetHost.allocateAppWidgetId();
Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
addEmptyData(pickIntent);
activity.startActivityForResult(pickIntent, R.id.REQUEST_PICK_APPWIDGET);
} catch (ActivityNotFoundException e) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(activity, activity.getString(R.string.widget_config_no_activity), Toast.LENGTH_SHORT).show();
}
});
}
}
/**
* This avoids a bug in the com.android.settings.AppWidgetPickActivity, which is used
* to select widgets. This just adds empty …Run Code Online (Sandbox Code Playgroud) 根据尝试到ListView点击项目来设置文本菜单标题.ListView包含书签列表 - > FAVICON + BOOKMARK TITLE
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(0, EDIT_ID, 0, R.string.menu_edit);
menu.add(0, DELETE_ID, 0, R.string.menu_delete);
menu.add(0, SHARE_ID, 0, R.string.menu_share);
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo;
View itemID = (info.targetView);
menu.setHeaderTitle("bla" + itemID);
}
Run Code Online (Sandbox Code Playgroud)
当我运行这段代码就说明android.widget.RelativeLayout@423d2389或什么,如果我改变itemID到String itemID = ((TextView) info.targetView).getText().toString();我得到强制关闭的,即使在Eclipse中显示没有错误或当我运行该应用程序长按.
我也希望以同样的方式获得favicon ...
感谢帮助!
我正在查询MediaStore.Images.Media.EXTERNAL_CONTENT_URI,查询工作正常.我能够从每个具有常量的列中获取数据,例如:
currentImage.ImageUrl = imagecursor.getString(imagecursor.getColumnIndex(MediaStore.Images.Media.DATA));
currentImage.Lat = imagecursor.getString(imagecursor.getColumnIndex(MediaStore.Images.Media.LATITUDE));
currentImage.Long = imagecursor.getString(imagecursor.getColumnIndex(MediaStore.Images.Media.LONGITUDE));
Run Code Online (Sandbox Code Playgroud)
宽度/高度列没有常量(不MediaStore.Images.Media.WIDTH)所以我试图访问它们imagecursor.getLong(imagecursor.getColumnIndex("width"));.
试图使用getLong,getString,getInt ......没有 - 总是一样崩溃.
这是堆栈:
02-22 19:38:26.242: E/AndroidRuntime(1607): FATAL EXCEPTION: main
02-22 19:38:26.242: E/AndroidRuntime(1607): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.MEDIA_SCANNER_FINISHED dat=file:///mnt/sdcard flg=0x10 } in com.Activity.android.chat.service.ChatService$ChatServiceReceiver@415b26c0
02-22 19:38:26.242: E/AndroidRuntime(1607): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:737)
02-22 19:38:26.242: E/AndroidRuntime(1607): at android.os.Handler.handleCallback(Handler.java:605)
02-22 19:38:26.242: E/AndroidRuntime(1607): at android.os.Handler.dispatchMessage(Handler.java:92)
02-22 19:38:26.242: E/AndroidRuntime(1607): at android.os.Looper.loop(Looper.java:137)
02-22 19:38:26.242: E/AndroidRuntime(1607): at android.app.ActivityThread.main(ActivityThread.java:4424)
02-22 19:38:26.242: E/AndroidRuntime(1607): at java.lang.reflect.Method.invokeNative(Native Method)
02-22 19:38:26.242: E/AndroidRuntime(1607): at java.lang.reflect.Method.invoke(Method.java:511)
02-22 …Run Code Online (Sandbox Code Playgroud) 当用户在AlertDialog中单击"确定"时,我想将变量传递给外部函数.我正在尝试这个例子,但它不会识别变量(Yup).
public final void deleteBookmark(Cursor cur, int pos) {
//fetching info
((Cursor) cur).moveToPosition(pos);
String bookmark_id = ((Cursor) cur).getString(((Cursor) cur).getColumnIndex(Browser.BookmarkColumns._ID));
String bookmark_title = ((Cursor) cur).getString(((Cursor) cur).getColumnIndex(Browser.BookmarkColumns.TITLE));
//asking user to approve delete request
AlertDialog alertDialog = new AlertDialog.Builder(Dmarks.this).create();
alertDialog.setTitle("Delete" + " " + bookmark_title);
alertDialog.setIcon(R.drawable.icon);
alertDialog.setMessage("Are you sure you want to delete this Bookmark?");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
**String Yup = "yes";**
} });
alertDialog.setButton2("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { …Run Code Online (Sandbox Code Playgroud) 我的应用程序可以选择创建主屏幕快捷方式.
我创建这样的快捷方式:
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
new Intent(ShortcutCreateActivity.this, ShortcutCreateActivity.class).putExtra(EXTRA_PROFILE_ID, profileId).putExtra(EXTRA_PROFILE_ACTION, item));
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, profileTitle);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);
Run Code Online (Sandbox Code Playgroud)
这按预期工作...当用户单击快捷方式时,ShortcutCreateActivity会启动,我会按照我的需要执行操作.
然而!我想避免开展活动的必要性.相反,我想创建一个发送广播的快捷方式.
我尝试用以下方法替换意图:
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
new Intent(INTENT_ACTION_THAT_I_WANT)
Run Code Online (Sandbox Code Playgroud)
但是当我单击快捷方式时,它会显示Toast"App is not installed".
是否可以创建发送广播而不是启动活动的主屏幕快捷方式?
(开始活动并快速完成它不是一种选择).
谢谢!
我一直在尝试按照这些说明实现Material Design主题.
ToolBar(我必须吗?)getSupportActionBar()整个项目.<application>标签包含android:theme="@style/AppTheme"我的styles.xml:
<style name="AppBaseTheme" parent="@style/Theme.AppCompat">
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar.Solid">
<item name="displayOptions">useLogo|showHome</item>
<item name="logo">@drawable/home_page_logo</item>
<item name="background">@color/actionbar_background_color</item>
<item name="textColor">@color/white</item>
<item name="titleTextStyle">@style/MyActionBarTextStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)
无论我尝试了什么,应用程序崩溃第二次我onCreate()使用此崩溃日志启动我的主要活动:
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this …Run Code Online (Sandbox Code Playgroud) 我知道如何使用Intents打开URL:
Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.lala.com"));
startActivity(browserIntent);
Run Code Online (Sandbox Code Playgroud)
但是如何在新窗口/选项卡上打开多个URL?
尝试创建几个Intent并使用不同的startActivity打开每个Intent但它只打开列表中的最后一个;
code code code
startActivity(Intent1); startActivity(Intent2); startActivity(Intent3); -> only Intent3 is opened eventually (which of course make sense :)).
Run Code Online (Sandbox Code Playgroud)
感谢任何帮助!
更新:仍在寻找答案:/
我想出了一个可能的解决方案,它确实在一个新窗口中打开了URL.
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.go.com"));
Bundle b = new Bundle();
b.putBoolean("new_window", true); //sets new window
intent.putExtras(b);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
以某种方式启动Activity以立即打开多个URL?用setResult()和startActivityForResult()的东西可能吗?
我想这些问题的标题说明了一切,或者什么也没说......经过几个小时的谷歌搜索,尝试和重新发明Java我决定问你.
我有这个存储类:
class AppInfo implements Comparable<AppInfo > {
private String appname = "";
private String pname = "";
private String versionName = "";
//private int versionCode = 0;
private Drawable icon;
private String appdir = "";
private String appSize = "";
@Override
public int compareTo(AppInfo other) {
int compareAppsName = appname.compareToIgnoreCase(other.appname);
return compareAppsName;
}
}
Run Code Online (Sandbox Code Playgroud)
我做我做的事情,最终我得到一个填充对象的List.一切都很好,ListView填充了正确的数据......
现在我想搜索一个字符串(某个pname)并查看它是否存在于List中,如果存在,它在列表中的位置(它的索引)是什么.
尝试创建另一个列表,只包含我需要的数据..尝试了Lists,HashMaps,LinkedHashMap,2维数组/ arrayList ......没有做到这一点......还尝试迭代列表但无法弄清楚如何处理元素我有.
希望我有所作为,甚至可能.
披露:请耐心等待,我是Java的新人.
对前一个问题的后续问题 - 编译ICS/JB相机应用程序 - 本机库jni-mosaic错误
我一直在尝试从CyanogenMod来源构建ICS相机应用程序.我在Windows 7上,UAC关闭.使用Cygwin和最新的Android NDK.
尝试使用chmod -R 777的工作空间,添加了NDK_TOOLCHAIN_VERSION := 4.4.3和LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog我的Android.mk文件,但无论我做什么,我仍然得到这个错误:
Compile++ thumb : jni_mosaic <= feature_mos_jni.cpp
In file included from jni/feature_mos_jni.cpp:21:0:
C:/android-ndk/platforms/android-14/arch-arm/usr/include/jni.h:592:13: note: the mangling of 'va_list' has changed in GCC 4.4
Compile++ thumb : jni_mosaic <= mosaic_renderer_jni.cpp
In file included from jni/mosaic_renderer_jni.cpp:19:0:
C:/android-ndk/platforms/android-14/arch-arm/usr/include/jni.h:592:13: note: the mangling of 'va_list' has changed in GCC 4.4
Compile++ thumb : jni_mosaic <= trsMatrix.cpp
Compile++ thumb : jni_mosaic <= AlignFeatures.cpp …Run Code Online (Sandbox Code Playgroud)