我想创建一个Android应用程序,它将能够扫描条形码,获取条形码中包含的信息,然后能够以某种方式使用该信息.
我不知道如何创建一个条形码扫描仪,所以我去Googling,似乎Zxing是在应用程序中实现条形码扫描仪最常用的方式.
一些链接:
http://code.google.com/p/zxing/
http://awalkingcity.com/blog/2008/08/25/qr-codes-made-easy-in-android/
然而,我在zxing上找到的样本涉及必须提示用户进入市场并安装zxing条形码扫描器,以便我的应用程序可以在需要时调用条形码扫描器,然后条形码扫描器将信息返回到我的应用程序.
虽然这对我来说是一个很好的起点,但我想知道是否有其他选项可以让我在我自己的应用程序中嵌入条形码扫描器而无需提示用户下载辅助应用程序?
我目前正在学习Android中的小部件.
我想创建一个WIFI小部件,它将显示SSID,即RSSI(信号)级别.
但我也希望能够从我正在运行的服务中发送数据,通过wifi计算声音质量.
以下是我阅读和快速教程后的内容:
public class WlanWidget extends AppWidgetProvider{
RemoteViews remoteViews;
AppWidgetManager appWidgetManager;
ComponentName thisWidget;
WifiManager wifiManager;
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
Timer timer = new Timer();
timer.scheduleAtFixedRate(new WlanTimer(context, appWidgetManager), 1, 10000);
}
private class WlanTimer extends TimerTask{
RemoteViews remoteViews;
AppWidgetManager appWidgetManager;
ComponentName thisWidget;
public WlanTimer(Context context, AppWidgetManager appWidgetManager) {
this.appWidgetManager = appWidgetManager;
remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
thisWidget = new ComponentName(context, WlanWidget.class);
wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
}
@Override
public void run() {
remoteViews.setTextViewText(R.id.widget_textview,
wifiManager.getConnectionInfo().getSSID());
appWidgetManager.updateAppWidget(thisWidget, remoteViews); …Run Code Online (Sandbox Code Playgroud) 我有一个运行的服务,当它收到一条消息说它必须被更改时,它会更新通知栏中的通知.
但是,有时在更新通知时会出现以下错误
java.lang.IllegalArgumentException: contentIntent required
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
变量设置
int icon = R.drawable.notification;
CharSequence tickerText = "Test";
long when = System.currentTimeMillis();
PendingIntent contentIntent;
Notification notification = new Notification(icon, tickerText, when);
NotificationManager mNotificationManager;
Run Code Online (Sandbox Code Playgroud)
NotificationManager创建
String ns = Context.NOTIFICATION_SERVICE;
mNotificationManager = (NotificationManager) getSystemService(ns);
Run Code Online (Sandbox Code Playgroud)
通知创建
Intent notificationIntent = new Intent(this, TestsApp.class);
contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.flags |= Notification.FLAG_NO_CLEAR;
notification.icon = R.drawable.notification3;
notification.setLatestEventInfo(this, "Registering", "Test", contentIntent);
mNotificationManager.notify(1, notification);
Run Code Online (Sandbox Code Playgroud)
更新通知
notification.icon = R.drawable.notification2;
notification.setLatestEventInfo(getApplicationContext(), "Registered", "Test", contentIntent);
mNotificationManager.notify(1, notification);
Run Code Online (Sandbox Code Playgroud)
所以有些事情发生在我的内容的某个地方,这是正确的吗?
它在我的Service类的顶部被声明为一个成员变量,并且除了上面显示的代码之外没有在代码中的任何其他地方使用,所以哪里可以重置为null?
我有以下XML代码CheckBoxPreference:
<CheckBoxPreference
android:key="pref_boot_startup"
android:title="Auto start"
android:defaultValue="true" />
Run Code Online (Sandbox Code Playgroud)
但是,当我在代码中检索首选项时,值为false.
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean autoStart = sharedPreferences.getBoolean("pref_boot_startup", true);
Run Code Online (Sandbox Code Playgroud)
我的autoStart变量返回false.
这有什么特别的原因吗?我错过了将默认值设置为的步骤true吗?
我想知道是否有人可以判断如何在原生Android屏幕上弹出对话框屏幕?
我目前有一个应用程序可以捕获拨出呼叫并停止呼叫,然后我想弹出一个对话框,该对话框将从拨号器屏幕接管并提醒用户已尝试呼叫被阻止并允许他们从中获取一些新选项对话框.
我知道有些人会说我应该使用通知,但我知道它并不是它应该工作的方式,我需要能够在呼叫被困时弹出一个对话框.
到目前为止,这是我的对话框代码
AlertDialog LDialog = new AlertDialog.Builder(context)
.setTitle("Call Blocked")
.setMessage("Call Blocked, reroute call?")
.setPositiveButton("ok", null).create();
LDialog.show();
Run Code Online (Sandbox Code Playgroud)
我认为我必须以某种方式获得拨号屏幕的上下文?
任何人都可以提供任何帮助和帮助或指向教程的链接?
提前致谢
我的appplication中的服务中有以下方法:
public void switchSpeaker(boolean speakerFlag){
if(speakerFlag){
audio_service.setSpeakerphoneOn(false);
}
else{
audio_service.setSpeakerphoneOn(true);
}
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是能够在如下的Activity中使用此方法的最佳和最有效的方法
final Button speaker_Button = (Button) findViewById(R.id.widget36);
speaker_Button.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
switchSpeaker(true); //method from Service
}
});
Run Code Online (Sandbox Code Playgroud)
我必须做AIDL还是有更简单的方法?
我正在尝试注册我的活动,以便活动选择器/选择器可以使用它,允许用户选择是否选择我的应用程序/活动来完成他们想要做的事情.
我想为用户提供选项,以便能够在他们想要发送短信时选择我的应用程序,当他们想要拨打电话时,为了尝试实现这一点,我在我的Activity标签中添加了以下代码段在我的清单中:
<intent-filter>
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
但是,活动选择器永远不会出现,并且在不向用户提供选择的情况下使用本机应用程序.任何人都可以看到我错在哪里?
编辑:
我发现我需要添加
<data android:scheme="sms" />
<data android:scheme="smsto" />
Run Code Online (Sandbox Code Playgroud)
对于短信,但我将如何用于拨打电话?
编辑2:
我为传出呼叫尝试了以下内容:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.DIAL" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="tel" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
但是再次没有运气,这是否被阻止了1.6?
编辑3:
当我点击Text Mobile时会发生这种情况:

