我创建了一个应用程序,您可以在其中下载Android视频.现在,我想要它,以便如果您在YouTube原生应用中播放视频,您也可以下载它.为此,我需要了解YouTube原生应用推出的Intent才能播放YouTube应用.
如果我在我的模拟器上安装了YouTube程序,我可以轻松地做到这一点,所以我的第一个问题是:
1.我可以为我的模拟器下载YouTube应用程序,或者......
2.当用户选择视频时使用的意图是什么用于播放.
我正在使用singleTop Activity来通过搜索对话框接收意图onNewIntent().
我注意到的是onPause()之前调用过onNewIntent(),然后调用它onResume().视觉:
onPause()onNewIntent()onResume()问题是我有注册的监听器onResume()被删除onPause(),但在onNewIntent()通话中需要它们.有没有一种标准方法可以让这些听众可用?
我的应用程序安装其他应用程序,它需要跟踪它已安装的应用程序.当然,这可以通过简单地保留已安装的应用程序列表来实现.但这不应该是必要的!PackageManager应该负责维护installedBy(a,b)关系.事实上,根据API,它是:
public abstract String getInstallerPackageName(String packageName) - 检索安装包的应用程序的包名称.这确定了包裹来自哪个市场.
使用Intent安装APK
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
使用Intent卸载APK:
Intent intent = new Intent(Intent.ACTION_DELETE, Uri.fromParts("package",
getPackageManager().getPackageArchiveInfo(apkUri.getPath(), 0).packageName,null));
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
这显然不是Android Market安装/卸载软件包的方式.他们使用更丰富的PackageManager版本.通过从Android Git存储库下载Android源代码可以看到这一点.以下是与Intent方法相对应的两种隐藏方法.不幸的是,外部开发人员无法使用它们.但也许他们将来会是这样?
使用PackageManager安装APK
/**
* @hide
*
* Install a package. Since this may take a little while, the result will
* be posted back to the given observer. An installation will fail if the calling context
* lacks the {@link android.Manifest.permission#INSTALL_PACKAGES} permission, if the
* package named in …Run Code Online (Sandbox Code Playgroud) 我知道如何更新我自己的程序,我知道如何使用预定义的Uri打开程序(例如短信或电子邮件)
我需要知道如何创建一个Intent来打开MyTracks或任何其他我不知道他们听什么意图的应用程序.
我从DDMS那里获得了这些信息,但我没有成功将其转化为我可以使用的Intent.这是在手动打开MyTracks时获取的.
谢谢你的帮助
05-06 11:22:24.945: INFO/ActivityManager(76): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.google.android.maps.mytracks/com.google.android.apps.mytracks.MyTracks bnds=[243,338][317,417] }
05-06 11:22:25.005: INFO/ActivityManager(76): Start proc com.google.android.maps.mytracks for activity com.google.android.maps.mytracks/com.google.android.apps.mytracks.MyTracks: pid=1176 uid=10063 gids={3003, 1015}
05-06 11:22:26.995: INFO/ActivityManager(76): Displayed activity com.google.android.maps.mytracks/com.google.android.apps.mytracks.MyTracks: 1996 ms (total 1996 ms)
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用intent分享一些文本:
Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_TEXT, "TEXT");
Run Code Online (Sandbox Code Playgroud)
和选择器翘曲:
startActivity(Intent.createChooser(sms, getResources().getString(R.string.share_using)));
Run Code Online (Sandbox Code Playgroud)
有用!但仅适用于电子邮件应用.
我需要的是所有消息应用程序的一般意图:电子邮件,短信,IM(Whatsapp,Viber,Gmail,SMS ...)尝试使用android.content.Intent.ACTION_VIEW
并尝试使用i.setType("vnd.android-dir/mms-sms");任何帮助...
("vnd.android-dir/mms-sms"仅使用sms共享!)
我正在尝试创建一个应用程序,当一个电话来到手机我想要检测数字.以下是我尝试过的,但它没有检测来电.
我想MainActivity在后台运行,我该怎么做?
我已经在manifest档案中给予了许可.
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Run Code Online (Sandbox Code Playgroud)
我应该在清单中提供其他任何东西吗?
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_layout);
}
public class myPhoneStateChangeListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
if (state == TelephonyManager.CALL_STATE_RINGING) {
String phoneNumber = incomingNumber;
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我的应用程序有通知,这是 - 很明显 - 没有任何标志,每次启动一个新的活动,所以我得到对方的顶部,这是错误的运行多个同样的活动.
我想要它做的是将通知挂起意图中指定的活动带到前面(如果它已在运行),否则启动它.
到目前为止,我所拥有的通知的意图/待定意图是
private static PendingIntent prepareIntent(Context context) {
Intent intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
Run Code Online (Sandbox Code Playgroud)
奇怪的是,它有时会起作用,有时它不会......我觉得我已经尝试了每一个标志组合.
android android-intent android-activity android-pendingintent
我MainActicity 开始RefreshService用Intent具有boolean所谓的多余isNextWeek.
我RefreshService做了一个在用户点击它时Notification启动我MainActivity的.
这看起来像这样:
Log.d("Refresh", "RefreshService got: isNextWeek: " + String.valueOf(isNextWeek));
Intent notificationIntent = new Intent(this, MainActivity.class);
notificationIntent.putExtra(MainActivity.IS_NEXT_WEEK, isNextWeek);
Log.d("Refresh", "RefreshService put in Intent: isNextWeek: " + String.valueOf(notificationIntent.getBooleanExtra(MainActivity.IS_NEXT_WEEK,false)));
pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
builder = new NotificationCompat.Builder(this).setContentTitle("Title").setContentText("ContentText").setSmallIcon(R.drawable.ic_notification).setContentIntent(pendingIntent);
notification = builder.build();
// Hide the notification after its selected
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(NOTIFICATION_REFRESH, notification);
Run Code Online (Sandbox Code Playgroud)
你可以看到notificationIntent应该有boolean额外IS_NEXT_WEEK的值,isNextWeek其中放入了PendingIntent.
当我现在点击这个时, …
android android-intent android-service android-pendingintent
我是新来的Android和我想明白之间的差别getApplication(),getApplicationContext()getBaseContext(),getContext()以及someClass.this特别是当使用这些方法在下面的代码行:
当我发起祝酒时,这些和我使用它们之间有什么区别?
Toast.makeText(LoginActivity.this, "LogIn successful", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplication(), "LogIn successful", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "LogIn successful", Toast.LENGTH_SHORT).show();
Toast.makeText(getBaseContext(), "LogIn successful", Toast.LENGTH_SHORT).show();
Run Code Online (Sandbox Code Playgroud)
与意图相同:
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
Intent intent = new Intent(MenuPagina., LoginActivity.class);
Intent intent = new Intent(getBaseContext(), LoginActivity.class);
Intent intent = new Intent(getApplication(), LoginActivity.class);
Run Code Online (Sandbox Code Playgroud) 我有一个需要捕获两个不同广播的Android活动.我目前的方法是BroadcastReceiver在Activity中使用一个单独的方法来捕获广播:
public class MyActivity extends Activity {
private MyActivity.BroadcastListener mBroadcastListener;
private boolean mIsActivityPaused = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
// Create the broadcast listener and register the filters
mIsActivityPaused = false;
mBroadcastListener = new BroadcastListener();
IntentFilter filter = new IntentFilter();
filter.addAction(Params.INTENT_REFRESH);
filter.addAction(Params.INTENT_UPDATE);
registerReceiver(mBroadcastListener, filter);
}
@Override
protected void onResume() {
super.onResume();
mIsActivityPaused = false;
}
@Override
protected void onPause() {
super.onPause();
mIsActivityPaused = true;
}
@Override
protected void onDestroy() {
unregisterReceiver(mBroadcastListener);
super.onDestroy();
}
private …Run Code Online (Sandbox Code Playgroud)