所以当我点击Call mobile时我想要同样的事情
我目前在以下URI"content:// sms /"上注册了一个内容观察者,以监听正在发送的传入和传出消息.
这似乎工作正常,我也尝试从短信数据库中删除但我只能删除以下URI中的整个线程"content:// sms/conversations /"
这是我用于此的代码
String url = "content://sms/";
Uri uri = Uri.parse(url);
getContentResolver().registerContentObserver(uri, true, new MyContentObserver(handler));
}
class MyContentObserver extends ContentObserver {
public MyContentObserver(Handler handler) {
super(handler);
}
@Override public boolean deliverSelfNotifications() {
return false;
}
@Override public void onChange(boolean arg0) {
super.onChange(arg0);
Log.v("SMS", "Notification on SMS observer");
Message msg = new Message();
msg.obj = "xxxxxxxxxx";
handler.sendMessage(msg);
Uri uriSMSURI = Uri.parse("content://sms/");
Cursor cur = getContentResolver().query(uriSMSURI, null, null,
null, null);
cur.moveToNext();
String protocol = cur.getString(cur.getColumnIndex("protocol"));
if(protocol == null){ …Run Code Online (Sandbox Code Playgroud) 我刚刚学习如何开发Android Wear,我已经为智能手表创建了一个全屏活动,在我的应用程序的移动部分,我获得了一些JSON数据,并从中创建了一个自定义对象列表.
在我的移动应用程序中,我在ListView中显示这些对象的信息.
在我的应用程序的Wear部分,我想显示此列表的限制版本,例如列表中的前3个将显示在Wearable上的全屏应用程序上.
我的问题是,似乎没有办法将Parcelable Objects发送到Android Wear,因此在DataItem中没有putParcelable选项.
看起来唯一的选择是以字节为单位发送对象,如下所示:
public void sendWearableData(GoogleApiClient aGoogleApiClient, ArrayList<MyObject> myObjectList, String path)
{
googleApiClient = aGoogleApiClient;
byte[] testBytes = new byte[0];
if (googleApiClient.isConnected()) {
PutDataMapRequest dataMapRequest = PutDataMapRequest.create(path);
try {
testBytes = BytesUtils.toByteArray(myObjectList);
} catch (IOException e) {
e.printStackTrace();
}
dataMapRequest.getDataMap().putByteArray(Constants.TEST_KEY, testBytes);
PutDataRequest request = dataMapRequest.asPutDataRequest();
Wearable.DataApi.putDataItem(googleApiClient, request);
}
}
Run Code Online (Sandbox Code Playgroud)
所以我必须将我的对象转换为字节,将其发送到Android Wear并将其转换回来?这意味着我已经实现了Parcelable的对象,所以我现在可以通过Intents发送它们也需要实现Serializable,这是正确的还是有更好的方法呢?
android serializable parcelable android-wear-data-api wear-os
我试图在我的Android应用程序中加密和解密字符串但我不断收到InvalidKeyException错误.
这是我的代码:
//生成密钥方法
public void generateKeys() {
Calendar cal = Calendar.getInstance();
Date now = cal.getTime();
cal.add(Calendar.YEAR, 25);
Date end = cal.getTime();
KeyPairGenerator kpg = null;
try {
kpg = KeyPairGenerator.getInstance("RSA", "AndroidKeyStore");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchProviderException e) {
e.printStackTrace();
}
try {
kpg.initialize(new KeyPairGeneratorSpec.Builder(context)
.setAlias(KEY_ALIAS)
.setStartDate(now)
.setEndDate(end)
.setSerialNumber(BigInteger.valueOf(1))
.setSubject(new X500Principal("CN=" + KEY_ALIAS))
.build());
} catch (InvalidAlgorithmParameterException e) {
e.printStackTrace();
}
KeyPair kp = kpg.generateKeyPair();
KeyStore ks = null;
try {
ks = KeyStore.getInstance("AndroidKeyStore");
ks.load(null);
Enumeration<String> aliases …Run Code Online (Sandbox Code Playgroud) android ×10
java ×2
aidl ×1
dialog ×1
dynamic ×1
encryption ×1
intentfilter ×1
native ×1
parcelable ×1
popup ×1
private-key ×1
screen ×1
serializable ×1
service ×1
sms ×1
uri ×1
wear-os ×1
widget ×1
zxing ×1